11import { spawnPromisified } from '../common/index.mjs' ;
2+ import { path } from '../common/fixtures.mjs' ;
23import assert from 'node:assert' ;
34import { suite , test } from 'node:test' ;
45import { parseArgs } from 'node:util' ;
@@ -212,6 +213,8 @@ test('order of option and positional does not matter (per README)', () => {
212213} ) ;
213214
214215suite ( 'correct default args' , ( ) => {
216+ const expected = { code : 0 , signal : null , stderr : '' , stdout : { foo : true , bar : true } } ;
217+
215218 suite ( 'with CLI flags' , ( ) => {
216219 const evalCode = "JSON.stringify(require('util').parseArgs({ strict: false }).values)" ;
217220 const evalCodePrinted = `process.stdout.write(${ evalCode } )` ;
@@ -225,33 +228,21 @@ suite('correct default args', () => {
225228 '--print --eval <script>' : [ '--print' , '--eval' , evalCode ] ,
226229 '--print --eval=<script>' : [ '--print' , `--eval=${ evalCode } ` ] ,
227230 } ;
228- for ( const description in execArgsTests ) {
229- const execArgs = execArgsTests [ description ] ;
231+ for ( const [ description , execArgs ] of Object . entries ( execArgsTests ) ) {
230232 test ( description , async ( ) => {
231233 const { code, signal, stderr, stdout } = await spawnPromisified (
232234 process . execPath ,
233235 [ ...execArgs , '--' , '--foo' , '--bar' ] ) ;
234- assert . deepStrictEqual ( {
235- code,
236- signal,
237- stderr,
238- stdout : JSON . parse ( stdout ) ,
239- } , {
240- code : 0 ,
241- signal : null ,
242- stderr : '' ,
243- stdout : { foo : true , bar : true } ,
244- } ) ;
236+ assert . deepStrictEqual ( { code, signal, stderr, stdout : JSON . parse ( stdout ) } , expected ) ;
245237 } ) ;
246238 }
247239 } ) ;
248240
249- test ( 'without CLI flags' , ( ) => {
250- const holdArgv = process . argv ;
251- process . argv = [ process . argv0 , 'script.js' , '--foo' , '--bar' ] ;
252- const { values } = parseArgs ( { strict : false } ) ;
253- assert . deepStrictEqual ( values , { __proto__ : null , foo : true , bar : true } ) ;
254- process . argv = holdArgv ;
241+ test ( 'without CLI flags' , async ( ) => {
242+ const { code, signal, stderr, stdout } = await spawnPromisified (
243+ process . execPath ,
244+ [ path ( 'parse-args.js' ) , '--foo' , '--bar' ] ) ;
245+ assert . deepStrictEqual ( { code, signal, stderr, stdout : JSON . parse ( stdout ) } , expected ) ;
255246 } ) ;
256247} ) ;
257248
0 commit comments