-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(docs-e2e): add lighthouse audit
- Loading branch information
1 parent
7c2043f
commit 5f9db96
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import type { Browser } from 'playwright' | ||
import { chromium, test } from '@playwright/test' | ||
import getPort from 'get-port' | ||
import { playAudit } from 'playwright-lighthouse' | ||
|
||
const lighthouseTest = test.extend<{ Page }, { port: number, browser: Browser }>({ | ||
port: [ | ||
async (use) => { | ||
// Assign a unique port for each playwright worker to support parallel tests | ||
const port = await getPort() | ||
await use(port) | ||
}, | ||
{ scope: 'worker' }, | ||
], | ||
|
||
browser: [ | ||
async ({ port }, use) => { | ||
const browser = await chromium.launch({ | ||
args: [`--remote-debugging-port=${port}`], | ||
}) | ||
await use(browser) | ||
}, | ||
{ scope: 'worker' }, | ||
], | ||
}) | ||
|
||
const thresholdsConfig = { | ||
'performance': 90, | ||
'accessibility': 90, | ||
'best-practices': 90, | ||
'seo': 90, | ||
// 'pwa': 50, | ||
} | ||
|
||
lighthouseTest('should pass lighthouse audits', async ({ page, port }) => { | ||
await page.goto('/') | ||
|
||
await playAudit({ | ||
page, | ||
port, | ||
thresholds: thresholdsConfig, | ||
reports: { | ||
formats: { | ||
// json: true, // defaults to false | ||
html: true, // defaults to false | ||
// csv: true, // defaults to false | ||
}, | ||
name: `latest-report`, // defaults to `lighthouse-${new Date().getTime()}` | ||
directory: `${process.cwd()}../../../lighthouse-report`, // defaults to `${process.cwd()}/lighthouse` | ||
}, | ||
}) | ||
}) |