mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 15:41:06 +00:00

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>
37 lines
847 B
JavaScript
37 lines
847 B
JavaScript
'use strict';
|
|
var common = require('../common');
|
|
var assert = require('assert');
|
|
var path = require('path'),
|
|
Buffer = require('buffer').Buffer,
|
|
fs = require('fs'),
|
|
filename = path.join(common.tmpDir, 'write.txt'),
|
|
expected = new Buffer('hello'),
|
|
openCalled = 0,
|
|
writeCalled = 0;
|
|
|
|
|
|
common.refreshTmpDir();
|
|
|
|
fs.open(filename, 'w', 0o644, function(err, fd) {
|
|
openCalled++;
|
|
if (err) throw err;
|
|
|
|
fs.write(fd, expected, 0, expected.length, null, function(err, written) {
|
|
writeCalled++;
|
|
if (err) throw err;
|
|
|
|
assert.equal(expected.length, written);
|
|
fs.closeSync(fd);
|
|
|
|
var found = fs.readFileSync(filename, 'utf8');
|
|
assert.deepEqual(expected.toString(), found);
|
|
fs.unlinkSync(filename);
|
|
});
|
|
});
|
|
|
|
process.on('exit', function() {
|
|
assert.equal(1, openCalled);
|
|
assert.equal(1, writeCalled);
|
|
});
|
|
|