• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// This test confirms that `undefined`, `null`, and `[]` can be used
4// as a placeholder for the second argument (`args`) of `spawnSync()`.
5// Previously, there was a bug where using `undefined` for the second argument
6// caused the third argument (`options`) to be ignored.
7// See https://github.com/nodejs/node/issues/24912.
8
9const common = require('../common');
10const tmpdir = require('../common/tmpdir');
11
12const assert = require('assert');
13const { spawnSync } = require('child_process');
14
15const command = common.isWindows ? 'cd' : 'pwd';
16const options = { cwd: tmpdir.path };
17
18tmpdir.refresh();
19
20if (common.isWindows) {
21  // This test is not the case for Windows based systems
22  // unless the `shell` options equals to `true`
23
24  options.shell = true;
25}
26
27const testCases = [
28  undefined,
29  null,
30  [],
31];
32
33const expectedResult = tmpdir.path.trim().toLowerCase();
34
35const results = testCases.map((testCase) => {
36  const { stdout, stderr, error } = spawnSync(
37    command,
38    testCase,
39    options
40  );
41
42  assert.ifError(error);
43  assert.deepStrictEqual(stderr, Buffer.alloc(0));
44
45  return stdout.toString().trim().toLowerCase();
46});
47
48assert.deepStrictEqual([...new Set(results)], [expectedResult]);
49