0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/test/sequential/test-regress-GH-4027.js
Rich Trott 7c79490bfb test: only refresh tmpDir for tests that need it
Expose `common.refreshTmpDir()` and only call it
for tests that use common.tmpDir or common.PIPE.

A positive side effect is the removal of a code
smell where child processes were detected by the
presence of `.send()`. Now each process can decide
for itself if it needs to refresh tmpDir.

PR-URL: https://github.com/nodejs/io.js/pull/1954
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
2015-06-13 22:27:17 -07:00

24 lines
574 B
JavaScript

'use strict';
var common = require('../common');
var assert = require('assert');
var path = require('path');
var fs = require('fs');
common.refreshTmpDir();
var filename = path.join(common.tmpDir, 'watched');
fs.writeFileSync(filename, 'quis custodiet ipsos custodes');
setTimeout(fs.unlinkSync, 100, filename);
var seenEvent = 0;
process.on('exit', function() {
assert.equal(seenEvent, 1);
});
fs.watchFile(filename, { interval: 50 }, function(curr, prev) {
assert.equal(prev.nlink, 1);
assert.equal(curr.nlink, 0);
fs.unwatchFile(filename);
seenEvent++;
});