mirror of
https://github.com/nodejs/node.git
synced 2025-05-10 17:57:53 +00:00

* extract the gist into common.pwdCommand * Merge test-child-process-buffering.js into test-child-process-stdio.js PR-URL: https://github.com/nodejs/node/pull/22522 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
48 lines
1.8 KiB
JavaScript
48 lines
1.8 KiB
JavaScript
// 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;
|
|
}
|