11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// This test confirms that `undefined`, `null`, and `[]` 41cb0ef41Sopenharmony_ci// can be used as a placeholder for the second argument (`args`) of `spawn()`. 51cb0ef41Sopenharmony_ci// Previously, there was a bug where using `undefined` for the second argument 61cb0ef41Sopenharmony_ci// caused the third argument (`options`) to be ignored. 71cb0ef41Sopenharmony_ci// See https://github.com/nodejs/node/issues/24912. 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst common = require('../common'); 101cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst assert = require('assert'); 131cb0ef41Sopenharmony_ciconst { spawn } = require('child_process'); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_citmpdir.refresh(); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciconst command = common.isWindows ? 'cd' : 'pwd'; 181cb0ef41Sopenharmony_ciconst options = { cwd: tmpdir.path }; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciif (common.isWindows) { 211cb0ef41Sopenharmony_ci // This test is not the case for Windows based systems 221cb0ef41Sopenharmony_ci // unless the `shell` options equals to `true` 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci options.shell = true; 251cb0ef41Sopenharmony_ci} 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciconst testCases = [ 281cb0ef41Sopenharmony_ci undefined, 291cb0ef41Sopenharmony_ci null, 301cb0ef41Sopenharmony_ci [], 311cb0ef41Sopenharmony_ci]; 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ciconst expectedResult = tmpdir.path.trim().toLowerCase(); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci(async () => { 361cb0ef41Sopenharmony_ci const results = await Promise.all( 371cb0ef41Sopenharmony_ci testCases.map((testCase) => { 381cb0ef41Sopenharmony_ci return new Promise((resolve) => { 391cb0ef41Sopenharmony_ci const subprocess = spawn(command, testCase, options); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci let accumulatedData = Buffer.alloc(0); 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci subprocess.stdout.on('data', common.mustCall((data) => { 441cb0ef41Sopenharmony_ci accumulatedData = Buffer.concat([accumulatedData, data]); 451cb0ef41Sopenharmony_ci })); 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci subprocess.stdout.on('end', () => { 481cb0ef41Sopenharmony_ci resolve(accumulatedData.toString().trim().toLowerCase()); 491cb0ef41Sopenharmony_ci }); 501cb0ef41Sopenharmony_ci }); 511cb0ef41Sopenharmony_ci }) 521cb0ef41Sopenharmony_ci ); 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci assert.deepStrictEqual([...new Set(results)], [expectedResult]); 551cb0ef41Sopenharmony_ci})().then(common.mustCall()); 56