summaryrefslogtreecommitdiff
path: root/test/parallel/test-child-process-spawn-args.js
diff options
context:
space:
mode:
authorEduard Bondarenko <eduardbcom@gmail.com>2018-12-08 23:50:17 +0200
committerRich Trott <rtrott@gmail.com>2018-12-16 07:22:45 -0800
commit20770073ba56d2af516cc8fa39527da3e4e01985 (patch)
tree669994062bd2da60bc58d1798c4000e3f2e86829 /test/parallel/test-child-process-spawn-args.js
parent02b66b5b866bd8398e7d815d3715ba3f94a5cf65 (diff)
downloadandroid-node-v8-20770073ba56d2af516cc8fa39527da3e4e01985.tar.gz
android-node-v8-20770073ba56d2af516cc8fa39527da3e4e01985.tar.bz2
android-node-v8-20770073ba56d2af516cc8fa39527da3e4e01985.zip
child_process: spawn ignores options in case args is undefined
spawn method ignores 3-d argument 'options' in case the second one 'args' equals to 'undefined'. Fixes: https://github.com/nodejs/node/issues/24912 PR-URL: https://github.com/nodejs/node/pull/24913 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Diffstat (limited to 'test/parallel/test-child-process-spawn-args.js')
-rw-r--r--test/parallel/test-child-process-spawn-args.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/parallel/test-child-process-spawn-args.js b/test/parallel/test-child-process-spawn-args.js
new file mode 100644
index 0000000000..35a1ea4020
--- /dev/null
+++ b/test/parallel/test-child-process-spawn-args.js
@@ -0,0 +1,53 @@
+'use strict';
+
+// This test confirms that `undefined`, `null`, and `[]`
+// can be used as a placeholder for the second argument (`args`) of `spawn()`.
+// Previously, there was a bug where using `undefined` for the second argument
+// caused the third argument (`options`) to be ignored.
+// See https://github.com/nodejs/node/issues/24912.
+
+const assert = require('assert');
+const { spawn } = require('child_process');
+
+const common = require('../common');
+const tmpdir = require('../common/tmpdir');
+
+const command = common.isWindows ? 'cd' : 'pwd';
+const options = { cwd: tmpdir.path };
+
+if (common.isWindows) {
+ // This test is not the case for Windows based systems
+ // unless the `shell` options equals to `true`
+
+ options.shell = true;
+}
+
+const testCases = [
+ undefined,
+ null,
+ [],
+];
+
+const expectedResult = tmpdir.path.trim().toLowerCase();
+
+(async () => {
+ const results = await Promise.all(
+ testCases.map((testCase) => {
+ return new Promise((resolve) => {
+ const subprocess = spawn(command, testCase, options);
+
+ let accumulatedData = Buffer.alloc(0);
+
+ subprocess.stdout.on('data', common.mustCall((data) => {
+ accumulatedData = Buffer.concat([accumulatedData, data]);
+ }));
+
+ subprocess.stdout.on('end', () => {
+ resolve(accumulatedData.toString().trim().toLowerCase());
+ });
+ });
+ })
+ );
+
+ assert.deepStrictEqual([...new Set(results)], [expectedResult]);
+})();