summaryrefslogtreecommitdiff
path: root/test/pummel/test-fs-watch-non-recursive.js
blob: 60d2c6b6a84900e4606ba0a664fd70972f232d75 (plain)
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
var common = require('../common');
var assert = require('assert');
var path = require('path');
var fs = require('fs');

var testDir = common.tmpDir;
var testsubdir = path.join(testDir, 'testsubdir');
var filepath = path.join(testsubdir, 'watch.txt');

function cleanup() {
  try { fs.unlinkSync(filepath); } catch (e) { }
  try { fs.rmdirSync(testsubdir); } catch (e) { }
}
process.on('exit', cleanup);
cleanup();

try { fs.mkdirSync(testsubdir, 0700); } catch (e) {}

// Need a grace period, else the mkdirSync() above fires off an event.
setTimeout(function() {
  var watcher = fs.watch(testDir, { persistent: true }, assert.fail);
  setTimeout(function() {
    fs.writeFileSync(filepath, 'test');
  }, 100);
  setTimeout(function() {
    watcher.close();
  }, 500);
}, 50);