Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-fs-watch-non-recursive.js « pummel « test - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 183733dda819dd5a0feb79cad572d6614c992f6c (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
'use strict';
const common = require('../common');
const path = require('path');
const fs = require('fs');

const testDir = common.tmpDir;
const testsubdir = path.join(testDir, 'testsubdir');
const 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, 0o700); } catch (e) {}

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