[READ-ONLY] Mirror of https://github.com/serhalp/npm.tax. npm supply chain risk explorer
npm.tax
npm
security
supply-chain-security
1import { expect, type Page, test } from "@playwright/test";
2import AxeBuilder from "@axe-core/playwright";
3
4async function expectNoAccessibilityViolations(page: Page) {
5 await expect(page.getByRole("heading", { name: "Tune the model" })).toBeVisible();
6
7 const results = await new AxeBuilder({ page })
8 .withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"])
9 .analyze();
10
11 const violations = results.violations.map(({ description, helpUrl, id, impact, nodes }) => ({
12 id,
13 impact,
14 description,
15 helpUrl,
16 nodes: nodes.map(({ failureSummary, target }) => ({
17 target,
18 failureSummary,
19 })),
20 }));
21
22 expect(violations, JSON.stringify(violations, null, 2)).toEqual([]);
23}
24
25for (const theme of ["light", "dark"] as const) {
26 test(`home page has no detectable accessibility violations in ${theme} mode`, async ({
27 page,
28 }) => {
29 await page.addInitScript((selectedTheme) => {
30 localStorage.setItem("theme", selectedTheme);
31 }, theme);
32
33 await page.goto("/");
34 await expectNoAccessibilityViolations(page);
35 });
36}
37
38test("home page controls expose accessible names", async ({ page }) => {
39 await page.goto("/");
40
41 await expect(page.getByRole("slider", { name: "Direct dependencies" })).toBeVisible();
42 await expect(page.getByRole("slider", { name: "Transitive dependencies" })).toBeVisible();
43 await expect(page.getByRole("slider", { name: "Time period" })).toBeVisible();
44 await expect(
45 page.getByRole("slider", { name: "Daily breach probability per package" }),
46 ).toBeVisible();
47 await expect(page.getByRole("textbox", { name: "Package name" })).toBeVisible();
48 await expect(page.getByRole("textbox", { name: "Version" })).toBeVisible();
49 await expect(
50 page.getByRole("textbox", { name: "Exact daily breach probability per package" }),
51 ).toBeVisible();
52 await expect(page.getByRole("img", { name: /cumulative breach probability/i })).toBeVisible();
53});