@@ -16,6 +16,8 @@ export function help (opts = {}) {
16
16
--test=@expressjs/perf-load-example
17
17
--node=lts_latest
18
18
--overrides='{"express":"latest"}'
19
+ --config=./expf.config.json
20
+ --[no-]write
19
21
`
20
22
}
21
23
@@ -25,13 +27,36 @@ export default function main (_opts = {}) {
25
27
return ;
26
28
}
27
29
return new Promise ( async ( resolve , reject ) => {
30
+ const cwd = normalize ( join ( import . meta. dirname , '..' , '..' ) ) ;
31
+
32
+ let conf = { } ;
33
+ try {
34
+ conf = ( await import ( join ( cwd , _opts . config || 'expf.config.json' ) , {
35
+ with : {
36
+ type : 'json'
37
+ }
38
+ } ) ) . default ;
39
+ } catch ( err ) {
40
+ // Only throw if config was explicitly passed, not if we failed to load the default file
41
+ if ( _opts . config ) {
42
+ throw new Error ( 'Failed to load config file' , {
43
+ cause : err
44
+ } ) ;
45
+ }
46
+ // Warn when a config file was found but was not loadable
47
+ if ( err . code !== 'ERR_MODULE_NOT_FOUND' ) {
48
+ process . emitWarning ( err ) ;
49
+ }
50
+ }
51
+
28
52
const opts = {
29
- cwd : normalize ( join ( import . meta . dirname , '..' , '..' ) ) ,
53
+ cwd,
30
54
repo : 'https://github.com/expressjs/perf-wg.git' ,
31
55
repoRef : 'master' ,
32
56
runner : '@expressjs/perf-runner-docker' ,
33
57
test : '@expressjs/perf-load-example' ,
34
58
node : 'lts_latest' ,
59
+ ...conf ,
35
60
..._opts
36
61
} ;
37
62
@@ -82,10 +107,14 @@ export default function main (_opts = {}) {
82
107
signal : ac . signal
83
108
} ) ;
84
109
85
- const outputFile = join ( dirname ( import . meta. resolve ( opts . test ) . replace ( / ^ f i l e : / , '' ) ) , 'results' , 'result-' + Date . now ( ) + '.json' ) ;
86
- await mkdir ( dirname ( outputFile ) , { recursive : true } ) ;
87
- await writeFile ( outputFile , JSON . stringify ( results , null , 2 ) ) ;
88
- console . log ( `written to: ${ outputFile } ` ) ;
110
+ if ( opts . write !== false ) {
111
+ const outputFile = join ( dirname ( import . meta. resolve ( opts . test ) . replace ( / ^ f i l e : / , '' ) ) , 'results' , 'result-' + Date . now ( ) + '.json' ) ;
112
+ await mkdir ( dirname ( outputFile ) , { recursive : true } ) ;
113
+ await writeFile ( outputFile , JSON . stringify ( results , null , 2 ) ) ;
114
+ console . log ( `written to: ${ outputFile } ` ) ;
115
+ } else {
116
+ console . log ( results ) ;
117
+ }
89
118
} catch ( e ) {
90
119
console . error ( e ) ;
91
120
}
0 commit comments