Skip to content
5 changes: 5 additions & 0 deletions lib/child_process.js
Original file line number Diff line number Diff line change
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
2 changes: 2 additions & 0 deletions test/fixtures/child-process-echo-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
process.send({ env: process.env })
process.exit(0)
17 changes: 17 additions & 0 deletions test/parallel/test-child-process-fork-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* fork should parse options correclty if args is undefined or null
*/

'use strict';
const common = require('../common');
const assert = require('assert');
const { fork } = require('child_process');
const fixtures = require('../common/fixtures');

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

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