-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlighthouse.ts
56 lines (46 loc) · 1.33 KB
/
lighthouse.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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");
});
});