@@ -14,8 +14,15 @@ function run(cmd, args, options = {}) {
1414 shell : false ,
1515 env : process . env ,
1616 } ) ;
17+ let timer ;
18+ if ( options . timeoutMs && Number . isFinite ( options . timeoutMs ) ) {
19+ timer = setTimeout ( ( ) => {
20+ child . kill ( 'SIGTERM' ) ;
21+ } , options . timeoutMs ) ;
22+ }
1723 child . on ( 'error' , reject ) ;
1824 child . on ( 'exit' , ( code ) => {
25+ if ( timer ) clearTimeout ( timer ) ;
1926 if ( code === 0 ) resolve ( ) ;
2027 else reject ( new Error ( `${ cmd } ${ args . join ( ' ' ) } failed with code ${ code } ` ) ) ;
2128 } ) ;
@@ -37,6 +44,7 @@ const thresholds = {
3744 bestPractices : Number ( process . env . LH_MIN_BEST_PRACTICES ?? 90 ) ,
3845 seo : Number ( process . env . LH_MIN_SEO ?? 100 ) ,
3946} ;
47+ const lighthouseTimeoutMs = Number ( process . env . LH_TIMEOUT_MS ?? 120000 ) ;
4048
4149function assertThreshold ( route , score ) {
4250 const failures = Object . entries ( thresholds )
@@ -69,10 +77,11 @@ try {
6977 '--quiet' ,
7078 '--chrome-flags=--headless=new --no-sandbox' ,
7179 '--only-categories=performance,accessibility,best-practices,seo' ,
80+ '--max-wait-for-load=45000' ,
7281 '--output' ,
7382 'json' ,
7483 `--output-path=${ outputPath } ` ,
75- ] ) ;
84+ ] , { timeoutMs : lighthouseTimeoutMs } ) ;
7685 } ;
7786
7887 await runLighthouse ( 'http://127.0.0.1:4321' , reportPaths . home ) ;
0 commit comments