11import { AxePuppeteer } from '@axe-core/puppeteer' ;
2- import { Result } from 'axe-core' ;
2+ import { Result as AxeResult } from 'axe-core' ;
33import puppeteer from 'puppeteer' ;
44import { callWithTimeout } from '../../utils/timeout.js' ;
55import { AutoCsp } from './auto-csp.js' ;
66import { CspViolation } from './auto-csp-types.js' ;
7- import { ServeTestingProgressLogFn } from './worker-types.js' ;
7+ import { LighthouseResult , ServeTestingProgressLogFn } from './worker-types.js' ;
8+ import { getLighthouseData } from './lighthouse.js' ;
89
910/**
1011 * Uses Puppeteer to take a screenshot of the main page, perform Axe testing,
@@ -18,13 +19,15 @@ export async function runAppInPuppeteer(
1819 includeAxeTesting : boolean ,
1920 progressLog : ServeTestingProgressLogFn ,
2021 enableAutoCsp : boolean ,
22+ includeLighthouseData : boolean ,
2123) {
2224 const runtimeErrors : string [ ] = [ ] ;
2325
2426 // Undefined by default so it gets flagged correctly as `skipped` if there's no data.
2527 let cspViolations : CspViolation [ ] | undefined ;
2628 let screenshotBase64Data : string | undefined ;
27- let axeViolations : Result [ ] | undefined ;
29+ let axeViolations : AxeResult [ ] | undefined ;
30+ let lighthouseResult : LighthouseResult | undefined ;
2831
2932 try {
3033 const browser = await puppeteer . launch ( {
@@ -139,6 +142,22 @@ export async function runAppInPuppeteer(
139142 ) ;
140143 progressLog ( 'success' , 'Screenshot captured and encoded' ) ;
141144 }
145+
146+ if ( includeLighthouseData ) {
147+ try {
148+ progressLog ( 'eval' , `Gathering Lighthouse data from ${ hostUrl } ` ) ;
149+ lighthouseResult = await getLighthouseData ( hostUrl , page ) ;
150+
151+ if ( lighthouseResult ) {
152+ progressLog ( 'success' , 'Lighthouse data has been collected' ) ;
153+ } else {
154+ progressLog ( 'error' , 'Lighthouse did not produce usable data' ) ;
155+ }
156+ } catch ( lighthouseError : any ) {
157+ progressLog ( 'error' , 'Could not gather Lighthouse data' , lighthouseError . message ) ;
158+ }
159+ }
160+
142161 await browser . close ( ) ;
143162 } catch ( screenshotError : any ) {
144163 let details : string = screenshotError . message ;
@@ -150,5 +169,5 @@ export async function runAppInPuppeteer(
150169 progressLog ( 'error' , 'Could not take screenshot' , details ) ;
151170 }
152171
153- return { screenshotBase64Data, runtimeErrors, axeViolations, cspViolations} ;
172+ return { screenshotBase64Data, runtimeErrors, axeViolations, cspViolations, lighthouseResult } ;
154173}
0 commit comments