Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Increase test coverage for fs/promises.js
  • Loading branch information
humphd committed Apr 30, 2018
commit fffdce1c68ba958a335ac6ac4bc5a01a4ecc4267
34 changes: 32 additions & 2 deletions test/parallel/test-fs-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,44 @@ function verifyStatObject(stat) {
stats = await stat(dest);
verifyStatObject(stats);

stats = await handle.stat();
verifyStatObject(stats);

await fdatasync(handle);
await handle.datasync();
await fsync(handle);
await handle.sync();

const buf = Buffer.from('hello world');

await write(handle, buf);

const ret = await read(handle, Buffer.alloc(11), 0, 11, 0);
assert.strictEqual(ret.bytesRead, 11);
assert.deepStrictEqual(ret.buffer, buf);

const buf2 = Buffer.from('HELLO WORLD');
await handle.write(buf2);
const ret2 = await handle.read(Buffer.alloc(11), 0, 11, 0);
assert.strictEqual(ret2.bytesRead, 11);
assert.deepStrictEqual(ret2.buffer, buf);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be compared with buf2?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Also, if we reduce magic numbers (like 11 in this case) it would be better.


await chmod(dest, 0o666);
await fchmod(handle, 0o666);
handle.chmod(0o666);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be awaited?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, thank you for spotting this. I'll fix.

try {
await fchmod(handle, (0o777 + 1));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better, if did this for chmod as well.

} catch (err) {
// mode can't be > 0o777
common.expectsError({
code: 'ERR_OUT_OF_RANGE',
type: RangeError
})(err);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a general note: we can actually use the following instead:

assert.rejects(
  // `mode` can't be > 0o777
  () => fchmod(handle, (0o777 + 1)),
  {
    code: 'ERR_OUT_OF_RANGE',
    name: 'RangeError [ERR_OUT_OF_RANGE]'
  }
);


await utimes(dest, new Date(), new Date());

try {
await futimes(handle, new Date(), new Date());
await handle.utimes(new Date(), new Date());
} catch (err) {
// Some systems do not have futimes. If there is an error,
// expect it to be ENOSYS
Expand Down Expand Up @@ -147,6 +167,16 @@ function verifyStatObject(stat) {
await rmdir(newdir);

await mkdtemp(path.resolve(tmpDir, 'FOO'));
try {
await mkdtemp(1);
} catch (err) {
// mkdtemp() expects to get a string prefix.
console.log('err', err);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can you please remove the console.log here?

common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
})(err);
}
}

doTest().then(common.mustCall());
Expand Down