Skip to content

Commit 2ac14a6

Browse files
committed
Add handling for known axe-core conflicts
1 parent 117dc04 commit 2ac14a6

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- [fix] Add handling for known axe-core conflicts [#103](https://github.com/chanzuckerberg/axe-storybook-testing/pull/103)
6+
57
## 8.2.1 (2024-10-21)
68

79
- [fix] Simplify the promise queue implementation [#102](https://github.com/chanzuckerberg/axe-storybook-testing/pull/102)

src/browser/AxePage.ts

+7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ export function analyze(
5959
});
6060
}
6161

62+
/**
63+
* (In Browser Context)
64+
*
65+
*/
6266
function runAxe({
6367
config,
6468
context,
@@ -83,6 +87,7 @@ function runAxe({
8387
window.axe.configure(config);
8488
}
8589

90+
// API: https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#api-name-axerun
8691
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
8792
// @ts-ignore This function executes in a browser context.
8893
return window.axe.run(context || document, options);
@@ -106,6 +111,8 @@ export function getRunOptions(
106111
}
107112

108113
/**
114+
* (In Browser Context)
115+
*
109116
* Add a promise queue so we can ensure only one promise runs at a time.
110117
*
111118
* Used to prevent concurrent runs of `axe.run`, which breaks (see https://github.com/dequelabs/axe-core/issues/1041).

src/browser/StorybookPage.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ async function fetchStoriesFromWindow(): Promise<StorybookStory[]> {
116116

117117
/**
118118
* Abuse Storybook's internal APIs to render a story without requiring a page reload (which would
119-
* be slow).
119+
* be slow). Also set up globals for any values needed for the running tests.
120120
*
121121
* Doing so is brittle, and updates to Storybook could break this. The trade off is that we don't
122122
* have to figure out how to process stories with Webpack - Storybook handles that for us.
@@ -134,10 +134,19 @@ function emitSetCurrentStory(id: string) {
134134
);
135135
}
136136

137-
return new Promise((resolve) => {
138-
// @ts-expect-error Access the protected "channel", so we can send stuff through it.
139-
const channel = storybookPreview.channel;
137+
// @ts-expect-error Access the protected "channel", so we can send stuff through it.
138+
const channel = storybookPreview.channel;
140139

140+
// update global to disable known addons containing `axe-core`
141+
channel.emit('updateGlobals', {
142+
globals: {
143+
a11y: {
144+
manual: true,
145+
},
146+
},
147+
});
148+
149+
return new Promise((resolve) => {
141150
channel.emit('setCurrentStory', {
142151
storyId: id,
143152
viewMode: 'story',

0 commit comments

Comments
 (0)