-
-
Notifications
You must be signed in to change notification settings - Fork 839
Fix a11y CI workflow #2503
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
Merged
Merged
Fix a11y CI workflow #2503
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
21b68ad
ci: refactor a11y tests
HiDeoo 757b1ed
ci: remove `pa11y-ci`
HiDeoo e0f2870
ci: increase a11y build step timeout
HiDeoo dc43808
test: exclude a11y tests from coverage
HiDeoo 398aa45
test: tweak a11y test output
HiDeoo c853ccb
test: reduce the number of pages testeed for a11y issues
HiDeoo 480fd3d
feat: remove aside landmarks
HiDeoo 0076726
feat: remove tab landmarks
HiDeoo c8e2df4
ci: add feedback during a11y tests
HiDeoo 033be42
chore: add changeset
HiDeoo 98562a3
test: move a11y tests to `docs/`
HiDeoo 0fb18f7
Merge branch 'main' into hd-feat-ci-a11y
HiDeoo 976005d
fix: restore `<aside>` element
HiDeoo 8d614df
test: add a11y ignore system and ignore `landmark-unique` for asides
HiDeoo 5f5eaeb
Merge branch 'main' into pr/2503
delucis 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 hidden or 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 @@ | ||
| --- | ||
| '@astrojs/starlight': minor | ||
| --- | ||
|
|
||
| Improves the accessibility of asides and tabs by removing some unnecessary HTML landmarks. |
This file contains hidden or 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 hidden or 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 hidden or 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,22 @@ | ||
| import { expect, test } from './test-utils'; | ||
|
|
||
| test('does not report accessibility violations on the docs site', async ({ docsSite }) => { | ||
| let violationsCount = 0; | ||
|
|
||
| const urls = await docsSite.getAllUrls(); | ||
|
|
||
| for (const url of urls) { | ||
| const violations = await docsSite.testPage(url); | ||
|
|
||
| if (violations.length > 0) { | ||
| violationsCount += violations.length; | ||
| } | ||
|
|
||
| await docsSite.reportPageViolations(violations); | ||
| } | ||
|
|
||
| expect( | ||
| violationsCount, | ||
| `Found ${violationsCount} accessibility violations. Check the errors above for more details.` | ||
| ).toBe(0); | ||
| }); |
This file contains hidden or 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,155 @@ | ||
| import { test as baseTest, type Page } from '@playwright/test'; | ||
| import { | ||
| DefaultTerminalReporter, | ||
| getViolations, | ||
| injectAxe, | ||
| reportViolations, | ||
| } from 'axe-playwright'; | ||
| import Sitemapper from 'sitemapper'; | ||
|
|
||
| export { expect, type Locator } from '@playwright/test'; | ||
|
|
||
| const config: Config = { | ||
| axe: { | ||
| // https://www.deque.com/axe/core-documentation/api-documentation/#axecore-tags | ||
| runOnly: { | ||
| type: 'tag', | ||
| values: ['wcag2a', 'wcag21a', 'wcag2aa', 'wcag21aa', 'wcag22aa', 'best-practice'], | ||
| }, | ||
| }, | ||
| // A list of violation to ignore. | ||
| ignore: [{ id: 'landmark-unique', nodeMatcher: landmarkUniqueNodeMatcher }], | ||
| sitemap: { | ||
| url: 'http://localhost:4321/sitemap-index.xml', | ||
| exclude: { | ||
| // A pattern to exclude URLs from the sitemap. | ||
| pattern: /\/(de|zh-cn|fr|es|pt-br|pt-pt|it|id|ko|ru|tr|hi|da|uk)\/.*/, | ||
| // A list of slugs to exclude from the sitemap after processing the pattern. | ||
| slugs: [ | ||
| 'components/using-components', | ||
| 'getting-started', | ||
| 'guides/customization', | ||
| 'guides/i18n', | ||
| 'guides/overriding-components', | ||
| 'guides/pages', | ||
| 'guides/project-structure', | ||
| 'guides/site-search', | ||
| 'manual-setup', | ||
| 'reference/frontmatter', | ||
| 'reference/overrides', | ||
| 'reference/plugins', | ||
| ], | ||
| }, | ||
| replace: { | ||
| query: 'https://starlight.astro.build', | ||
| value: 'http://localhost:4321', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| process.env.ASTRO_TELEMETRY_DISABLED = 'true'; | ||
| process.env.ASTRO_DISABLE_UPDATE_CHECK = 'true'; | ||
|
|
||
| export const test = baseTest.extend<{ | ||
| docsSite: DocsSite; | ||
| }>({ | ||
| docsSite: async ({ page }, use) => use(new DocsSite(page)), | ||
| }); | ||
|
|
||
| // A Playwright test fixture accessible from within all tests. | ||
| class DocsSite { | ||
| constructor(private readonly page: Page) {} | ||
|
|
||
| async getAllUrls() { | ||
| const sitemap = new Sitemapper({ url: config.sitemap.url }); | ||
| const { sites } = await sitemap.fetch(); | ||
|
|
||
| if (sites.length === 0) { | ||
| throw new Error('No URLs found in sitemap.'); | ||
| } | ||
|
|
||
| const urls: string[] = []; | ||
|
|
||
| for (const site of sites) { | ||
| const url = site.replace(config.sitemap.replace.query, config.sitemap.replace.value); | ||
| if (config.sitemap.exclude.pattern.test(url)) continue; | ||
| if (config.sitemap.exclude.slugs.some((slug) => url.endsWith(`/${slug}/`))) continue; | ||
| urls.push(url); | ||
| } | ||
|
|
||
| return urls; | ||
| } | ||
|
|
||
| async testPage(url: string) { | ||
| await this.page.goto(url); | ||
| await injectAxe(this.page); | ||
| await this.page.waitForLoadState('networkidle'); | ||
| const violations = await getViolations(this.page, undefined, config.axe); | ||
| return this.#filterViolations(violations); | ||
| } | ||
|
|
||
| async reportPageViolations(violations: Awaited<ReturnType<typeof this.testPage>>) { | ||
| const url = this.page.url().replace(config.sitemap.replace.value, ''); | ||
|
|
||
| if (violations.length > 0) { | ||
| console.error(`> Found ${violations.length} violations on ${url}\n`); | ||
| await reportViolations(violations, new DefaultTerminalReporter(true, true, false)); | ||
| console.error('\n'); | ||
| } else { | ||
| console.log(`> Found no violations on ${url}`); | ||
| } | ||
| } | ||
|
|
||
| #filterViolations(violations: Awaited<ReturnType<typeof getViolations>>) { | ||
| return violations.filter((violation) => { | ||
| return !config.ignore.some((ignore) => { | ||
| if (typeof ignore === 'string') return violation.id === ignore; | ||
| if (violation.id !== ignore.id) return false; | ||
| if (!ignore.nodeMatcher) return true; | ||
| return !violation.nodes.some(ignore.nodeMatcher); | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| function landmarkUniqueNodeMatcher(node: ViolationNode) { | ||
| /** | ||
| * Ignore the `landmark-unique` violation only if the node HTML is an aside. | ||
| * | ||
| * The best action to fix this violation would be to remove the landmark altogether as it's not | ||
| * necessary in this case and switch to the `note` role. Although, this is not possible at the | ||
| * moment due to an issue with NVDA not announcing it and also skipping the associated label for | ||
| * a role not supported. | ||
| * | ||
| * @see https://github.com/nvaccess/nvda/issues/10439 | ||
| * @see https://github.com/withastro/starlight/pull/2503 | ||
| */ | ||
| return !/^<aside[^>]* class="starlight-aside[^>]*>$/.test(node.html); | ||
| } | ||
|
|
||
| interface Config { | ||
| axe: Parameters<typeof getViolations>[2]; | ||
| ignore: Array< | ||
| | string | ||
| | { | ||
| id: string; | ||
| // A function called for each node to evaluate if it should be ignored or not. | ||
| // Return `true` if the node should be considered for the violation, `false` otherwise. | ||
| nodeMatcher?: (node: ViolationNode) => boolean; | ||
| } | ||
| >; | ||
| sitemap: { | ||
| url: string; | ||
| exclude: { | ||
| pattern: RegExp; | ||
| slugs: string[]; | ||
| }; | ||
| replace: { | ||
| query: string; | ||
| value: string; | ||
| }; | ||
| }; | ||
| } | ||
|
|
||
| type Violations = Awaited<ReturnType<typeof getViolations>>; | ||
| type ViolationNode = Violations[number]['nodes'][number]; |
This file contains hidden or 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 hidden or 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 hidden or 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,28 @@ | ||
| import { defineConfig, devices } from '@playwright/test'; | ||
|
|
||
| export default defineConfig({ | ||
| forbidOnly: !!process.env['CI'], | ||
| projects: [ | ||
| { | ||
| name: 'Chrome Stable', | ||
| use: { | ||
| ...devices['Desktop Chrome'], | ||
| headless: true, | ||
| }, | ||
| }, | ||
| ], | ||
| testMatch: '__a11y__/*.test.ts', | ||
| // The timeout for the accessibility tests only. | ||
| timeout: 180 * 1_000, | ||
| webServer: [ | ||
| { | ||
| command: 'pnpm run build && pnpm run preview', | ||
| reuseExistingServer: !process.env['CI'], | ||
| stdout: 'pipe', | ||
| // The timeout of the single build step ran before the accessibility tests. | ||
| timeout: 120 * 1_000, | ||
| url: 'http://localhost:4321', | ||
| }, | ||
| ], | ||
| workers: 1, | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
This is needed as
axe-playwrighthas a peer dependency ofplaywrightwhich we explicitly don't use in favor of@playwright/test. Both official packages are different in the sense thatplaywrightautomatically installs browser binaries while@playwright/testdoes not. Runningpnpm test:a11yin thepackages/starlight/directory will take care of installing the necessary dependencies in our case only when needed.