forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlighthouse-setup.cjs
More file actions
24 lines (20 loc) · 898 Bytes
/
lighthouse-setup.cjs
File metadata and controls
24 lines (20 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* Lighthouse CI puppeteer setup script.
* Sets the color mode (light/dark) before running accessibility audits.
*
* The color mode is determined by the LIGHTHOUSE_COLOR_MODE environment variable.
* If not set, defaults to 'dark'.
*/
/** @param {import('puppeteer').Browser} browser */
module.exports = async function setup(browser, { url }) {
const colorMode = process.env.LIGHTHOUSE_COLOR_MODE || 'dark'
const page = await browser.newPage()
// Set localStorage before navigating so @nuxtjs/color-mode picks it up
await page.evaluateOnNewDocument(mode => {
localStorage.setItem('npmx-color-mode', mode)
}, colorMode)
// Navigate and wait for DOM only - Lighthouse will do its own full load
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 60000 })
// Close the page - Lighthouse will open its own with localStorage already set
await page.close()
}