summaryrefslogtreecommitdiff
path: root/test/parallel/test-dummy-stdio.js
blob: 165c2c2c575ff55190830c781e61030f3e779b88 (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
'use strict';
const common = require('../common');
const assert = require('assert');
const child_process = require('child_process');

if (common.isWindows)
  common.skip('fs.closeSync(n) does not close stdio on Windows');

function runTest(fd, streamName, testOutputStream, expectedName) {
  const result = child_process.spawnSync(process.execPath, [
    '--expose-internals',
    '-e', `
    require('internal/process/stdio').resetStdioForTesting();
    fs.closeSync(${fd});
    const ctorName = process.${streamName}.constructor.name;
    process.${testOutputStream}.write(ctorName);
    `]);
  assert.strictEqual(result[testOutputStream].toString(), expectedName,
                     `stdout:\n${result.stdout}\nstderr:\n${result.stderr}\n` +
                     `while running test with fd = ${fd}`);
  if (testOutputStream !== 'stderr')
    assert.strictEqual(result.stderr.toString(), '');
}

runTest(0, 'stdin', 'stdout', 'Readable');
runTest(1, 'stdout', 'stderr', 'Writable');
runTest(2, 'stderr', 'stdout', 'Writable');