Skip to content

Commit 4a6d0b6

Browse files
committed
test: add 0 cls standard
1 parent d06e64b commit 4a6d0b6

4 files changed

Lines changed: 52 additions & 13 deletions

File tree

.lighthouserc.cjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,18 @@ module.exports = {
3535
chromePath: findChrome(),
3636
puppeteerScript: './lighthouse-setup.cjs',
3737
settings: {
38-
onlyCategories: ['accessibility'],
38+
onlyCategories: process.env.LH_PERF ? ['performance'] : ['accessibility'],
3939
skipAudits: ['valid-source-maps'],
4040
},
4141
},
4242
assert: {
43-
assertions: {
44-
'categories:accessibility': ['error', { minScore: 1 }],
45-
},
43+
assertions: process.env.LH_PERF
44+
? {
45+
'cumulative-layout-shift': ['error', { maxNumericValue: 0 }],
46+
}
47+
: {
48+
'categories:accessibility': ['error', { minScore: 1 }],
49+
},
4650
},
4751
upload: {
4852
target: 'temporary-public-storage',

CONTRIBUTING.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ This focus helps guide our project decisions as a community and what we choose t
5454
- [Unit tests](#unit-tests)
5555
- [Component accessibility tests](#component-accessibility-tests)
5656
- [Lighthouse accessibility tests](#lighthouse-accessibility-tests)
57+
- [Lighthouse performance tests](#lighthouse-performance-tests)
5758
- [End to end tests](#end-to-end-tests)
5859
- [Test fixtures (mocking external APIs)](#test-fixtures-mocking-external-apis)
5960
- [Submitting changes](#submitting-changes)
@@ -114,6 +115,7 @@ pnpm test:unit # Unit tests only
114115
pnpm test:nuxt # Nuxt component tests
115116
pnpm test:browser # Playwright E2E tests
116117
pnpm test:a11y # Lighthouse accessibility audits
118+
pnpm test:perf # Lighthouse performance audits (CLS)
117119
```
118120

119121
### Project structure
@@ -641,18 +643,38 @@ pnpm test:a11y:prebuilt
641643

642644
# Or run a single color mode manually
643645
pnpm build:test
644-
LIGHTHOUSE_COLOR_MODE=dark ./scripts/lighthouse-a11y.sh
646+
LIGHTHOUSE_COLOR_MODE=dark ./scripts/lighthouse.sh
645647
```
646648

647649
This requires Chrome or Chromium to be installed. The script will auto-detect common installation paths. Results are printed to the terminal and saved in `.lighthouseci/`.
648650

649651
#### Configuration
650652

651-
| File | Purpose |
652-
| ---------------------------- | --------------------------------------------------------- |
653-
| `.lighthouserc.cjs` | Lighthouse CI config (URLs, assertions, Chrome path) |
654-
| `lighthouse-setup.cjs` | Puppeteer script for color mode + client-side API mocking |
655-
| `scripts/lighthouse-a11y.sh` | Shell wrapper that runs the audit for a given color mode |
653+
| File | Purpose |
654+
| ----------------------- | --------------------------------------------------------- |
655+
| `.lighthouserc.cjs` | Lighthouse CI config (URLs, assertions, Chrome path) |
656+
| `lighthouse-setup.cjs` | Puppeteer script for color mode + client-side API mocking |
657+
| `scripts/lighthouse.sh` | Shell wrapper that runs the audit for a given color mode |
658+
659+
### Lighthouse performance tests
660+
661+
The project also runs Lighthouse performance audits to enforce zero Cumulative Layout Shift (CLS). These run separately from the accessibility audits and test the same set of URLs.
662+
663+
#### How it works
664+
665+
The same `.lighthouserc.cjs` config is shared between accessibility and performance audits. When the `LH_PERF` environment variable is set, the config switches from the `accessibility` category to the `performance` category and asserts that CLS is exactly 0.
666+
667+
#### Running locally
668+
669+
```bash
670+
# Build + run performance audit
671+
pnpm test:perf
672+
673+
# Or against an existing test build
674+
pnpm test:perf:prebuilt
675+
```
676+
677+
Unlike the accessibility audits, performance audits do not run in separate light/dark modes.
656678

657679
### End to end tests
658680

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
"generate:lexicons": "lex build --lexicons lexicons --out shared/types/lexicons --clear",
3535
"test": "vite test",
3636
"test:a11y": "pnpm build:test && LIGHTHOUSE_COLOR_MODE=dark pnpm test:a11y:prebuilt && LIGHTHOUSE_COLOR_MODE=light pnpm test:a11y:prebuilt",
37-
"test:a11y:prebuilt": "./scripts/lighthouse-a11y.sh",
37+
"test:a11y:prebuilt": "./scripts/lighthouse.sh",
38+
"test:perf": "pnpm build:test && pnpm test:perf:prebuilt",
39+
"test:perf:prebuilt": "LH_PERF=1 ./scripts/lighthouse.sh",
3840
"test:browser": "pnpm build:test && pnpm test:browser:prebuilt",
3941
"test:browser:prebuilt": "playwright test",
4042
"test:browser:ui": "pnpm build:test && pnpm test:browser:prebuilt --ui",
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
#!/bin/bash
2-
# Run Lighthouse accessibility tests in both light and dark mode
2+
# Run Lighthouse CI audits.
3+
#
4+
# Modes:
5+
# - Accessibility (default): requires LIGHTHOUSE_COLOR_MODE (dark/light)
6+
# - Performance: set LH_PERF=1 (no color mode needed)
37
#
4-
# This script runs lhci autorun twice, once for each color mode.
58
# The LIGHTHOUSE_COLOR_MODE env var is read by lighthouse-setup.cjs
69
# to set the appropriate theme before each audit.
710

811
set -e
912

13+
if [ -n "${LH_PERF}" ]; then
14+
echo "⚡ Running Lighthouse performance audit (CLS)..."
15+
pnpx @lhci/cli autorun --upload.githubStatusContextSuffix="/perf"
16+
echo ""
17+
echo "✅ Performance audit completed"
18+
exit 0
19+
fi
20+
1021
case "${LIGHTHOUSE_COLOR_MODE}" in
1122
dark)
1223
echo "🌙 Running Lighthouse accessibility audit (dark mode)..."

0 commit comments

Comments
 (0)