-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add a11y tests and GitHub action #460
Open
ethanWallace
wants to merge
15
commits into
main
Choose a base branch
from
feat/a11y-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
04f3118
Add cypress test to test a11y on all pages
ethanWallace 98d2997
Update a11y-tests.yml to use cypress test
ethanWallace b650bb8
Various a11y fixes identified by testing
ethanWallace d7fc509
Update github action
ethanWallace f268d28
Try to solve permission error
ethanWallace 932243b
Try to solve permission issue
ethanWallace 799664e
Update a11y-tests.yml
ethanWallace d1998cf
Optimize test + dead links scan
ethanWallace 4c963c2
Fix dead links
ethanWallace 3015987
feat: Convert component previews to iframes (#466)
ethanWallace 9f8de1a
Split EN/FR site a11y tests into seperate test files
ethanWallace 0a359da
Add timeout to visit
ethanWallace f183664
increase timeout time
ethanWallace 3a11d85
Remove uppercase letter from url
ethanWallace 73765db
Fix scripts to allow preview build
ethanWallace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
name: A11y test | ||
name: A11y test documentation site | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
paths-ignore: | ||
- 'reports/**' | ||
branches: | ||
- gh-pages | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-deploy: | ||
name: A11y test | ||
a11y-test: | ||
name: A11y test documentation site | ||
runs-on: ubuntu-latest | ||
container: | ||
image: cypress/included:11.2.0 | ||
steps: | ||
- name: Git Checkout | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
- name: Install pa11y | ||
run: npm install -g pa11y-ci pa11y-ci-reporter-html | ||
- name: run pa11y test | ||
run: pa11y-ci --sitemap https://cds-snc.github.io/${{ github.event.repository.name }}/sitemap.xml | ||
- name: Commit | ||
if: always() | ||
run: | | ||
git config --local user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --local user.name "github-actions[bot]" | ||
git add -A | ||
git commit -m "A11y report" | ||
- name: Push changes | ||
if: always() | ||
uses: ad-m/github-push-action@77c5b412c50b723d2a4fbc6d71fb5723bcd439aa | ||
|
||
- uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3.8.2 | ||
with: | ||
node-version: '18.x' | ||
|
||
- name: Cypress run | ||
uses: cypress-io/github-action@v6 | ||
with: | ||
github_token: ${{ secrets.ACCESS_TOKEN }} | ||
branch: 'gh-pages' | ||
build: npm run build:eleventy | ||
start: npm run watch:eleventy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { defineConfig } = require("cypress"); | ||
|
||
module.exports = defineConfig({ | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
on('task', { | ||
log(message) { | ||
console.log(message) | ||
|
||
return null | ||
}, | ||
table(message) { | ||
console.table(message) | ||
|
||
return null | ||
} | ||
}) | ||
}, | ||
baseUrl: 'http://localhost:8080', | ||
viewportWidth: 1280, | ||
viewportHeight: 850, | ||
screenshotOnRunFailure: false, | ||
video: false, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/// <reference types="cypress" /> | ||
|
||
const enLinks = require('../../src/en/en.json'); | ||
|
||
const pagesEn = []; | ||
|
||
// Create index of English pages | ||
Object.keys(enLinks.links).forEach(key => { | ||
const url = enLinks.links[key]; | ||
if ( | ||
!url.includes('coming-soon') && | ||
!url.includes('https') && | ||
!url.includes('mailto') && | ||
!url.includes('demo') | ||
) { | ||
let regex = /components\/[a-z]/; | ||
const pageName = key.replace(/([A-Z])/g, ' $1'); | ||
if (regex.test(url)) { | ||
pagesEn.push({ | ||
name: `${pageName} - use case`, | ||
url, | ||
}); | ||
pagesEn.push({ | ||
name: `${pageName} - design`, | ||
url: `${url}/design/`, | ||
}); | ||
pagesEn.push({ | ||
name: `${pageName} - code`, | ||
url: `${url}/code/`, | ||
}); | ||
} else { | ||
pagesEn.push({ | ||
name: pageName, | ||
url, | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
describe(`A11Y test English documentation site`, () => { | ||
for (const page of pagesEn) { | ||
it(`${page.name}: ${page.url}`, () => { | ||
cy.visit(page.url, { timeout: 30000 }); | ||
cy.get('.hydrated').then(() => { | ||
cy.injectAxe(); | ||
cy.checkA11y(null, null, terminalLog); | ||
// skip theme and topic menu since links are pulled from external source | ||
if (!page.url.includes('theme-and-topic-menu')) { | ||
cy.scanDeadLinks(); | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
// Output a11y errors in table in console | ||
function terminalLog(violations) { | ||
cy.task( | ||
'log', | ||
`${violations.length} accessibility violation${ | ||
violations.length === 1 ? '' : 's' | ||
} ${violations.length === 1 ? 'was' : 'were'} detected`, | ||
); | ||
// pluck specific keys to keep the table readable | ||
const violationData = violations.map( | ||
({ id, impact, description, nodes }) => ({ | ||
id, | ||
impact, | ||
description, | ||
nodes: nodes.length, | ||
}), | ||
); | ||
|
||
cy.task('table', violationData); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/// <reference types="cypress" /> | ||
|
||
const frLinks = require('../../src/fr/fr.json'); | ||
|
||
const pagesFr = []; | ||
|
||
// Create index of French pages | ||
Object.keys(frLinks.links).forEach(key => { | ||
const url = frLinks.links[key]; | ||
if ( | ||
!url.includes('developpement-en-cours') && | ||
!url.includes('https') && | ||
!url.includes('mailto') && | ||
!url.includes('demo') | ||
) { | ||
let regex = /composants\/[a-z]/; | ||
const pageName = key.replace(/([A-Z])/g, ' $1'); | ||
if (regex.test(url)) { | ||
pagesFr.push({ | ||
name: `${pageName} - use case`, | ||
url, | ||
}); | ||
pagesFr.push({ | ||
name: `${pageName} - design`, | ||
url: `${url}/design/`, | ||
}); | ||
pagesFr.push({ | ||
name: `${pageName} - code`, | ||
url: `${url}/code/`, | ||
}); | ||
} else { | ||
pagesFr.push({ | ||
name: `${pageName}`, | ||
url, | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
describe(`A11Y test French documentation site`, () => { | ||
after | ||
for (const page of pagesFr) { | ||
it(`${page.name}: ${page.url}`, () => { | ||
cy.visit(page.url, { timeout: 30000 }); | ||
cy.get('.hydrated').then(() => { | ||
cy.injectAxe(); | ||
cy.checkA11y(null, null, terminalLog); | ||
// skip theme and topic menu since links are pulled from external source | ||
if (!page.url.includes('menu-thematique')) { | ||
cy.scanDeadLinks(); | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
// Output a11y errors in table in console | ||
function terminalLog(violations) { | ||
cy.task( | ||
'log', | ||
`${violations.length} accessibility violation${ | ||
violations.length === 1 ? '' : 's' | ||
} ${violations.length === 1 ? 'was' : 'were'} detected`, | ||
); | ||
// pluck specific keys to keep the table readable | ||
const violationData = violations.map( | ||
({ id, impact, description, nodes }) => ({ | ||
id, | ||
impact, | ||
description, | ||
nodes: nodes.length, | ||
}), | ||
); | ||
|
||
cy.task('table', violationData); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "Using fixtures to represent data", | ||
"email": "hello@cypress.io", | ||
"body": "Fixtures are a great way to mock data for responses to routes" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// *********************************************** | ||
// This example commands.js shows you how to | ||
// create various custom commands and overwrite | ||
// existing commands. | ||
// | ||
// For more comprehensive examples of custom | ||
// commands please read more here: | ||
// https://on.cypress.io/custom-commands | ||
// *********************************************** | ||
|
||
// keep track of what we test so we dont test the same thing twice | ||
let links_checked = []; | ||
|
||
Cypress.Commands.add('scanDeadLinks', () => { | ||
cy.get('body').within(() => { | ||
let checked = 0; | ||
|
||
cy.get('a', { includeShadowDom: true }) | ||
.each(link => { | ||
if ( | ||
link.prop('href').startsWith('mailto') || | ||
link.prop('href').includes('.pdf') | ||
) | ||
return; | ||
|
||
const check_url = link.prop('href'); | ||
|
||
// skip if its already been checked | ||
if (links_checked.includes(check_url)) return; | ||
|
||
cy.request(link.prop('href')).as('link'); | ||
|
||
links_checked.push(check_url); | ||
checked++; | ||
}) | ||
.as('links'); | ||
|
||
cy.get('@links').then(links => { | ||
cy.log('links checked', checked); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// *********************************************************** | ||
// This example support/e2e.js is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import './commands' | ||
import 'cypress-axe' | ||
import 'cypress-html-validate/commands' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the
impact
level here as well, please?