1
1
import { AxePuppeteer } from '@axe-core/puppeteer' ;
2
- import { Result } from 'axe-core' ;
2
+ import { Result as AxeResult } from 'axe-core' ;
3
3
import puppeteer from 'puppeteer' ;
4
4
import { callWithTimeout } from '../../utils/timeout.js' ;
5
5
import { AutoCsp } from './auto-csp.js' ;
6
6
import { 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' ;
8
9
9
10
/**
10
11
* Uses Puppeteer to take a screenshot of the main page, perform Axe testing,
@@ -18,13 +19,15 @@ export async function runAppInPuppeteer(
18
19
includeAxeTesting : boolean ,
19
20
progressLog : ServeTestingProgressLogFn ,
20
21
enableAutoCsp : boolean ,
22
+ includeLighthouseData : boolean ,
21
23
) {
22
24
const runtimeErrors : string [ ] = [ ] ;
23
25
24
26
// Undefined by default so it gets flagged correctly as `skipped` if there's no data.
25
27
let cspViolations : CspViolation [ ] | undefined ;
26
28
let screenshotBase64Data : string | undefined ;
27
- let axeViolations : Result [ ] | undefined ;
29
+ let axeViolations : AxeResult [ ] | undefined ;
30
+ let lighthouseResult : LighthouseResult | undefined ;
28
31
29
32
try {
30
33
const browser = await puppeteer . launch ( {
@@ -139,6 +142,22 @@ export async function runAppInPuppeteer(
139
142
) ;
140
143
progressLog ( 'success' , 'Screenshot captured and encoded' ) ;
141
144
}
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
+
142
161
await browser . close ( ) ;
143
162
} catch ( screenshotError : any ) {
144
163
let details : string = screenshotError . message ;
@@ -150,5 +169,5 @@ export async function runAppInPuppeteer(
150
169
progressLog ( 'error' , 'Could not take screenshot' , details ) ;
151
170
}
152
171
153
- return { screenshotBase64Data, runtimeErrors, axeViolations, cspViolations} ;
172
+ return { screenshotBase64Data, runtimeErrors, axeViolations, cspViolations, lighthouseResult } ;
154
173
}
0 commit comments