summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorShobhit Chittora <chittorashobhit@gmail.com>2018-08-20 21:32:31 +0530
committerRich Trott <rtrott@gmail.com>2018-11-01 19:41:33 -0700
commit0d9d32ad1598e07816c204ad566e723b3cc83406 (patch)
treecb50d896b3b2fb7f05373d7c26fbad924dbfc972 /test
parent22f7d0a4bdf4e33cfb85be1f341b1f8cadf1b668 (diff)
downloadandroid-node-v8-0d9d32ad1598e07816c204ad566e723b3cc83406.tar.gz
android-node-v8-0d9d32ad1598e07816c204ad566e723b3cc83406.tar.bz2
android-node-v8-0d9d32ad1598e07816c204ad566e723b3cc83406.zip
child_process: handle undefined/null for fork() args
PR-URL: https://github.com/nodejs/node/pull/22416 Fixes: https://github.com/nodejs/node/issues/20749 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/child-process-echo-options.js1
-rw-r--r--test/parallel/test-child-process-fork-options.js37
2 files changed, 38 insertions, 0 deletions
diff --git a/test/fixtures/child-process-echo-options.js b/test/fixtures/child-process-echo-options.js
new file mode 100644
index 0000000000..04f3f8dcff
--- /dev/null
+++ b/test/fixtures/child-process-echo-options.js
@@ -0,0 +1 @@
+process.send({ env: process.env });
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 0000000000..5efb9bdbb4
--- /dev/null
+++ b/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
+
+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);
+ }));
+}