Skip to content

Commit b2a5399

Browse files
Trottaddaleax
authored andcommitted
test: refactor test-fs-watch-stop-sync
* format test per project guide * use listener that emits clear message * use common.mustNotCall() to confirm different listener is not invoked * add comment describing the test PR-URL: #13689 Reviewed-By: David Cai <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 10aee10 commit b2a5399

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed
+16-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
'use strict';
2-
32
const common = require('../common');
4-
const assert = require('assert');
3+
4+
// This test checks that the `stop` event is emitted asynchronously.
5+
//
6+
// If it isn't asynchronous, then the listener will be called during the
7+
// execution of `watch.stop()`. That would be a bug.
8+
//
9+
// If it is asynchronous, then the listener will be removed before the event is
10+
// emitted.
11+
512
const fs = require('fs');
613

7-
const watch = fs.watchFile(__filename, common.noop);
8-
watch.once('stop', assert.fail); // Should not trigger.
14+
const listener = common.mustNotCall(
15+
'listener should have been removed before the event was emitted'
16+
);
17+
18+
const watch = fs.watchFile(__filename, common.mustNotCall());
19+
watch.once('stop', listener);
920
watch.stop();
10-
watch.removeListener('stop', assert.fail);
21+
watch.removeListener('stop', listener);

0 commit comments

Comments
 (0)