Skip to content

Commit 62b9475

Browse files
committed
ci: run lighthouse a11y tests in both light + dark mode
1 parent 3c84708 commit 62b9475

4 files changed

Lines changed: 49 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
- name: 🏗️ Build project
9292
run: pnpm build
9393

94-
- name: ♿ Accessibility audit (Lighthouse)
95-
run: pnpx @lhci/cli autorun
94+
- name: ♿ Accessibility audit (Lighthouse - dark & light mode)
95+
run: ./scripts/lighthouse-a11y.sh
9696
env:
9797
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}

.lighthouserc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"http://localhost:3000/nuxt"
1010
],
1111
"numberOfRuns": 1,
12+
"puppeteerScript": "./lighthouse-setup.js",
1213
"settings": {
1314
"onlyCategories": ["accessibility"],
1415
"skipAudits": ["valid-source-maps"]

lighthouse-setup.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Lighthouse CI puppeteer setup script.
3+
* Sets the color mode (light/dark) before running accessibility audits.
4+
*
5+
* The color mode is determined by the LIGHTHOUSE_COLOR_MODE environment variable.
6+
* If not set, defaults to 'dark'.
7+
*/
8+
9+
/** @param {import('puppeteer').Browser} browser */
10+
export default async function setup(browser, { url }) {
11+
const colorMode = process.env.LIGHTHOUSE_COLOR_MODE || 'dark'
12+
const page = await browser.newPage()
13+
14+
// Set localStorage before navigating so @nuxtjs/color-mode picks it up
15+
await page.evaluateOnNewDocument(mode => {
16+
localStorage.setItem('npmx-color-mode', mode)
17+
}, colorMode)
18+
19+
await page.goto(url, { waitUntil: 'networkidle0' })
20+
21+
// Also set the data-theme attribute directly to ensure the mode is applied
22+
await page.evaluate(mode => {
23+
document.documentElement.setAttribute('data-theme', mode)
24+
}, colorMode)
25+
26+
// Close the page - Lighthouse will open its own
27+
await page.close()
28+
}

scripts/lighthouse-a11y.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
# Run Lighthouse accessibility tests in both light and dark mode
3+
#
4+
# This script runs lhci autorun twice, once for each color mode.
5+
# The LIGHTHOUSE_COLOR_MODE env var is read by lighthouse-setup.js
6+
# to set the appropriate theme before each audit.
7+
8+
set -e
9+
10+
echo "🌙 Running Lighthouse accessibility audit (dark mode)..."
11+
LIGHTHOUSE_COLOR_MODE=dark pnpx @lhci/cli autorun
12+
13+
echo ""
14+
echo "☀️ Running Lighthouse accessibility audit (light mode)..."
15+
LIGHTHOUSE_COLOR_MODE=light pnpx @lhci/cli autorun
16+
17+
echo ""
18+
echo "✅ Accessibility audits completed for both color modes"

0 commit comments

Comments
 (0)