@@ -4,13 +4,13 @@ import { fileURLToPath } from 'url';
44
55const DEBUG = ! ! process . env . DEBUG ;
66
7- const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
7+ const packageRoot = join ( dirname ( fileURLToPath ( import . meta. url ) ) , '..' ) ;
88
99async function getMeasurements ( instrumentFile ) {
10- const args = [ join ( __dirname , '. ./src/app.mjs' ) ] ;
10+ const args = [ join ( packageRoot , './src/app.mjs' ) ] ;
1111
1212 if ( instrumentFile ) {
13- args . unshift ( '--import' , join ( __dirname , '..' , instrumentFile ) ) ;
13+ args . unshift ( '--import' , join ( packageRoot , instrumentFile ) ) ;
1414 }
1515
1616 const cmd = `node ${ args . join ( ' ' ) } ` ;
@@ -32,13 +32,15 @@ async function getMeasurements(instrumentFile) {
3232 appProcess . stderr . on ( 'data' , data => {
3333 log ( `appProcess stderr: ${ data } ` ) ;
3434 reject ( data ) ;
35+ appProcess . kill ( ) ;
3536 } ) ;
3637 } ) ;
3738
3839 log ( 'Example app listening, running autocannon...' ) ;
3940
4041 const autocannon = spawn ( 'yarn test' , {
4142 shell : true ,
43+ cwd : packageRoot ,
4244 } ) ;
4345
4446 let lastJson = undefined ;
@@ -51,11 +53,13 @@ async function getMeasurements(instrumentFile) {
5153 }
5254 } ) ;
5355
54- autocannon . stderr . on ( 'data' , data => {
55- log ( `autocannon stderr: ${ data } ` ) ;
56- } ) ;
56+ return new Promise ( ( resolve , reject ) => {
57+ autocannon . stderr . on ( 'data' , data => {
58+ log ( `autocannon stderr: ${ data } ` ) ;
59+ autocannon . kill ( ) ;
60+ reject ( data ) ;
61+ } ) ;
5762
58- return new Promise ( resolve => {
5963 autocannon . on ( 'close' , code => {
6064 log ( `autocannon closed with code ${ code } ` ) ;
6165
0 commit comments