Skip to content

Commit ab37375

Browse files
thefourtheyervagg
authored andcommitted
test: enhance fs-watch-recursive test
This patch - issues a TAP plugin parsable message on non darwin/windows boxes - uses `const` wherever applicable - moves the test to parallel PR-URL: #2599 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Johan Bergström <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent bc683d1 commit ab37375

File tree

2 files changed

+43
-51
lines changed

2 files changed

+43
-51
lines changed
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
});

test/sequential/test-fs-watch-recursive.js

-51
This file was deleted.

0 commit comments

Comments
 (0)