|
1 | 1 | import { formatWCAGTag } from '../support/formatWCAGTag' |
2 | 2 |
|
3 | | -describe('a11y tests', () => { |
4 | | - const pages = ['/'] |
| 3 | +describe('accessibility tests', () => { |
| 4 | + const pages = ['/', '/admin'] |
5 | 5 |
|
6 | 6 | pages.forEach((page) => { |
7 | 7 | it(`WCAG 2.2 accessibility evaluation of ${ |
8 | 8 | page === '/' ? 'Homepage' : page |
9 | 9 | }`, () => { |
10 | | - cy.visit(page, { failOnStatusCode: false }) |
11 | | - cy.injectAxe() |
| 10 | + cy.request({ |
| 11 | + url: page, |
| 12 | + failOnStatusCode: false, |
| 13 | + }).then((response) => { |
| 14 | + const statusCode = response.status |
12 | 15 |
|
13 | | - const safeName = page.replace(/^\//, '').toLowerCase() |
14 | | - const reportPath = `cypress/reports/a11y-report-wcag-${ |
15 | | - safeName === '' ? 'homepage' : safeName |
16 | | - }.json` |
| 16 | + if (statusCode >= 400) { |
| 17 | + cy.task( |
| 18 | + 'log', |
| 19 | + '\n====================================================================================' |
| 20 | + ) |
| 21 | + cy.task( |
| 22 | + 'log', |
| 23 | + `⚠️ Skipping Accessibility Check: ${page} failed to load (Status: ${statusCode}).` |
| 24 | + ) |
| 25 | + cy.task( |
| 26 | + 'log', |
| 27 | + '====================================================================================' |
| 28 | + ) |
| 29 | + return |
| 30 | + } |
| 31 | + cy.visit(page) |
| 32 | + cy.injectAxe() |
17 | 33 |
|
18 | | - cy.window() |
19 | | - .its('axe') |
20 | | - .then((axe) => { |
21 | | - const options = { |
22 | | - runOnly: { |
23 | | - type: 'tag', |
24 | | - values: [ |
25 | | - 'wcag2a', |
26 | | - 'wcag2aa', |
27 | | - 'wcag21a', |
28 | | - 'wcag21aa', |
29 | | - 'wcag22a', |
30 | | - 'wcag22aa', |
31 | | - ], |
32 | | - }, |
33 | | - } |
| 34 | + const safeName = page.replace(/^\//, '').toLowerCase() |
| 35 | + const reportPath = `cypress/reports/a11y-report-wcag-${ |
| 36 | + safeName === '' ? 'homepage' : safeName |
| 37 | + }.json` |
34 | 38 |
|
35 | | - return axe.run(options).then((results) => { |
36 | | - cy.task( |
37 | | - 'log', |
38 | | - `\n=== WCAG 2.2 accessibility evaluation of ${ |
39 | | - page === '/' ? 'Homepage' : page |
40 | | - } ===` |
41 | | - ) |
| 39 | + cy.window() |
| 40 | + .its('axe') |
| 41 | + .then((axe) => { |
| 42 | + const options = { |
| 43 | + runOnly: { |
| 44 | + type: 'tag', |
| 45 | + values: [ |
| 46 | + 'wcag2a', |
| 47 | + 'wcag2aa', |
| 48 | + 'wcag21a', |
| 49 | + 'wcag21aa', |
| 50 | + 'wcag22a', |
| 51 | + 'wcag22aa', |
| 52 | + ], |
| 53 | + }, |
| 54 | + } |
42 | 55 |
|
43 | | - const categories = [ |
44 | | - { key: 'violations', label: `❌ failed` }, |
45 | | - { key: 'passes', label: `✅ passed` }, |
46 | | - { key: 'incomplete', label: `⚠️ incomplete` }, |
47 | | - { key: 'inapplicable', label: `⏭️ inapplicable` }, |
48 | | - ] |
49 | | - |
50 | | - categories.forEach(({ key, label }) => { |
51 | | - const items = results[key] || [] |
| 56 | + return axe.run(options).then((results) => { |
52 | 57 | cy.task( |
53 | 58 | 'log', |
54 | | - `\n=== ${label} (${items.length}) ===` |
| 59 | + `\n=== WCAG 2.2 accessibility evaluation of ${ |
| 60 | + page === '/' ? 'Homepage' : page |
| 61 | + } ===` |
55 | 62 | ) |
56 | 63 |
|
57 | | - items.forEach((rule) => { |
58 | | - const wcagRefs = |
59 | | - (rule.tags || []) |
60 | | - .filter((tag) => /^wcag/i.test(tag)) |
61 | | - .map((tag) => formatWCAGTag(tag)) |
62 | | - .join(', ') || 'no WCAG reference' |
| 64 | + const categories = [ |
| 65 | + { key: 'violations', label: `❌ failed` }, |
| 66 | + { key: 'passes', label: `✅ passed` }, |
| 67 | + { key: 'incomplete', label: `⚠️ incomplete` }, |
| 68 | + { |
| 69 | + key: 'inapplicable', |
| 70 | + label: `⏭️ inapplicable`, |
| 71 | + }, |
| 72 | + ] |
63 | 73 |
|
64 | | - cy.task('log', `→ Rule: ${rule.id}`) |
65 | | - cy.task('log', ` Description: ${rule.help}`) |
| 74 | + categories.forEach(({ key, label }) => { |
| 75 | + const items = results[key] || [] |
66 | 76 | cy.task( |
67 | 77 | 'log', |
68 | | - ` Impact: ${rule.impact || 'n/a'}` |
| 78 | + `\n===== ${label} (${items.length}) =====` |
69 | 79 | ) |
70 | | - cy.task('log', ` WCAG: ${wcagRefs}`) |
71 | | - cy.task('log', ` Help: ${rule.helpUrl}`) |
| 80 | + |
| 81 | + items.forEach((rule) => { |
| 82 | + const wcagRefs = |
| 83 | + (rule.tags || []) |
| 84 | + .filter((tag) => /^wcag/i.test(tag)) |
| 85 | + .map((tag) => formatWCAGTag(tag)) |
| 86 | + .join(', ') || 'no WCAG reference' |
| 87 | + |
| 88 | + cy.task('log', `→ Rule: ${rule.id}`) |
| 89 | + cy.task( |
| 90 | + 'log', |
| 91 | + ` Description: ${rule.help}` |
| 92 | + ) |
| 93 | + cy.task( |
| 94 | + 'log', |
| 95 | + ` Impact: ${rule.impact || 'n/a'}` |
| 96 | + ) |
| 97 | + cy.task('log', ` WCAG: ${wcagRefs}`) |
| 98 | + cy.task('log', ` Help: ${rule.helpUrl}`) |
| 99 | + }) |
72 | 100 | }) |
73 | | - }) |
74 | 101 |
|
75 | | - cy.writeFile(reportPath, results) |
| 102 | + cy.writeFile(reportPath, results) |
| 103 | + }) |
76 | 104 | }) |
77 | | - }) |
| 105 | + }) |
78 | 106 | }) |
79 | 107 | }) |
80 | 108 | }) |
0 commit comments