Skip to content

Commit 18f49dc

Browse files
committed
chore(workflows): silently run playwright axe tests
1 parent 0f3ee8b commit 18f49dc

File tree

3 files changed

+75
-25
lines changed

3 files changed

+75
-25
lines changed

.github/workflows/playwright.yml

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,61 @@
1-
name: Playwright Tests
1+
name: Playwright Accessibility Tests
2+
23
on:
3-
push:
4-
branches: [ main ]
54
pull_request:
6-
branches: [ main ]
5+
types: [opened, synchronize, reopened]
6+
77
jobs:
8-
test:
8+
playwright:
9+
name: Playwright
10+
runs-on: ubuntu-latest
911
timeout-minutes: 60
12+
outputs:
13+
issue_count: ${{ steps.playwright.outputs.issue_count }}
14+
steps:
15+
- name: Checkout repository from GitHub
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 20
22+
23+
- name: Install dependencies
24+
run: npm ci
25+
26+
- name: Install Playwright Browsers
27+
run: npx playwright install --with-deps
28+
29+
- name: Build app
30+
run: npm run build
31+
32+
- name: Serve preview
33+
run: npm run preview & npx wait-on http://localhost:4173
34+
35+
- name: Run Playwright tests
36+
run: npx playwright test || true
37+
38+
- name: Count Playwright accessibility issues
39+
id: playwright
40+
run: |
41+
issue_count=$(jq '. | length' playwright-a11y-violations.json)
42+
echo "issue_count=$issue_count" >> $GITHUB_OUTPUT
43+
44+
- name: Upload report artifact
45+
uses: actions/upload-artifact@v4
46+
if: ${{ !cancelled() }}
47+
with:
48+
name: playwright-report
49+
path: playwright-report/
50+
retention-days: 30
51+
52+
comment-on-pr:
53+
needs: playwright
54+
if: needs.playwright.outputs.issue_count != '0'
1055
runs-on: ubuntu-latest
1156
steps:
12-
- uses: actions/checkout@v4
13-
- uses: actions/setup-node@v4
14-
with:
15-
node-version: lts/*
16-
- name: Install dependencies
17-
run: npm ci
18-
- name: Install Playwright Browsers
19-
run: npx playwright install --with-deps
20-
- name: Run Playwright tests
21-
run: npx playwright test
22-
- uses: actions/upload-artifact@v4
23-
if: ${{ !cancelled() }}
24-
with:
25-
name: playwright-report
26-
path: playwright-report/
27-
retention-days: 30
57+
- name: Comment on PR
58+
uses: thollander/actions-comment-pull-request@v3
59+
with:
60+
message: "♿ Playwright detected ${{ needs.playwright.outputs.issue_count }} accessibility issue(s) – please review [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})."
61+
github-token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ dist-ssr
2929
/blob-report/
3030
/playwright/.cache/
3131
/playwright/.auth/
32+
playwright-a11y-violations.json

e2e/basic.spec.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1+
import fs from 'fs';
12
import AxeBuilder from '@axe-core/playwright';
2-
import {test, expect} from '@playwright/test';
3+
import {test} from '@playwright/test';
34

4-
test.only('BASIC', async ({page}) => {
5-
await page.goto('localhost:5173');
5+
test('BASIC', async ({page}, testInfo) => {
6+
await page.goto('http://localhost:4173');
67
await page.locator('#root').waitFor();
78

89
// Check the whole page
910
const axeBuilder = await new AxeBuilder({page})
1011
.withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'])
1112
.analyze();
12-
expect(axeBuilder.violations).toEqual([]);
13+
const violations = axeBuilder.violations;
14+
15+
// Write violations to json file
16+
fs.writeFileSync(
17+
'playwright-a11y-violations.json',
18+
JSON.stringify(violations, null, 2)
19+
);
20+
21+
// Add an info annotation if there are violations
22+
if (violations.length > 0) {
23+
testInfo.annotations.push({
24+
type: 'info',
25+
description: `Accessibility violations found: ${violations.length}`
26+
});
27+
}
1328
});

0 commit comments

Comments
 (0)