Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: increase test coverage for readfile with withFileTypes option #23557

Closed
Changes from all commits
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
13 changes: 13 additions & 0 deletions test/parallel/test-fs-readdir-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ function assertDirents(dirents) {
// Check the readdir Sync version
assertDirents(fs.readdirSync(readdirDir, { withFileTypes: true }));

fs.readdir(__filename, {
withFileTypes: true
}, common.mustCall((err) => {
assert.throws(
() => { throw err; },
{
code: 'ENOTDIR',
name: 'Error',
message: `ENOTDIR: not a directory, scandir '${__filename}'`
}
);
}));
Copy link
Member

@BridgeAR BridgeAR Oct 12, 2018

Choose a reason for hiding this comment

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

As a suggestion:

To test the actual error it would be best to rewrite this to e.g.,:

fs.readdir(__filename, { withFileTypes: true }, common.expectsError({
  message: 'FOOBAR',
  name: 'ErrorName',
  ...
});

Copy link
Contributor Author

@christian-bromann christian-bromann Oct 12, 2018

Choose a reason for hiding this comment

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

@BridgeAR the error is actually passed within the fs.readdir callback, how about:

fs.readdir(__filename, {
  withFileTypes: true
}, common.mustCall((err) => {
  assert.throws(
    () => { throw err; },
    {
      code: 'ENOTDIR',
      name: 'Error',
      message: `ENOTDIR: not a directory, scandir '${__filename}'`
    }
  );
}));

Copy link
Member

Choose a reason for hiding this comment

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

Right, sorry, I made a mistake when writing the example. I just updated it.


// Check the readdir async version
fs.readdir(readdirDir, {
withFileTypes: true
Expand Down