-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
970 additions
and
10 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,41 @@ | ||
import AxeBuilder from "@axe-core/playwright"; | ||
import { type Page, expect, test } from "@playwright/test"; | ||
import type axe from "axe-core"; | ||
import { createHtmlReport } from "axe-html-reporter"; | ||
|
||
import { attachReport, clientCredentials, throwOnConsoleError } from "./utils"; | ||
|
||
const htmlReport = async (name: string, results: axe.AxeResults) => { | ||
const reportFileName = `${test.info().project.name}-${name}.html`; | ||
|
||
createHtmlReport({ | ||
results, | ||
options: { | ||
outputDir: "reports/a11y", | ||
reportFileName | ||
} | ||
}); | ||
|
||
return `reports/a11y/${reportFileName}`; | ||
}; | ||
|
||
const a11y = async (name: string, page: Page) => { | ||
const results = await new AxeBuilder({ page }).analyze(); | ||
const path = await htmlReport(name, results); | ||
await attachReport("axe-report", path); | ||
|
||
return results; | ||
}; | ||
|
||
test.describe("accessibility", () => { | ||
test.describe.configure({ mode: "serial" }); | ||
|
||
test("home", async ({ page }) => { | ||
throwOnConsoleError(page); | ||
await clientCredentials(page); | ||
|
||
await page.goto("/"); | ||
const results = await a11y("home", page); | ||
expect(results.violations).toEqual([]); | ||
}); | ||
}); |
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,56 @@ | ||
import test, { type BrowserContext, type Page, chromium } from "@playwright/test"; | ||
import { playAudit } from "playwright-lighthouse"; | ||
|
||
import { attachReport, clientCredentials } from "./utils"; | ||
|
||
const threshold = process.env.LIGHTHOUSE_THRESHOLD | ||
? Number(process.env.LIGHTHOUSE_THRESHOLD) | ||
: 0; | ||
|
||
const lighthouse = async (page: Page, name: string) => { | ||
await playAudit({ | ||
page, | ||
port: 9222, | ||
thresholds: { | ||
performance: threshold, | ||
accessibility: threshold, | ||
"best-practices": threshold, | ||
seo: threshold, | ||
pwa: threshold | ||
}, | ||
reports: { | ||
name, | ||
directory: "reports/lighthouse/", | ||
formats: { | ||
json: false, | ||
html: true | ||
} | ||
} | ||
}); | ||
|
||
await attachReport("lighthouse-report", `reports/lighthouse/${name}.html`); | ||
}; | ||
|
||
test.describe("lighthouse", () => { | ||
test.describe.configure({ mode: "serial" }); | ||
|
||
let context: BrowserContext; | ||
|
||
test.beforeAll(async () => { | ||
context = await chromium.launchPersistentContext(".playwright/chromium-lighthouse", { | ||
args: ["--remote-debugging-port=9222", "--ignore-certificate-errors"] | ||
}); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await context.close(); | ||
}); | ||
|
||
test("home", async () => { | ||
const page = await context.newPage(); | ||
await clientCredentials(page); | ||
|
||
await page.goto("/"); | ||
await lighthouse(page, "home"); | ||
}); | ||
}); |
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
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
Oops, something went wrong.