Skip to content

Commit bdcf8f4

Browse files
Trottaddaleax
authored andcommitted
test: fix test/pummel/test-fs-watch-file.js
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 <daijiro.wachi@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent be16cc9 commit bdcf8f4

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

test/pummel/test-fs-watch-file.js

+7-14
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,8 @@ process.on('exit', function() {
6060
fs.writeFileSync(filepathOne, 'hello');
6161

6262
assert.throws(
63-
function() {
64-
fs.watchFile(filepathOne);
65-
},
66-
function(e) {
67-
return e.message === '"watchFile()" requires a listener function';
68-
}
63+
() => { fs.watchFile(filepathOne); },
64+
{ code: 'ERR_INVALID_ARG_TYPE' }
6965
);
7066

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

8682
assert.throws(
87-
function() {
88-
fs.watchFile(filepathTwo);
89-
},
90-
function(e) {
91-
return e.message === '"watchFile()" requires a listener function';
92-
}
83+
() => { fs.watchFile(filepathTwo); },
84+
{ code: 'ERR_INVALID_ARG_TYPE' }
9385
);
9486

9587
{ // Does not throw.
@@ -114,9 +106,10 @@ setTimeout(function() {
114106
fs.unwatchFile(filenameThree, b);
115107
++watchSeenThree;
116108
}
117-
fs.watchFile(filenameThree, common.mustNotCall());
109+
const uncalledListener = common.mustNotCall();
110+
fs.watchFile(filenameThree, uncalledListener);
118111
fs.watchFile(filenameThree, b);
119-
fs.unwatchFile(filenameThree, common.mustNotCall());
112+
fs.unwatchFile(filenameThree, uncalledListener);
120113
}
121114

122115
setTimeout(function() {

0 commit comments

Comments
 (0)