mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 09:02:40 +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>
26 lines
560 B
JavaScript
26 lines
560 B
JavaScript
'use strict';
|
|
var fs = require('fs');
|
|
var assert = require('assert');
|
|
var path = require('path');
|
|
|
|
var common = require('../common');
|
|
|
|
var file = path.join(common.tmpDir, '/read_stream_fd_test.txt');
|
|
var input = 'hello world';
|
|
var output = '';
|
|
var fd, stream;
|
|
|
|
common.refreshTmpDir();
|
|
fs.writeFileSync(file, input);
|
|
fd = fs.openSync(file, 'r');
|
|
|
|
stream = fs.createReadStream(null, { fd: fd, encoding: 'utf8' });
|
|
stream.on('data', function(data) {
|
|
output += data;
|
|
});
|
|
|
|
process.on('exit', function() {
|
|
fs.unlinkSync(file);
|
|
assert.equal(output, input);
|
|
});
|