| 
 | 1 | +'use strict';  | 
 | 2 | + | 
 | 3 | +const common = require('../common');  | 
 | 4 | + | 
 | 5 | +if (!(process.platform === 'darwin' || common.isWindows)) {  | 
 | 6 | +  console.log('1..0 # Skipped: recursive option is darwin/windows specific');  | 
 | 7 | +  return;  | 
 | 8 | +}  | 
 | 9 | + | 
 | 10 | +const assert = require('assert');  | 
 | 11 | +const path = require('path');  | 
 | 12 | +const fs = require('fs');  | 
 | 13 | + | 
 | 14 | +const testDir = common.tmpDir;  | 
 | 15 | +const filenameOne = 'watch.txt';  | 
 | 16 | +const testsubdirName = 'testsubdir';  | 
 | 17 | +const testsubdir = path.join(testDir, testsubdirName);  | 
 | 18 | +const relativePathOne = path.join('testsubdir', filenameOne);  | 
 | 19 | +const filepathOne = path.join(testsubdir, filenameOne);  | 
 | 20 | + | 
 | 21 | +common.refreshTmpDir();  | 
 | 22 | + | 
 | 23 | +fs.mkdirSync(testsubdir, 0o700);  | 
 | 24 | + | 
 | 25 | +const watcher = fs.watch(testDir, {recursive: true});  | 
 | 26 | + | 
 | 27 | +var watcherClosed = false;  | 
 | 28 | +watcher.on('change', function(event, filename) {  | 
 | 29 | +  assert.ok('change' === event || 'rename' === event);  | 
 | 30 | + | 
 | 31 | +  // Ignore stale events generated by mkdir and other tests  | 
 | 32 | +  if (filename !== relativePathOne)  | 
 | 33 | +    return;  | 
 | 34 | + | 
 | 35 | +  watcher.close();  | 
 | 36 | +  watcherClosed = true;  | 
 | 37 | +});  | 
 | 38 | + | 
 | 39 | +fs.writeFileSync(filepathOne, 'world');  | 
 | 40 | + | 
 | 41 | +process.on('exit', function() {  | 
 | 42 | +  assert(watcherClosed, 'watcher Object was not closed');  | 
 | 43 | +});  | 
0 commit comments