Skip to content

Commit

Permalink
test: FileHandle.readFile
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Apr 23, 2022
1 parent af95f5b commit c1ef64d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/yarnpkg-fslib/tests/patchedFs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,39 @@ describe(`patchedFs`, () => {
});
});

it(`should support FileHandle.readFile`, async () => {
const patchedFs = extendFs(fs, new PosixFS(new NodeFS()));

await xfs.mktempPromise(async dir => {
const filepath = npath.join(npath.fromPortablePath(dir), `foo.txt`);
await patchedFs.promises.writeFile(filepath, `foo`);

{
const fd = await patchedFs.promises.open(filepath, `r`);
await expect(fd.readFile()).resolves.toEqual(Buffer.from(`foo`));
await fd.close();
}

{
const fd = await patchedFs.promises.open(filepath, `r`);
await expect(fd.readFile({})).resolves.toEqual(Buffer.from(`foo`));
await fd.close();
}

{
const fd = await patchedFs.promises.open(filepath, `r`);
await expect(fd.readFile(`utf8`)).resolves.toEqual(`foo`);
await fd.close();
}

{
const fd = await patchedFs.promises.open(filepath, `r`);
await expect(fd.readFile({encoding: `utf8`})).resolves.toEqual(`foo`);
await fd.close();
}
});
});

it(`should support FileHandle.write`, async () => {
const patchedFs = extendFs(fs, new PosixFS(new NodeFS()));

Expand Down

0 comments on commit c1ef64d

Please sign in to comment.