Skip to content

Commit

Permalink
test: fix test/pummel/test-fs-watch-file.js
Browse files Browse the repository at this point in the history
test-fs-watch-file.js fails for two reasons. First, there are cases
where it is checking the error message for an error whose message has
changed since the test was written. Change these instances to check for
an error code instead.

Second, there is an instance where it tries to remove a listener but
fails because `common.mustNotCall()` returns a differnet instance of a
function on each call. Store the function in a variable name so it can
be removed as a listener on a file.

PR-URL: #25384
Reviewed-By: Daijiro Wachi <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Trott authored and MylesBorins committed May 16, 2019
1 parent 95f311c commit af2d22a
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions test/pummel/test-fs-watch-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,8 @@ process.on('exit', function() {
fs.writeFileSync(filepathOne, 'hello');

assert.throws(
function() {
fs.watchFile(filepathOne);
},
function(e) {
return e.message === '"watchFile()" requires a listener function';
}
() => { fs.watchFile(filepathOne); },
{ code: 'ERR_INVALID_ARG_TYPE' }
);

// Does not throw.
Expand All @@ -84,12 +80,8 @@ process.chdir(testDir);
fs.writeFileSync(filepathTwoAbs, 'howdy');

assert.throws(
function() {
fs.watchFile(filepathTwo);
},
function(e) {
return e.message === '"watchFile()" requires a listener function';
}
() => { fs.watchFile(filepathTwo); },
{ code: 'ERR_INVALID_ARG_TYPE' }
);

{ // Does not throw.
Expand All @@ -114,9 +106,10 @@ setTimeout(function() {
fs.unwatchFile(filenameThree, b);
++watchSeenThree;
}
fs.watchFile(filenameThree, common.mustNotCall());
const uncalledListener = common.mustNotCall();
fs.watchFile(filenameThree, uncalledListener);
fs.watchFile(filenameThree, b);
fs.unwatchFile(filenameThree, common.mustNotCall());
fs.unwatchFile(filenameThree, uncalledListener);
}

setTimeout(function() {
Expand Down

0 comments on commit af2d22a

Please sign in to comment.