1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const cp = require('child_process'); 5 6// This test spawns itself with an argument to indicate when it is a child to 7// easily and portably print the value of argv[0] 8if (process.argv[2] === 'child') { 9 console.log(process.argv0); 10 return; 11} 12 13const noArgv0 = cp.spawnSync(process.execPath, [__filename, 'child']); 14assert.strictEqual(noArgv0.stdout.toString().trim(), process.execPath); 15 16const withArgv0 = cp.spawnSync(process.execPath, [__filename, 'child'], 17 { argv0: 'withArgv0' }); 18assert.strictEqual(withArgv0.stdout.toString().trim(), 'withArgv0'); 19 20assert.throws(() => { 21 cp.spawnSync(process.execPath, [__filename, 'child'], { argv0: [] }); 22}, { 23 code: 'ERR_INVALID_ARG_TYPE', 24 name: 'TypeError', 25 message: 'The "options.argv0" property must be of type string.' + 26 common.invalidArgTypeHelper([]) 27}); 28