1'use strict'; 2 3const common = require('../common'); 4 5const fs = require('fs'); 6const assert = require('assert'); 7 8const uncalledListener = common.mustNotCall(); 9const uncalledListener2 = common.mustNotCall(); 10const watcher = fs.watchFile(__filename, uncalledListener); 11 12watcher.unref(); 13watcher.unref(); 14watcher.ref(); 15watcher.unref(); 16watcher.ref(); 17watcher.ref(); 18watcher.unref(); 19 20fs.unwatchFile(__filename, uncalledListener); 21 22// Watch the file with two different listeners. 23fs.watchFile(__filename, uncalledListener); 24const watcher2 = fs.watchFile(__filename, uncalledListener2); 25 26setTimeout( 27 common.mustCall(() => { 28 fs.unwatchFile(__filename, common.mustNotCall()); 29 assert.strictEqual(watcher2.listenerCount('change'), 2); 30 fs.unwatchFile(__filename, uncalledListener); 31 assert.strictEqual(watcher2.listenerCount('change'), 1); 32 watcher2.unref(); 33 }), 34 common.platformTimeout(100) 35); 36