@storybook/addon-a11y 10.1.0-alpha.1 → 10.1.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_browser-chunks/chunk-3FKQRDK3.js +13 -0
- package/dist/_browser-chunks/chunk-4BE7D4DS.js +9 -0
- package/dist/_browser-chunks/chunk-CQ2APV2R.js +163 -0
- package/dist/_browser-chunks/matchers-DMFSMG2O.js +1263 -0
- package/dist/index.js +4 -6
- package/dist/manager.js +554 -1741
- package/dist/postinstall.js +1777 -3836
- package/dist/preview.js +3 -3
- package/package.json +4 -4
- package/dist/_browser-chunks/chunk-JFJ5UJ7Q.js +0 -11
- package/dist/_browser-chunks/chunk-JZJ5QO7P.js +0 -26
- package/dist/_browser-chunks/chunk-W2OC36OK.js +0 -217
- package/dist/_browser-chunks/matchers-ZRZBO4XZ.js +0 -1987
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var ADDON_ID = "storybook/a11y", PANEL_ID = `${ADDON_ID}/panel`, PARAM_KEY = "a11y", UI_STATE_ID = `${ADDON_ID}/ui`, RESULT = `${ADDON_ID}/result`, REQUEST = `${ADDON_ID}/request`, RUNNING = `${ADDON_ID}/running`, ERROR = `${ADDON_ID}/error`, MANUAL = `${ADDON_ID}/manual`, SELECT = `${ADDON_ID}/select`, DOCUMENTATION_LINK = "writing-tests/accessibility-testing", DOCUMENTATION_DISCREPANCY_LINK = `${DOCUMENTATION_LINK}#why-are-my-tests-failing-in-different-environments`;
|
|
3
|
+
var EVENTS = { RESULT, REQUEST, RUNNING, ERROR, MANUAL, SELECT }, STATUS_TYPE_ID_COMPONENT_TEST = "storybook/component-test", STATUS_TYPE_ID_A11Y = "storybook/a11y";
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
ADDON_ID,
|
|
7
|
+
PANEL_ID,
|
|
8
|
+
PARAM_KEY,
|
|
9
|
+
DOCUMENTATION_DISCREPANCY_LINK,
|
|
10
|
+
EVENTS,
|
|
11
|
+
STATUS_TYPE_ID_COMPONENT_TEST,
|
|
12
|
+
STATUS_TYPE_ID_A11Y
|
|
13
|
+
};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EVENTS,
|
|
3
|
+
PANEL_ID
|
|
4
|
+
} from "./chunk-3FKQRDK3.js";
|
|
5
|
+
import {
|
|
6
|
+
__export
|
|
7
|
+
} from "./chunk-4BE7D4DS.js";
|
|
8
|
+
|
|
9
|
+
// src/preview.tsx
|
|
10
|
+
var preview_exports = {};
|
|
11
|
+
__export(preview_exports, {
|
|
12
|
+
afterEach: () => afterEach,
|
|
13
|
+
initialGlobals: () => initialGlobals,
|
|
14
|
+
parameters: () => parameters
|
|
15
|
+
});
|
|
16
|
+
import { expect } from "storybook/test";
|
|
17
|
+
|
|
18
|
+
// src/a11yRunner.ts
|
|
19
|
+
import { ElementA11yParameterError } from "storybook/internal/preview-errors";
|
|
20
|
+
import { global as global2 } from "@storybook/global";
|
|
21
|
+
import { addons, waitForAnimations } from "storybook/preview-api";
|
|
22
|
+
|
|
23
|
+
// src/a11yRunnerUtils.ts
|
|
24
|
+
import { global } from "@storybook/global";
|
|
25
|
+
var { document } = global, withLinkPaths = (results, storyId) => {
|
|
26
|
+
let pathname = document.location.pathname.replace(/iframe\.html$/, ""), enhancedResults = { ...results };
|
|
27
|
+
return ["incomplete", "passes", "violations"].forEach((key) => {
|
|
28
|
+
Array.isArray(results[key]) && (enhancedResults[key] = results[key].map((result) => ({
|
|
29
|
+
...result,
|
|
30
|
+
nodes: result.nodes.map((node, index) => {
|
|
31
|
+
let id = `${key}.${result.id}.${index + 1}`, linkPath = `${pathname}?path=/story/${storyId}&addonPanel=${PANEL_ID}&a11ySelection=${id}`;
|
|
32
|
+
return { id, ...node, linkPath };
|
|
33
|
+
})
|
|
34
|
+
})));
|
|
35
|
+
}), enhancedResults;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/a11yRunner.ts
|
|
39
|
+
var { document: document2 } = global2, channel = addons.getChannel(), DEFAULT_PARAMETERS = { config: {}, options: {} }, DISABLED_RULES = [
|
|
40
|
+
// In component testing, landmarks are not always present
|
|
41
|
+
// and the rule check can cause false positives
|
|
42
|
+
"region"
|
|
43
|
+
], queue = [], isRunning = !1, runNext = async () => {
|
|
44
|
+
if (queue.length === 0) {
|
|
45
|
+
isRunning = !1;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
isRunning = !0;
|
|
49
|
+
let next = queue.shift();
|
|
50
|
+
next && await next(), runNext();
|
|
51
|
+
}, run = async (input = DEFAULT_PARAMETERS, storyId) => {
|
|
52
|
+
let axe = (await import("axe-core"))?.default || globalThis.axe, { config = {}, options = {} } = input;
|
|
53
|
+
if (input.element)
|
|
54
|
+
throw new ElementA11yParameterError();
|
|
55
|
+
let context = {
|
|
56
|
+
include: document2?.body,
|
|
57
|
+
exclude: [".sb-wrapper", "#storybook-docs", "#storybook-highlights-root"]
|
|
58
|
+
// Internal Storybook elements that are always in the document
|
|
59
|
+
};
|
|
60
|
+
if (input.context) {
|
|
61
|
+
let hasInclude = typeof input.context == "object" && "include" in input.context && input.context.include !== void 0, hasExclude = typeof input.context == "object" && "exclude" in input.context && input.context.exclude !== void 0;
|
|
62
|
+
hasInclude ? context.include = input.context.include : !hasInclude && !hasExclude && (context.include = input.context), hasExclude && (context.exclude = context.exclude.concat(input.context.exclude));
|
|
63
|
+
}
|
|
64
|
+
axe.reset();
|
|
65
|
+
let configWithDefault = {
|
|
66
|
+
...config,
|
|
67
|
+
rules: [...DISABLED_RULES.map((id) => ({ id, enabled: !1 })), ...config?.rules ?? []]
|
|
68
|
+
};
|
|
69
|
+
return axe.configure(configWithDefault), new Promise((resolve, reject) => {
|
|
70
|
+
let highlightsRoot = document2?.getElementById("storybook-highlights-root");
|
|
71
|
+
highlightsRoot && (highlightsRoot.style.display = "none");
|
|
72
|
+
let task = async () => {
|
|
73
|
+
try {
|
|
74
|
+
let result = await axe.run(context, options), resultWithLinks = withLinkPaths(result, storyId);
|
|
75
|
+
resolve(resultWithLinks);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
reject(error);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
queue.push(task), isRunning || runNext(), highlightsRoot && (highlightsRoot.style.display = "");
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
channel.on(EVENTS.MANUAL, async (storyId, input = DEFAULT_PARAMETERS) => {
|
|
84
|
+
try {
|
|
85
|
+
await waitForAnimations();
|
|
86
|
+
let result = await run(input, storyId), resultJson = JSON.parse(JSON.stringify(result));
|
|
87
|
+
channel.emit(EVENTS.RESULT, resultJson, storyId);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
channel.emit(EVENTS.ERROR, error);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// src/utils.ts
|
|
94
|
+
function getIsVitestStandaloneRun() {
|
|
95
|
+
try {
|
|
96
|
+
return import.meta.env.VITEST_STORYBOOK === "false";
|
|
97
|
+
} catch {
|
|
98
|
+
return !1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/preview.tsx
|
|
103
|
+
var vitestMatchersExtended = !1, afterEach = async ({
|
|
104
|
+
id: storyId,
|
|
105
|
+
reporting,
|
|
106
|
+
parameters: parameters2,
|
|
107
|
+
globals,
|
|
108
|
+
viewMode
|
|
109
|
+
}) => {
|
|
110
|
+
let a11yParameter = parameters2.a11y, a11yGlobals = globals.a11y, shouldRunEnvironmentIndependent = a11yParameter?.disable !== !0 && a11yParameter?.test !== "off" && a11yGlobals?.manual !== !0, getMode = () => {
|
|
111
|
+
switch (a11yParameter?.test) {
|
|
112
|
+
case "todo":
|
|
113
|
+
return "warning";
|
|
114
|
+
case "error":
|
|
115
|
+
default:
|
|
116
|
+
return "failed";
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
if (shouldRunEnvironmentIndependent && viewMode === "story")
|
|
120
|
+
try {
|
|
121
|
+
let result = await run(a11yParameter, storyId);
|
|
122
|
+
if (result) {
|
|
123
|
+
let hasViolations = (result?.violations.length ?? 0) > 0;
|
|
124
|
+
if (reporting.addReport({
|
|
125
|
+
type: "a11y",
|
|
126
|
+
version: 1,
|
|
127
|
+
result,
|
|
128
|
+
status: hasViolations ? getMode() : "passed"
|
|
129
|
+
}), getIsVitestStandaloneRun() && hasViolations && getMode() === "failed") {
|
|
130
|
+
if (!vitestMatchersExtended) {
|
|
131
|
+
let { toHaveNoViolations } = await import("./matchers-DMFSMG2O.js");
|
|
132
|
+
expect.extend({ toHaveNoViolations }), vitestMatchersExtended = !0;
|
|
133
|
+
}
|
|
134
|
+
expect(result).toHaveNoViolations();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
} catch (e) {
|
|
138
|
+
if (reporting.addReport({
|
|
139
|
+
type: "a11y",
|
|
140
|
+
version: 1,
|
|
141
|
+
result: {
|
|
142
|
+
error: e
|
|
143
|
+
},
|
|
144
|
+
status: "failed"
|
|
145
|
+
}), getIsVitestStandaloneRun())
|
|
146
|
+
throw e;
|
|
147
|
+
}
|
|
148
|
+
}, initialGlobals = {
|
|
149
|
+
a11y: {
|
|
150
|
+
manual: !1
|
|
151
|
+
}
|
|
152
|
+
}, parameters = {
|
|
153
|
+
a11y: {
|
|
154
|
+
test: "todo"
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export {
|
|
159
|
+
afterEach,
|
|
160
|
+
initialGlobals,
|
|
161
|
+
parameters,
|
|
162
|
+
preview_exports
|
|
163
|
+
};
|