-
Notifications
You must be signed in to change notification settings - Fork 47
A11y: make the axe peer deps optional #2485
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
Changes from all commits
d79dc51
7a2dbe7
64cca66
0f26478
59e39f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,11 +1,13 @@ | ||||||
| import AxeBuilder from '@axe-core/playwright'; | ||||||
| import { TestFixture } from '@playwright/test'; | ||||||
| import { AxeResults } from 'axe-core'; | ||||||
| import type { AxeResults } from 'axe-core'; | ||||||
| import type { AxeBuilder as AxeBuilderType } from '@axe-core/playwright'; | ||||||
|
|
||||||
| import { PlaywrightArgs, AxeScanContext } from '../types'; | ||||||
|
|
||||||
| export const DEFAULT_A11Y_TAGS = ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa' /* 'best-practice' */]; | ||||||
|
|
||||||
| let AxeBuilder: typeof AxeBuilderType; | ||||||
|
|
||||||
| /** | ||||||
| * @alpha - the API for accessibility scanning is still being finalized and may change in future releases. Feedback is welcome! | ||||||
| */ | ||||||
|
|
@@ -15,6 +17,14 @@ export const scanForA11yViolations: TestFixture< | |||||
| > = async ({ page }, use, testInfo) => { | ||||||
| let inc = 1; | ||||||
| await use(async (context?: AxeScanContext) => { | ||||||
| if (!AxeBuilder) { | ||||||
| try { | ||||||
| const { AxeBuilder: _AxeBuilder } = await import('@axe-core/playwright'); | ||||||
| AxeBuilder = _AxeBuilder; | ||||||
|
Comment on lines
+21
to
+23
|
||||||
| } catch (error) { | ||||||
| throw new Error('@axe-core/playwright must be installed as a peer dependency to use a11y scanning.'); | ||||||
|
||||||
| throw new Error('@axe-core/playwright must be installed as a peer dependency to use a11y scanning.'); | |
| throw new Error('@axe-core/playwright and axe-core must be installed (as peer dependencies) to use a11y scanning.'); |
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.
that optional dependency only impacts TypeScript types, which seem to not be an issue unless we forget to import type, so we don't care I think.
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.
I don't think it's an issue but
plugin-e2eships types which rely onaxe-core. I think they'll be consideredanyif the package is missing but want to surface it in the PR all the same.Uh oh!
There was an error while loading. Please reload this page.
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.
yeah :/ ultimately I think this is still probably the cleanest way to make this work, since the user probably doesn't actually interact with the report but just passes it from the fixture to the custom matcher.