summaryrefslogtreecommitdiff
path: root/test/parallel/test-child-process-spawnsync-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-spawnsync-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-spawnsync-args.js')
-rw-r--r--test/parallel/test-child-process-spawnsync-args.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/parallel/test-child-process-spawnsync-args.js b/test/parallel/test-child-process-spawnsync-args.js
new file mode 100644
index 0000000000..d8dbf9c6bd
--- /dev/null
+++ b/test/parallel/test-child-process-spawnsync-args.js
@@ -0,0 +1,45 @@
+'use strict';
+
+// This test confirms that `undefined`, `null`, and `[]` can be used
+// as a placeholder for the second argument (`args`) of `spawnSync()`.
+// 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 { spawnSync } = 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();
+
+const results = testCases.map((testCase) => {
+ const { stdout, stderr } = spawnSync(
+ command,
+ testCase,
+ options
+ );
+
+ assert.deepStrictEqual(stderr, Buffer.alloc(0));
+
+ return stdout.toString().trim().toLowerCase();
+});
+
+assert.deepStrictEqual([...new Set(results)], [expectedResult]);