• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const child_process = require('child_process');
5
6if (common.isWindows)
7  common.skip('fs.closeSync(n) does not close stdio on Windows');
8
9function runTest(fd, streamName, testOutputStream, expectedName) {
10  const result = child_process.spawnSync(process.execPath, [
11    '--expose-internals',
12    '--no-warnings',
13    '-e',
14    `const { internalBinding } = require('internal/test/binding');
15    internalBinding('process_methods').resetStdioForTesting();
16    fs.closeSync(${fd});
17    const ctorName = process.${streamName}.constructor.name;
18    process.${testOutputStream}.write(ctorName);
19    `]);
20  assert.strictEqual(result[testOutputStream].toString(), expectedName,
21                     `stdout:\n${result.stdout}\nstderr:\n${result.stderr}\n` +
22                     `while running test with fd = ${fd}`);
23  if (testOutputStream !== 'stderr')
24    assert.strictEqual(result.stderr.toString(), '');
25}
26
27runTest(0, 'stdin', 'stdout', 'Readable');
28runTest(1, 'stdout', 'stderr', 'Writable');
29runTest(2, 'stderr', 'stdout', 'Writable');
30