aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-dummy-stdio.js
blob: 4866f85c7def4be14e4f0db553aefe2947e5cc12 (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
28
29
'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',
    '--no-warnings',
    '-e',
    `const { internalBinding } = require('internal/test/binding');
    internalBinding('process_methods').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');