Skip to content

Commit

Permalink
test(docs-e2e): add lighthouse audit
Browse files Browse the repository at this point in the history
  • Loading branch information
MFarabi619 committed Dec 3, 2024
1 parent 7c2043f commit 5f9db96
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/docs-e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const baseURL = process.env.BASE_URL || 'http://127.0.0.1:3000'
*/
export default defineConfig({
...nxE2EPreset(__filename, { testDir: './src' }),
fullyParallel: true,
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
retries: 2,
use: {
Expand All @@ -37,6 +38,7 @@ export default defineConfig({
cwd: workspaceRoot,
timeout: 120 * 1000,
},
reporter: [['html']],
projects: [
{
name: 'chromium (desktop)',
Expand Down
52 changes: 52 additions & 0 deletions apps/docs-e2e/src/lighthouse.spec.ts
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`
},
})
})

0 comments on commit 5f9db96

Please sign in to comment.