@@ -6,8 +6,6 @@ import path from 'node:path';
66import { spawnSync } from 'node:child_process' ;
77
88const isWindows = os . platform ( ) === 'win32' ;
9- const fixturesDir = path . join ( import . meta. dirname , '../../test/fixtures' ) ;
10- const distDir = path . join ( import . meta. dirname , '../../dist' ) ;
119
1210const variants = [
1311 { name : 'async' , x, isAsync : true } ,
@@ -368,79 +366,40 @@ if (!isWindows) {
368366 } ) ;
369367
370368 test ( 'resolves when grandchild holds piped stdout open' , async ( ) => {
371- const dir = fs . mkdtempSync (
372- path . join ( os . tmpdir ( ) , 'tinyexec-grandchild-' )
373- ) ;
374- const runnerScript = path . join ( dir , 'runner.mjs' ) ;
375- const distPath = JSON . stringify ( path . join ( distDir , 'main.mjs' ) ) ;
376- const fixturePath = JSON . stringify (
377- path . join ( fixturesDir , 'grandchild.mjs' )
378- ) ;
379-
380- fs . writeFileSync (
381- runnerScript ,
382- `import { x } from ${ distPath }
383- const result = await x('node', [${ fixturePath } ])
384- process.stdout.write(JSON.stringify({ stdout: result.stdout, exitCode: result.exitCode }))
385- `
386- ) ;
387-
388- try {
389- const proc = spawnSync ( 'node' , [ runnerScript ] , {
390- timeout : 10000 ,
369+ const proc = spawnSync (
370+ 'node' ,
371+ [ 'test/fixtures/spawn_grandchild.mjs' , 'grandchild.mjs' ] ,
372+ {
373+ timeout : 10_000 ,
391374 encoding : 'utf8' ,
392375 killSignal : 'SIGKILL' ,
393376 stdio : [ 'pipe' , 'pipe' , 'pipe' ]
394- } ) ;
377+ }
378+ ) ;
395379
396- expect ( proc . signal ) . not . toBe ( 'SIGKILL' ) ;
397- expect ( proc . status ) . toBe ( 0 ) ;
398- const parsed = JSON . parse ( proc . stdout . trim ( ) ) ;
399- expect ( parsed . exitCode ) . toBe ( 0 ) ;
400- expect ( parsed . stdout ) . toBe ( 'output\n' ) ;
401- } finally {
402- spawnSync ( 'pkill' , [ '-f' , 'tinyexec-test-grandchild' ] ) ;
403- fs . rmSync ( dir , { recursive : true , force : true } ) ;
404- }
380+ expect ( proc . signal ) . not . toBe ( 'SIGKILL' ) ;
381+ expect ( proc . status ) . toBe ( 0 ) ;
382+ const parsed = JSON . parse ( proc . stdout . trim ( ) ) ;
383+ expect ( parsed . exitCode ) . toBe ( 0 ) ;
384+ expect ( parsed . stdout ) . toBe ( 'output\n' ) ;
405385 } ) ;
406386
407387 test ( 'iterator completes when grandchild holds piped stdout open' , async ( ) => {
408- const dir = fs . mkdtempSync (
409- path . join ( os . tmpdir ( ) , 'tinyexec-grandchild-' )
410- ) ;
411- const runnerScript = path . join ( dir , 'runner.mjs' ) ;
412- const distPath = JSON . stringify ( path . join ( distDir , 'main.mjs' ) ) ;
413- const fixturePath = JSON . stringify (
414- path . join ( fixturesDir , 'grandchild_multiline.mjs' )
415- ) ;
416-
417- fs . writeFileSync (
418- runnerScript ,
419- `import { x } from ${ distPath }
420- const lines = []
421- for await (const line of x('node', [${ fixturePath } ])) {
422- lines.push(line)
423- }
424- process.stdout.write(JSON.stringify(lines))
425- `
426- ) ;
427-
428- try {
429- const proc = spawnSync ( 'node' , [ runnerScript ] , {
430- timeout : 10000 ,
388+ const proc = spawnSync (
389+ 'node' ,
390+ [ 'test/fixtures/spawn_grandchild_iterator.mjs' ] ,
391+ {
392+ timeout : 10_000 ,
431393 encoding : 'utf8' ,
432394 killSignal : 'SIGKILL' ,
433395 stdio : [ 'pipe' , 'pipe' , 'pipe' ]
434- } ) ;
396+ }
397+ ) ;
435398
436- expect ( proc . signal ) . not . toBe ( 'SIGKILL' ) ;
437- expect ( proc . status ) . toBe ( 0 ) ;
438- const parsed = JSON . parse ( proc . stdout . trim ( ) ) ;
439- expect ( parsed ) . toEqual ( [ 'line1' , 'line2' ] ) ;
440- } finally {
441- spawnSync ( 'pkill' , [ '-f' , 'tinyexec-test-grandchild' ] ) ;
442- fs . rmSync ( dir , { recursive : true , force : true } ) ;
443- }
399+ expect ( proc . signal ) . not . toBe ( 'SIGKILL' ) ;
400+ expect ( proc . status ) . toBe ( 0 ) ;
401+ const parsed = JSON . parse ( proc . stdout . trim ( ) ) ;
402+ expect ( parsed ) . toEqual ( [ 'line1' , 'line2' ] ) ;
444403 } ) ;
445404 } ) ;
446405
0 commit comments