11const { spawn : spawnChild , spawnSync } = require ( 'child_process' ) ;
22const arg = require ( 'arg' ) ;
3- const { shell, kill } = require ( './utils' ) ;
3+ const { shell, kill, sleep , waitOnChild } = require ( './utils' ) ;
44
55const npm = / ^ w i n / . test ( process . platform ) ? 'npm.cmd' : 'npm' ;
66
@@ -23,8 +23,8 @@ async function withWorker(workdir, fn) {
2323 }
2424}
2525
26- async function test ( workdir ) {
27- const { status, output } = spawnSync ( npm , [ 'run' , 'workflow' ] , {
26+ async function test ( workdir , scriptName , expectedOutput ) {
27+ const { status, output } = spawnSync ( npm , [ 'run' , scriptName ] , {
2828 cwd : workdir ,
2929 shell,
3030 encoding : 'utf8' ,
@@ -33,21 +33,25 @@ async function test(workdir) {
3333 if ( status !== 0 ) {
3434 throw new Error ( 'Failed to run workflow' ) ;
3535 }
36- if ( ! output [ 1 ] . includes ( 'Hello, Temporal!\n' ) ) {
36+ if ( ! output [ 1 ] . includes ( ` ${ expectedOutput } \n` ) ) {
3737 throw new Error ( `Invalid output: "${ output [ 1 ] } "` ) ;
3838 }
3939}
4040
4141async function main ( ) {
4242 const opts = arg ( {
4343 '--work-dir' : String ,
44+ '--script-name' : String ,
45+ '--expected-output' : String ,
4446 } ) ;
4547 const workdir = opts [ '--work-dir' ] ;
4648 if ( ! workdir ) {
4749 throw new Error ( 'Missing required option --work-dir' ) ;
4850 }
51+ const scriptName = opts [ '--script-name' ] ?? 'workflow' ;
52+ const expectedOutput = opts [ '--expected-output' ] ?? 'Hello, Temporal!' ;
4953
50- await withWorker ( workdir , ( ) => test ( workdir ) ) ;
54+ await withWorker ( workdir , ( ) => test ( workdir , scriptName , expectedOutput ) ) ;
5155}
5256
5357main ( )
0 commit comments