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
Prev Previous commit
Next Next commit
test: check fs.watch filename on Linux and macOS
Fixes: #13108
  • Loading branch information
Chris Young committed May 21, 2017
commit 9bd40124d7d7bf6f1ddb93ef9092fdfa49f83f95
22 changes: 22 additions & 0 deletions test/parallel/test-fs-watchfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,25 @@ fs.watchFile(enoentFile, {interval: 0}, common.mustCall(function(curr, prev) {
fs.unwatchFile(enoentFile);
}
}, 2));

// Watch events should callback with a filename
if (common.isLinux || common.isOSX) {
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.

I would add Windows too. You can also add AIX according to @gireeshpunathil's suggestion.

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.

I just checked, it passes on windows.

const dir = common.tmpDir + '/watch';

fs.mkdir(dir, common.mustCall(function(err) {
assert(!err);
Copy link
Copy Markdown
Contributor

@refack refack May 19, 2017

Choose a reason for hiding this comment

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

If you could use assert.ifError if (err) assert.fail(err); instead. It will rethrow the error so we know what went wrong.
assert(!err) will just say true != false


fs.watch(dir, common.mustCall(function(eventType, filename) {
this._handle.close();
common.refreshTmpDir();
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.

For the test to pass on Windows you should remove the common.refreshTmpDir();. Don't worry about it, the test harness will take care of it.

assert.strictEqual(filename, 'foo.txt');
}));

fs.writeFile(`${dir}/foo.txt`, 'foo', common.mustCall((err) => {
if (err) {
Copy link
Copy Markdown
Contributor

@refack refack May 19, 2017

Choose a reason for hiding this comment

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

you can replace the whole callback with (err) => assert.ifError(err)
Ref: #13092 (comment)

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.

you should replace the whole callback with common.mustCall((err) => {if (err) assert.fail(err)})
Ref: #13115

common.refreshTmpDir();
assert(!err);
}
}));
}));
}