From 4ffbf08db1bab3dc48798db48f089c425f5f3e48 Mon Sep 17 00:00:00 2001 From: Shobhit Chittora Date: Mon, 20 Aug 2018 21:32:31 +0530 Subject: [PATCH 1/8] child_process: handling fork( path, undefined / null, obj ) Closes: #20749 --- lib/child_process.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/child_process.js b/lib/child_process.js index 6cce1b09e5654b..7e763695c0d70b 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -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]); From deda17fa6168d6feeec62de918209e27db278cad Mon Sep 17 00:00:00 2001 From: Shobhit Chittora Date: Wed, 22 Aug 2018 11:40:54 +0530 Subject: [PATCH 2/8] child_process: adds test + indentation fix --- lib/child_process.js | 2 +- test/fixtures/child-process-echo-options.js | 2 ++ .../parallel/test-child-process-fork-options.js | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/child-process-echo-options.js create mode 100644 test/parallel/test-child-process-fork-options.js diff --git a/lib/child_process.js b/lib/child_process.js index 7e763695c0d70b..629e2c415a4443 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -70,7 +70,7 @@ exports.fork = function fork(modulePath /* , args, options */) { } if (pos < arguments.length && (arguments[pos] === undefined || - arguments[pos] === null)) { + arguments[pos] === null)) { pos++; } diff --git a/test/fixtures/child-process-echo-options.js b/test/fixtures/child-process-echo-options.js new file mode 100644 index 00000000000000..88905d54bf1197 --- /dev/null +++ b/test/fixtures/child-process-echo-options.js @@ -0,0 +1,2 @@ +process.send({ env: process.env }) +process.exit(0) \ No newline at end of file diff --git a/test/parallel/test-child-process-fork-options.js b/test/parallel/test-child-process-fork-options.js new file mode 100644 index 00000000000000..47588eca08a434 --- /dev/null +++ b/test/parallel/test-child-process-fork-options.js @@ -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); +})); From 331ecbe66e67fa30f2690fd6f95d32f1ccd20107 Mon Sep 17 00:00:00 2001 From: Shobhit Chittora Date: Wed, 22 Aug 2018 20:52:36 +0530 Subject: [PATCH 3/8] child_process: fixes typo + lint fix --- test/fixtures/child-process-echo-options.js | 4 ++-- test/parallel/test-child-process-fork-options.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/fixtures/child-process-echo-options.js b/test/fixtures/child-process-echo-options.js index 88905d54bf1197..fb28f3a72a064a 100644 --- a/test/fixtures/child-process-echo-options.js +++ b/test/fixtures/child-process-echo-options.js @@ -1,2 +1,2 @@ -process.send({ env: process.env }) -process.exit(0) \ No newline at end of file +process.send({ env: process.env }); +process.exit(0); diff --git a/test/parallel/test-child-process-fork-options.js b/test/parallel/test-child-process-fork-options.js index 47588eca08a434..eee18fb8b73148 100644 --- a/test/parallel/test-child-process-fork-options.js +++ b/test/parallel/test-child-process-fork-options.js @@ -1,5 +1,5 @@ /** - * fork should parse options correclty if args is undefined or null + * fork should parse options correctly if args is undefined or null */ 'use strict'; From 262c9c1e020f1de7291e8cddd46298106e66a309 Mon Sep 17 00:00:00 2001 From: Shobhit Chittora Date: Wed, 29 Aug 2018 12:06:06 +0530 Subject: [PATCH 4/8] child_process: refactored test as per the comments + alignment fix --- lib/child_process.js | 4 ++-- test/parallel/test-child-process-fork-options.js | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 629e2c415a4443..5b24328e545ffb 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -69,8 +69,8 @@ exports.fork = function fork(modulePath /* , args, options */) { args = arguments[pos++]; } - if (pos < arguments.length && (arguments[pos] === undefined || - arguments[pos] === null)) { + if (pos < arguments.length && + (arguments[pos] === undefined || arguments[pos] === null)) { pos++; } diff --git a/test/parallel/test-child-process-fork-options.js b/test/parallel/test-child-process-fork-options.js index eee18fb8b73148..ee75948ab3dae6 100644 --- a/test/parallel/test-child-process-fork-options.js +++ b/test/parallel/test-child-process-fork-options.js @@ -1,17 +1,17 @@ -/** - * fork should parse options correctly if args is undefined or null - */ - '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 + 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 }) { +cp.on('message', common.mustCall(({ env }) => { assert.strictEqual(env.foo, expectedEnv.foo); })); From 38890801b90d0a844e566e0122dc318f86d0ab89 Mon Sep 17 00:00:00 2001 From: Shobhit Chittora Date: Wed, 12 Sep 2018 13:31:51 +0530 Subject: [PATCH 5/8] child_process: removes exit(0) from the test --- test/fixtures/child-process-echo-options.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/fixtures/child-process-echo-options.js b/test/fixtures/child-process-echo-options.js index fb28f3a72a064a..04f3f8dcffe6a9 100644 --- a/test/fixtures/child-process-echo-options.js +++ b/test/fixtures/child-process-echo-options.js @@ -1,2 +1 @@ process.send({ env: process.env }); -process.exit(0); From 9d771cf866592e779c6b3487ecd9565c3b030805 Mon Sep 17 00:00:00 2001 From: Shobhit Chittora Date: Thu, 4 Oct 2018 00:14:41 +0530 Subject: [PATCH 6/8] child_process: adding on exit handle --- test/parallel/test-child-process-fork-options.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/parallel/test-child-process-fork-options.js b/test/parallel/test-child-process-fork-options.js index ee75948ab3dae6..745ecb18fb0377 100644 --- a/test/parallel/test-child-process-fork-options.js +++ b/test/parallel/test-child-process-fork-options.js @@ -15,3 +15,7 @@ const cp = fork(fixtures.path('child-process-echo-options.js'), undefined, cp.on('message', common.mustCall(({ env }) => { assert.strictEqual(env.foo, expectedEnv.foo); })); + +cp.on('exit', common.mustCall((code) => { + assert.strictEqual(code, 0); +})); From ee714208782aaccb35ecc6b54eb90f2b43e90667 Mon Sep 17 00:00:00 2001 From: Shobhit Chittora Date: Wed, 10 Oct 2018 08:52:33 +0530 Subject: [PATCH 7/8] child_process: extending process.env --- test/parallel/test-child-process-fork-options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-child-process-fork-options.js b/test/parallel/test-child-process-fork-options.js index 745ecb18fb0377..bbc220e0951887 100644 --- a/test/parallel/test-child-process-fork-options.js +++ b/test/parallel/test-child-process-fork-options.js @@ -10,7 +10,7 @@ const { fork } = require('child_process'); const expectedEnv = { foo: 'bar' }; const cp = fork(fixtures.path('child-process-echo-options.js'), undefined, - { env: Object.assign({}, expectedEnv) }); + { env: Object.assign({}, process.env, expectedEnv) }); cp.on('message', common.mustCall(({ env }) => { assert.strictEqual(env.foo, expectedEnv.foo); From 2cf060dfbaa8f1ff74660e0c936e138d1cff684a Mon Sep 17 00:00:00 2001 From: Shobhit Chittora Date: Mon, 22 Oct 2018 14:55:58 +0530 Subject: [PATCH 8/8] child_process: adds test for null check --- .../test-child-process-fork-options.js | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/test/parallel/test-child-process-fork-options.js b/test/parallel/test-child-process-fork-options.js index bbc220e0951887..5efb9bdbb49735 100644 --- a/test/parallel/test-child-process-fork-options.js +++ b/test/parallel/test-child-process-fork-options.js @@ -9,13 +9,29 @@ 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); -})); +{ + const cp = fork(fixtures.path('child-process-echo-options.js'), undefined, + { env: Object.assign({}, process.env, expectedEnv) }); -cp.on('exit', common.mustCall((code) => { - assert.strictEqual(code, 0); -})); + 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); + })); +}