aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-child-process-custom-fds.js
blob: 1c89c207d37f99f94f17511ed97e8b73913ce4e1 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Flags: --expose_internals
'use strict';
const common = require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
const internalCp = require('internal/child_process');

if (!common.isMainThread)
  common.skip('stdio is not associated with file descriptors in Workers');

// This test uses the deprecated `customFds` option. We expect a deprecation
// warning, but only once (per node process).
const msg = 'child_process: options.customFds option is deprecated. ' +
            'Use options.stdio instead.';
common.expectWarning('DeprecationWarning', msg, 'DEP0006');

// Verify that customFds is used if stdio is not provided.
{
  const customFds = [-1, process.stdout.fd, process.stderr.fd];
  const oldSpawnSync = internalCp.spawnSync;
  internalCp.spawnSync = common.mustCall(function(opts) {
    assert.deepStrictEqual(opts.options.customFds, customFds);
    assert.deepStrictEqual(opts.options.stdio, [
      { type: 'pipe', readable: true, writable: false },
      { type: 'fd', fd: process.stdout.fd },
      { type: 'fd', fd: process.stderr.fd }
    ]);
  });
  spawnSync(...common.pwdCommand, { customFds });
  internalCp.spawnSync = oldSpawnSync;
}

// Verify that customFds is ignored when stdio is present.
{
  const customFds = [0, 1, 2];
  const oldSpawnSync = internalCp.spawnSync;
  internalCp.spawnSync = common.mustCall(function(opts) {
    assert.deepStrictEqual(opts.options.customFds, customFds);
    assert.deepStrictEqual(opts.options.stdio, [
      { type: 'pipe', readable: true, writable: false },
      { type: 'pipe', readable: false, writable: true },
      { type: 'pipe', readable: false, writable: true }
    ]);
  });
  spawnSync(...common.pwdCommand, { customFds, stdio: 'pipe' });
  internalCp.spawnSync = oldSpawnSync;
}