From 4539200f7aa8b6787eb615d719a8688003db155e Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 14 Jun 2017 15:30:58 -0700 Subject: [PATCH] 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 --- test/parallel/test-fs-watch-stop-sync.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-fs-watch-stop-sync.js b/test/parallel/test-fs-watch-stop-sync.js index 4655c0ac62943d..7f0882e489f8b3 100644 --- a/test/parallel/test-fs-watch-stop-sync.js +++ b/test/parallel/test-fs-watch-stop-sync.js @@ -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);