aboutsummaryrefslogtreecommitdiff
path: root/test/sequential
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-03-03 00:28:05 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-03-08 01:14:53 +0800
commit6c25f2ea49c2521dfd2423bf3a06222633ec4dc9 (patch)
tree4ac455087cbded9f029a37e9e80f4428bf87a6a2 /test/sequential
parent48b5c11b16a4c0035c9beecf252997721dfc2fdd (diff)
downloadandroid-node-v8-6c25f2ea49c2521dfd2423bf3a06222633ec4dc9.tar.gz
android-node-v8-6c25f2ea49c2521dfd2423bf3a06222633ec4dc9.tar.bz2
android-node-v8-6c25f2ea49c2521dfd2423bf3a06222633ec4dc9.zip
fs: improve errors thrown from fs.watch()
- Add an accessor property `initialized `to FSEventWrap to check the state of the handle from the JS land - Introduce ERR_FS_WATCHER_ALREADY_STARTED so calling start() on a watcher that is already started will throw instead of doing nothing silently. - Introduce ERR_FS_WATCHER_NOT_STARTED so calling close() on a watcher that is already closed will throw instead of doing nothing silently. - Validate the filename passed to fs.watch() - Assert that the handle in the watcher are instances of FSEvent instead of relying on the illegal invocation error from the VM. - Add more assertions in FSEventWrap methods now that we check `initialized` and the filename in JS land before invoking the binding. - Use uvException instead of errornoException to create the errors with the error numbers from libuv to make them consistent with other errors in fs. TODO: - Improve fs.watchFile() the same way this patch improves fs.watch() - It seems possible to fire both rename and change event from libuv together now that we can check if the handle is closed via `initialized` in JS land. PR-URL: https://github.com/nodejs/node/pull/19089 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/sequential')
-rw-r--r--test/sequential/test-fs-watch.js7
1 files changed, 5 insertions, 2 deletions
diff --git a/test/sequential/test-fs-watch.js b/test/sequential/test-fs-watch.js
index b672e9c753..91d750acd0 100644
--- a/test/sequential/test-fs-watch.js
+++ b/test/sequential/test-fs-watch.js
@@ -112,12 +112,15 @@ tmpdir.refresh();
// https://github.com/joyent/node/issues/6690
{
let oldhandle;
- assert.throws(function() {
+ assert.throws(() => {
const w = fs.watch(__filename, common.mustNotCall());
oldhandle = w._handle;
w._handle = { close: w._handle.close };
w.close();
- }, /^TypeError: Illegal invocation$/);
+ }, {
+ message: 'handle must be a FSEvent',
+ code: 'ERR_ASSERTION'
+ });
oldhandle.close(); // clean up
assert.throws(function() {