Skip to content

Commit ed31df8

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

File tree

3 files changed

+68
-24
lines changed

3 files changed

+68
-24
lines changed

.github/workflows/playwright.yml

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,55 @@
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: Run Playwright tests
30+
run: npx playwright test || †rue
31+
32+
- name: Upload report artifact
33+
uses: actions/upload-artifact@v4
34+
if: ${{ !cancelled() }}
35+
with:
36+
name: playwright-report
37+
path: playwright-report/
38+
retention-days: 30
39+
40+
- name: Count Playwright accessibility issues
41+
id: playwright
42+
run: |
43+
issue_count=$(jq '. | length' playwright-a11y-violations.json)
44+
echo "issue_count=$issue_count" >> $GITHUB_OUTPUT
45+
46+
comment-on-pr:
47+
needs: playwright
48+
if: needs.playwright.outputs.issue_count != '0'
1049
runs-on: ubuntu-latest
1150
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
51+
- name: Comment on PR
52+
uses: thollander/actions-comment-pull-request@v3
53+
with:
54+
message: "♿ Playwright detected ${{ needs.playwright.outputs.issue_count }} accessibility issue(s) – please review [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})."
55+
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: 18 additions & 3 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+
test('BASIC', async ({page}, testInfo) => {
56
await page.goto('localhost:5173');
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)