From bdcf8f4784b33a4702c786249f16137c2cf5581a Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 7 Jan 2019 20:39:57 -0800 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/25384 Reviewed-By: Daijiro Wachi Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- test/pummel/test-fs-watch-file.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/test/pummel/test-fs-watch-file.js b/test/pummel/test-fs-watch-file.js index d8694418e9eea5..70e793938ac2d3 100644 --- a/test/pummel/test-fs-watch-file.js +++ b/test/pummel/test-fs-watch-file.js @@ -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. @@ -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. @@ -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() {