Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_process: handling fork( path, undefined / null, obj ) #22416

Closed
wants to merge 8 commits into from
5 changes: 5 additions & 0 deletions lib/child_process.js
Expand Up @@ -69,6 +69,11 @@ exports.fork = function fork(modulePath /* , args, options */) {
args = arguments[pos++];
}

if (pos < arguments.length &&
(arguments[pos] === undefined || arguments[pos] === null)) {
pos++;
}

if (pos < arguments.length && arguments[pos] != null) {
if (typeof arguments[pos] !== 'object') {
throw new ERR_INVALID_ARG_VALUE(`arguments[${pos}]`, arguments[pos]);
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/child-process-echo-options.js
@@ -0,0 +1 @@
process.send({ env: process.env });
37 changes: 37 additions & 0 deletions test/parallel/test-child-process-fork-options.js
@@ -0,0 +1,37 @@
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');

// This test ensures that fork should parse options
// correctly if args is undefined or null
shobhitchittora marked this conversation as resolved.
Show resolved Hide resolved

const assert = require('assert');
const { fork } = require('child_process');

const expectedEnv = { foo: 'bar' };

{
const cp = fork(fixtures.path('child-process-echo-options.js'), undefined,
{ env: Object.assign({}, process.env, expectedEnv) });

cp.on('message', common.mustCall(({ env }) => {
assert.strictEqual(env.foo, expectedEnv.foo);
}));

cp.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
}));
}

{
const cp = fork(fixtures.path('child-process-echo-options.js'), null,
{ env: Object.assign({}, process.env, expectedEnv) });

cp.on('message', common.mustCall(({ env }) => {
assert.strictEqual(env.foo, expectedEnv.foo);
}));

cp.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
}));
}