forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-fs-watch-recursive.js
More file actions
48 lines (37 loc) · 1.21 KB
/
test-fs-watch-recursive.js
File metadata and controls
48 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var common = require('../common');
var assert = require('assert');
var path = require('path');
var fs = require('fs');
if (process.platform === 'darwin') {
var watchSeenOne = 0;
var testDir = common.tmpDir;
var filenameOne = 'watch.txt';
var testsubdirName = 'testsubdir';
var testsubdir = path.join(testDir, testsubdirName);
var relativePathOne = path.join('testsubdir', filenameOne);
var filepathOne = path.join(testsubdir, filenameOne);
process.on('exit', function() {
assert.ok(watchSeenOne > 0);
});
function cleanup() {
try { fs.unlinkSync(filepathOne); } catch (e) { }
try { fs.rmdirSync(testsubdir); } catch (e) { }
};
try { fs.mkdirSync(testsubdir, 0700); } catch (e) {}
assert.doesNotThrow(function() {
var watcher = fs.watch(testDir, {recursive: true});
watcher.on('change', function(event, filename) {
assert.ok('change' === event || 'rename' === event);
// Ignore stale events generated by mkdir
if (filename === testsubdirName)
return;
assert.equal(relativePathOne, filename);
watcher.close();
cleanup();
++watchSeenOne;
});
});
setTimeout(function() {
fs.writeFileSync(filepathOne, 'world');
}, 10);
}