Skip to content

Commit

Permalink
test: refactor test-fs-watch-stop-sync
Browse files Browse the repository at this point in the history
* 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 <davidcai1993@yahoo.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
Trott authored and addaleax committed Jun 21, 2017
1 parent 10aee10 commit b2a5399
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions test/parallel/test-fs-watch-stop-sync.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
'use strict';

const common = require('../common');
const assert = require('assert');

// This test checks that the `stop` event is emitted asynchronously.
//
// If it isn't asynchronous, then the listener will be called during the
// execution of `watch.stop()`. That would be a bug.
//
// If it is asynchronous, then the listener will be removed before the event is
// emitted.

const fs = require('fs');

const watch = fs.watchFile(__filename, common.noop);
watch.once('stop', assert.fail); // Should not trigger.
const listener = common.mustNotCall(
'listener should have been removed before the event was emitted'
);

const watch = fs.watchFile(__filename, common.mustNotCall());
watch.once('stop', listener);
watch.stop();
watch.removeListener('stop', assert.fail);
watch.removeListener('stop', listener);

0 comments on commit b2a5399

Please sign in to comment.