@@ -4,13 +4,13 @@ import { fileURLToPath } from 'url';
4
4
5
5
const DEBUG = ! ! process . env . DEBUG ;
6
6
7
- const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
7
+ const packageRoot = join ( dirname ( fileURLToPath ( import . meta. url ) ) , '..' ) ;
8
8
9
9
async function getMeasurements ( instrumentFile ) {
10
- const args = [ join ( __dirname , '. ./src/app.mjs' ) ] ;
10
+ const args = [ join ( packageRoot , './src/app.mjs' ) ] ;
11
11
12
12
if ( instrumentFile ) {
13
- args . unshift ( '--import' , join ( __dirname , '..' , instrumentFile ) ) ;
13
+ args . unshift ( '--import' , join ( packageRoot , instrumentFile ) ) ;
14
14
}
15
15
16
16
const cmd = `node ${ args . join ( ' ' ) } ` ;
@@ -32,13 +32,15 @@ async function getMeasurements(instrumentFile) {
32
32
appProcess . stderr . on ( 'data' , data => {
33
33
log ( `appProcess stderr: ${ data } ` ) ;
34
34
reject ( data ) ;
35
+ appProcess . kill ( ) ;
35
36
} ) ;
36
37
} ) ;
37
38
38
39
log ( 'Example app listening, running autocannon...' ) ;
39
40
40
41
const autocannon = spawn ( 'yarn test' , {
41
42
shell : true ,
43
+ cwd : packageRoot ,
42
44
} ) ;
43
45
44
46
let lastJson = undefined ;
@@ -51,11 +53,13 @@ async function getMeasurements(instrumentFile) {
51
53
}
52
54
} ) ;
53
55
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
+ } ) ;
57
62
58
- return new Promise ( resolve => {
59
63
autocannon . on ( 'close' , code => {
60
64
log ( `autocannon closed with code ${ code } ` ) ;
61
65
0 commit comments