snap-ally 0.1.1-beta → 0.2.1-beta
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/A11yAuditOverlay.d.ts +46 -17
- package/dist/A11yAuditOverlay.js +209 -106
- package/dist/A11yHtmlRenderer.js +10 -4
- package/dist/A11yScanner.js +1 -1
- package/dist/SnapAllyReporter.d.ts +56 -10
- package/dist/SnapAllyReporter.js +305 -240
- package/dist/templates/report-app.js +50 -17
- package/package.json +1 -1
|
@@ -1,42 +1,71 @@
|
|
|
1
1
|
import { Page, TestInfo } from '@playwright/test';
|
|
2
|
-
export interface AuditAnnotation {
|
|
3
|
-
type: string;
|
|
4
|
-
description: string;
|
|
5
|
-
keyPage: string;
|
|
6
|
-
}
|
|
7
2
|
/**
|
|
8
3
|
* Handles visual feedback and Playwright annotations during an accessibility audit.
|
|
4
|
+
*
|
|
5
|
+
* Responsibilities:
|
|
6
|
+
* - Rendering violation banners and element highlights via a Shadow DOM overlay
|
|
7
|
+
* - Capturing screenshots and attaching them to the Playwright test report
|
|
8
|
+
*
|
|
9
|
+
* All DOM mutations are isolated inside a Shadow DOM root to avoid
|
|
10
|
+
* interfering with the page under test.
|
|
9
11
|
*/
|
|
10
12
|
export declare class A11yAuditOverlay {
|
|
11
|
-
|
|
12
|
-
protected keyPage: string;
|
|
13
|
+
private readonly page;
|
|
13
14
|
private readonly overlayRootId;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/** IDs for elements created inside the shadow root. */
|
|
16
|
+
private static readonly BANNER_ID;
|
|
17
|
+
private static readonly HIGHLIGHT_ID;
|
|
18
|
+
constructor(page: Page);
|
|
17
19
|
/**
|
|
18
20
|
* Shows a compact, modern banner at the bottom of the page describing the violation.
|
|
21
|
+
*
|
|
22
|
+
* @param violation - Object containing the Axe rule `id` and human-readable `help` text.
|
|
23
|
+
* @param color - CSS colour used as the banner background (rgb/rgba/hex).
|
|
19
24
|
*/
|
|
20
25
|
showViolationOverlay(violation: {
|
|
21
26
|
id: string;
|
|
22
27
|
help: string;
|
|
23
28
|
}, color: string): Promise<void>;
|
|
24
29
|
/**
|
|
25
|
-
* Removes the violation description
|
|
30
|
+
* Removes the violation description banner from the page.
|
|
26
31
|
*/
|
|
27
32
|
hideViolationOverlay(): Promise<void>;
|
|
28
33
|
/**
|
|
29
|
-
*
|
|
34
|
+
* Draws a glowing highlight border around the element matching `selector`.
|
|
35
|
+
*
|
|
36
|
+
* The element is scrolled into view first so that the highlight coordinates
|
|
37
|
+
* are accurate after any layout shift.
|
|
38
|
+
*
|
|
39
|
+
* @param selector - A CSS selector that uniquely identifies the target element.
|
|
40
|
+
* @param color - CSS colour for the highlight border and glow.
|
|
41
|
+
*/
|
|
42
|
+
highlightElement(selector: string, color: string): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Removes the element highlight from the page.
|
|
45
|
+
*/
|
|
46
|
+
unhighlightElement(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Attaches arbitrary data to the Playwright test report.
|
|
49
|
+
*
|
|
50
|
+
* @param testInfo - The current Playwright `TestInfo` instance.
|
|
51
|
+
* @param name - Attachment name shown in the report.
|
|
52
|
+
* @param description - Content to attach (serialised as JSON by the caller).
|
|
30
53
|
*/
|
|
31
54
|
addTestAttachment(testInfo: TestInfo, name: string, description: string): Promise<void>;
|
|
32
|
-
getAuditAnnotations(): AuditAnnotation[];
|
|
33
55
|
/**
|
|
34
|
-
* Captures a screenshot and attaches it to the test report.
|
|
56
|
+
* Captures a viewport screenshot and attaches it to the test report.
|
|
57
|
+
*
|
|
58
|
+
* The screenshot uses `fullPage: false` (viewport only) to avoid browser
|
|
59
|
+
* resizing flashes that can occur with full-page captures.
|
|
60
|
+
*
|
|
61
|
+
* @param fileName - Name for the attachment in the test report.
|
|
62
|
+
* @param testInfo - The current Playwright `TestInfo` instance.
|
|
63
|
+
* @returns The raw screenshot buffer.
|
|
35
64
|
*/
|
|
36
65
|
captureAndAttachScreenshot(fileName: string, testInfo: TestInfo): Promise<Buffer>;
|
|
37
|
-
highlightElement(selector: string, color: string): Promise<void>;
|
|
38
66
|
/**
|
|
39
|
-
*
|
|
67
|
+
* Wrapper around `page.evaluate` that silently swallows errors caused by
|
|
68
|
+
* the page or browser closing mid-evaluation (e.g. navigation, test teardown).
|
|
40
69
|
*/
|
|
41
|
-
|
|
70
|
+
private safeEvaluate;
|
|
42
71
|
}
|
package/dist/A11yAuditOverlay.js
CHANGED
|
@@ -4,37 +4,58 @@ exports.A11yAuditOverlay = void 0;
|
|
|
4
4
|
const test_1 = require("@playwright/test");
|
|
5
5
|
/**
|
|
6
6
|
* Handles visual feedback and Playwright annotations during an accessibility audit.
|
|
7
|
+
*
|
|
8
|
+
* Responsibilities:
|
|
9
|
+
* - Rendering violation banners and element highlights via a Shadow DOM overlay
|
|
10
|
+
* - Capturing screenshots and attaching them to the Playwright test report
|
|
11
|
+
*
|
|
12
|
+
* All DOM mutations are isolated inside a Shadow DOM root to avoid
|
|
13
|
+
* interfering with the page under test.
|
|
7
14
|
*/
|
|
8
15
|
class A11yAuditOverlay {
|
|
9
|
-
constructor(page
|
|
16
|
+
constructor(page) {
|
|
10
17
|
this.page = page;
|
|
11
|
-
this.keyPage = keyPage;
|
|
12
18
|
this.overlayRootId = 'a11y-audit-overlay-root';
|
|
13
|
-
this.auditAnnotations = [];
|
|
14
|
-
}
|
|
15
|
-
reset() {
|
|
16
|
-
this.auditAnnotations = [];
|
|
17
19
|
}
|
|
20
|
+
// ──────────────────────────────────────────────
|
|
21
|
+
// Violation banner
|
|
22
|
+
// ──────────────────────────────────────────────
|
|
18
23
|
/**
|
|
19
24
|
* Shows a compact, modern banner at the bottom of the page describing the violation.
|
|
25
|
+
*
|
|
26
|
+
* @param violation - Object containing the Axe rule `id` and human-readable `help` text.
|
|
27
|
+
* @param color - CSS colour used as the banner background (rgb/rgba/hex).
|
|
20
28
|
*/
|
|
21
29
|
async showViolationOverlay(violation, color) {
|
|
22
|
-
await this.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
'
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
const
|
|
33
|
-
|
|
30
|
+
await this.safeEvaluate(([v, rawColor, rootId, bannerId]) => {
|
|
31
|
+
// --- helpers scoped to the browser context ---
|
|
32
|
+
const toAlphaColor = (c, alpha = 0.85) => {
|
|
33
|
+
if (c.includes('rgba'))
|
|
34
|
+
return c;
|
|
35
|
+
if (c.includes('rgb'))
|
|
36
|
+
return c.replace('rgb', 'rgba').replace(')', `, ${alpha})`);
|
|
37
|
+
// Hex – append alpha byte (0xD9 ≈ 0.85)
|
|
38
|
+
return `${c}D9`;
|
|
39
|
+
};
|
|
40
|
+
const getOrCreateRoot = (id) => {
|
|
41
|
+
let root = document.getElementById(id);
|
|
42
|
+
if (!root) {
|
|
43
|
+
root = document.createElement('div');
|
|
44
|
+
root.id = id;
|
|
45
|
+
root.style.cssText =
|
|
46
|
+
'position:absolute;top:0;left:0;width:0;height:0;z-index:2147483647;';
|
|
47
|
+
document.body.appendChild(root);
|
|
48
|
+
root.attachShadow({ mode: 'open' });
|
|
49
|
+
}
|
|
50
|
+
return root.shadowRoot;
|
|
51
|
+
};
|
|
52
|
+
// --- main logic ---
|
|
53
|
+
const shadow = getOrCreateRoot(rootId);
|
|
54
|
+
let container = shadow.getElementById(bannerId);
|
|
34
55
|
if (!container) {
|
|
35
56
|
const style = document.createElement('style');
|
|
36
57
|
style.textContent = `
|
|
37
|
-
|
|
58
|
+
#${bannerId} {
|
|
38
59
|
position: fixed;
|
|
39
60
|
left: 50%;
|
|
40
61
|
bottom: 24px;
|
|
@@ -56,7 +77,7 @@ class A11yAuditOverlay {
|
|
|
56
77
|
z-index: 10000;
|
|
57
78
|
}
|
|
58
79
|
.badge {
|
|
59
|
-
background: rgba(255,
|
|
80
|
+
background: rgba(255,255,255,0.2);
|
|
60
81
|
padding: 2px 8px;
|
|
61
82
|
border-radius: 6px;
|
|
62
83
|
font-size: 11px;
|
|
@@ -74,126 +95,208 @@ class A11yAuditOverlay {
|
|
|
74
95
|
`;
|
|
75
96
|
shadow.appendChild(style);
|
|
76
97
|
container = document.createElement('div');
|
|
77
|
-
container.id =
|
|
98
|
+
container.id = bannerId;
|
|
78
99
|
shadow.appendChild(container);
|
|
79
100
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
container.style.backgroundColor = toAlphaColor(rawColor);
|
|
102
|
+
// Build DOM nodes instead of innerHTML to prevent XSS
|
|
103
|
+
container.textContent = ''; // clear previous content
|
|
104
|
+
const icon = document.createElement('div');
|
|
105
|
+
icon.style.fontSize = '20px';
|
|
106
|
+
icon.textContent = '⚠️';
|
|
107
|
+
const badge = document.createElement('span');
|
|
108
|
+
badge.className = 'badge';
|
|
109
|
+
badge.textContent = v.id;
|
|
110
|
+
const helpText = document.createElement('span');
|
|
111
|
+
helpText.style.opacity = '0.9';
|
|
112
|
+
helpText.textContent = v.help;
|
|
113
|
+
const row = document.createElement('div');
|
|
114
|
+
row.style.cssText = 'margin-bottom:4px;display:flex;align-items:center;gap:8px;';
|
|
115
|
+
row.appendChild(badge);
|
|
116
|
+
row.appendChild(helpText);
|
|
117
|
+
const content = document.createElement('div');
|
|
118
|
+
content.className = 'content';
|
|
119
|
+
content.appendChild(row);
|
|
120
|
+
container.appendChild(icon);
|
|
121
|
+
container.appendChild(content);
|
|
122
|
+
}, [
|
|
123
|
+
violation,
|
|
124
|
+
color,
|
|
125
|
+
this.overlayRootId,
|
|
126
|
+
A11yAuditOverlay.BANNER_ID,
|
|
127
|
+
]);
|
|
96
128
|
}
|
|
97
129
|
/**
|
|
98
|
-
* Removes the violation description
|
|
130
|
+
* Removes the violation description banner from the page.
|
|
99
131
|
*/
|
|
100
132
|
async hideViolationOverlay() {
|
|
101
|
-
await this.
|
|
133
|
+
await this.safeEvaluate((rootId) => {
|
|
102
134
|
const el = document.getElementById(rootId);
|
|
103
135
|
if (el)
|
|
104
136
|
el.remove();
|
|
105
137
|
}, this.overlayRootId);
|
|
106
138
|
}
|
|
139
|
+
// ──────────────────────────────────────────────
|
|
140
|
+
// Element highlighting
|
|
141
|
+
// ──────────────────────────────────────────────
|
|
107
142
|
/**
|
|
108
|
-
*
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
getAuditAnnotations() {
|
|
117
|
-
return this.auditAnnotations;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Captures a screenshot and attaches it to the test report.
|
|
143
|
+
* Draws a glowing highlight border around the element matching `selector`.
|
|
144
|
+
*
|
|
145
|
+
* The element is scrolled into view first so that the highlight coordinates
|
|
146
|
+
* are accurate after any layout shift.
|
|
147
|
+
*
|
|
148
|
+
* @param selector - A CSS selector that uniquely identifies the target element.
|
|
149
|
+
* @param color - CSS colour for the highlight border and glow.
|
|
121
150
|
*/
|
|
122
|
-
async captureAndAttachScreenshot(fileName, testInfo) {
|
|
123
|
-
return await test_1.test.step('Capture A11y screenshot', async () => {
|
|
124
|
-
// Use viewport screenshot instead of fullPage to avoid browser resizing flashes
|
|
125
|
-
const screenshot = await this.page.screenshot({ fullPage: false });
|
|
126
|
-
await testInfo.attach(fileName, { contentType: 'image/png', body: screenshot });
|
|
127
|
-
return screenshot;
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
151
|
async highlightElement(selector, color) {
|
|
131
|
-
await this.
|
|
152
|
+
await this.safeEvaluate(([sel, rawColor, rootId, highlightId]) => {
|
|
132
153
|
const target = document.querySelector(sel);
|
|
133
154
|
if (!target)
|
|
134
155
|
return;
|
|
135
|
-
// Scroll FIRST to ensure accurate coordinates after scroll
|
|
136
156
|
target.scrollIntoView({ behavior: 'auto', block: 'center' });
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
157
|
+
const toAlphaColor = (c, alpha) => {
|
|
158
|
+
if (c.includes('rgba'))
|
|
159
|
+
return c.replace(/[\d.]+\)$/, `${alpha})`);
|
|
160
|
+
if (c.includes('rgb'))
|
|
161
|
+
return c.replace('rgb', 'rgba').replace(')', `, ${alpha})`);
|
|
162
|
+
// Hex – convert alpha to 2-char hex
|
|
163
|
+
const hex = Math.round(alpha * 255)
|
|
164
|
+
.toString(16)
|
|
165
|
+
.padStart(2, '0');
|
|
166
|
+
return `${c}${hex}`;
|
|
167
|
+
};
|
|
168
|
+
const getOrCreateRoot = (id) => {
|
|
169
|
+
let root = document.getElementById(id);
|
|
170
|
+
if (!root) {
|
|
171
|
+
root = document.createElement('div');
|
|
172
|
+
root.id = id;
|
|
173
|
+
root.style.cssText =
|
|
174
|
+
'position:absolute;top:0;left:0;width:0;height:0;z-index:2147483647;';
|
|
175
|
+
document.body.appendChild(root);
|
|
176
|
+
root.attachShadow({ mode: 'open' });
|
|
177
|
+
}
|
|
178
|
+
return root.shadowRoot;
|
|
179
|
+
};
|
|
180
|
+
const shadow = getOrCreateRoot(rootId);
|
|
181
|
+
let highlight = shadow.getElementById(highlightId);
|
|
148
182
|
if (!highlight) {
|
|
149
183
|
const style = document.createElement('style');
|
|
150
184
|
style.textContent = `
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
border: 2px solid var(--c);
|
|
167
|
-
}
|
|
168
|
-
`;
|
|
185
|
+
#${highlightId} {
|
|
186
|
+
position: absolute;
|
|
187
|
+
pointer-events: none;
|
|
188
|
+
border-radius: 8px;
|
|
189
|
+
box-sizing: border-box;
|
|
190
|
+
z-index: 9999;
|
|
191
|
+
box-shadow: 0 0 0 4px var(--c-alpha), 0 0 20px var(--c-alpha);
|
|
192
|
+
}
|
|
193
|
+
.glow {
|
|
194
|
+
position: absolute;
|
|
195
|
+
inset: 0;
|
|
196
|
+
border-radius: inherit;
|
|
197
|
+
border: 2px solid var(--c);
|
|
198
|
+
}
|
|
199
|
+
`;
|
|
169
200
|
shadow.appendChild(style);
|
|
170
201
|
highlight = document.createElement('div');
|
|
171
|
-
highlight.id =
|
|
172
|
-
|
|
202
|
+
highlight.id = highlightId;
|
|
203
|
+
const glow = document.createElement('div');
|
|
204
|
+
glow.className = 'glow';
|
|
205
|
+
highlight.appendChild(glow);
|
|
173
206
|
shadow.appendChild(highlight);
|
|
174
207
|
}
|
|
208
|
+
const pad = 4;
|
|
175
209
|
const rect = target.getBoundingClientRect();
|
|
176
|
-
highlight.style.left = `${rect.left + window.scrollX -
|
|
177
|
-
highlight.style.top = `${rect.top + window.scrollY -
|
|
178
|
-
highlight.style.width = `${rect.width +
|
|
179
|
-
highlight.style.height = `${rect.height +
|
|
180
|
-
highlight.style.border = `3px solid ${
|
|
181
|
-
highlight.style.setProperty('--c',
|
|
182
|
-
highlight.style.setProperty('--c-alpha',
|
|
183
|
-
}, [
|
|
210
|
+
highlight.style.left = `${rect.left + window.scrollX - pad}px`;
|
|
211
|
+
highlight.style.top = `${rect.top + window.scrollY - pad}px`;
|
|
212
|
+
highlight.style.width = `${rect.width + pad * 2}px`;
|
|
213
|
+
highlight.style.height = `${rect.height + pad * 2}px`;
|
|
214
|
+
highlight.style.border = `3px solid ${rawColor}`;
|
|
215
|
+
highlight.style.setProperty('--c', rawColor);
|
|
216
|
+
highlight.style.setProperty('--c-alpha', toAlphaColor(rawColor, 0.3));
|
|
217
|
+
}, [
|
|
218
|
+
selector,
|
|
219
|
+
color,
|
|
220
|
+
this.overlayRootId,
|
|
221
|
+
A11yAuditOverlay.HIGHLIGHT_ID,
|
|
222
|
+
]);
|
|
184
223
|
}
|
|
185
224
|
/**
|
|
186
|
-
* Removes
|
|
225
|
+
* Removes the element highlight from the page.
|
|
187
226
|
*/
|
|
188
227
|
async unhighlightElement() {
|
|
189
|
-
await this.
|
|
228
|
+
await this.safeEvaluate(([rootId, highlightId]) => {
|
|
190
229
|
const root = document.getElementById(rootId);
|
|
191
|
-
if (root
|
|
192
|
-
const highlight = root.shadowRoot.getElementById(
|
|
230
|
+
if (root === null || root === void 0 ? void 0 : root.shadowRoot) {
|
|
231
|
+
const highlight = root.shadowRoot.getElementById(highlightId);
|
|
193
232
|
if (highlight)
|
|
194
233
|
highlight.remove();
|
|
195
234
|
}
|
|
196
|
-
}, this.overlayRootId);
|
|
235
|
+
}, [this.overlayRootId, A11yAuditOverlay.HIGHLIGHT_ID]);
|
|
236
|
+
}
|
|
237
|
+
// ──────────────────────────────────────────────
|
|
238
|
+
// Test report helpers
|
|
239
|
+
// ──────────────────────────────────────────────
|
|
240
|
+
/**
|
|
241
|
+
* Attaches arbitrary data to the Playwright test report.
|
|
242
|
+
*
|
|
243
|
+
* @param testInfo - The current Playwright `TestInfo` instance.
|
|
244
|
+
* @param name - Attachment name shown in the report.
|
|
245
|
+
* @param description - Content to attach (serialised as JSON by the caller).
|
|
246
|
+
*/
|
|
247
|
+
async addTestAttachment(testInfo, name, description) {
|
|
248
|
+
await testInfo.attach(name, {
|
|
249
|
+
contentType: 'application/json',
|
|
250
|
+
body: Buffer.from(description),
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Captures a viewport screenshot and attaches it to the test report.
|
|
255
|
+
*
|
|
256
|
+
* The screenshot uses `fullPage: false` (viewport only) to avoid browser
|
|
257
|
+
* resizing flashes that can occur with full-page captures.
|
|
258
|
+
*
|
|
259
|
+
* @param fileName - Name for the attachment in the test report.
|
|
260
|
+
* @param testInfo - The current Playwright `TestInfo` instance.
|
|
261
|
+
* @returns The raw screenshot buffer.
|
|
262
|
+
*/
|
|
263
|
+
async captureAndAttachScreenshot(fileName, testInfo) {
|
|
264
|
+
return await test_1.test.step('Capture A11y screenshot', async () => {
|
|
265
|
+
const screenshot = await this.page.screenshot({ fullPage: false });
|
|
266
|
+
await testInfo.attach(fileName, { contentType: 'image/png', body: screenshot });
|
|
267
|
+
return screenshot;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
// ──────────────────────────────────────────────
|
|
271
|
+
// Private helpers
|
|
272
|
+
// ──────────────────────────────────────────────
|
|
273
|
+
/**
|
|
274
|
+
* Wrapper around `page.evaluate` that silently swallows errors caused by
|
|
275
|
+
* the page or browser closing mid-evaluation (e.g. navigation, test teardown).
|
|
276
|
+
*/
|
|
277
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
278
|
+
async safeEvaluate(fn, arg) {
|
|
279
|
+
try {
|
|
280
|
+
if (arg !== undefined) {
|
|
281
|
+
await this.page.evaluate(fn, arg);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
await this.page.evaluate(fn);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
if (error instanceof Error &&
|
|
289
|
+
(error.message.includes('Target page, context or browser has been closed') ||
|
|
290
|
+
error.message.includes('Execution context was destroyed') ||
|
|
291
|
+
error.message.includes('Test ended'))) {
|
|
292
|
+
// Page navigated away or test ended — overlay is no longer relevant.
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
197
297
|
}
|
|
198
298
|
}
|
|
199
299
|
exports.A11yAuditOverlay = A11yAuditOverlay;
|
|
300
|
+
/** IDs for elements created inside the shadow root. */
|
|
301
|
+
A11yAuditOverlay.BANNER_ID = 'a11y-banner';
|
|
302
|
+
A11yAuditOverlay.HIGHLIGHT_ID = 'a11y-highlight';
|
package/dist/A11yHtmlRenderer.js
CHANGED
|
@@ -59,11 +59,17 @@ class A11yHtmlRenderer {
|
|
|
59
59
|
if (!fs.existsSync(outputFolder)) {
|
|
60
60
|
fs.mkdirSync(outputFolder, { recursive: true });
|
|
61
61
|
}
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
// Derive a unique data filename from the HTML filename to avoid collisions
|
|
63
|
+
// when multiple reports (e.g. accessibility + execution) share the same folder.
|
|
64
|
+
const htmlBaseName = path.basename(outputFileName, '.html');
|
|
65
|
+
const dataJsName = `data-${htmlBaseName}.js`;
|
|
66
|
+
// 1. Copy the HTML template and patch the data.js reference to the unique name
|
|
67
|
+
let templateHtml = fs.readFileSync(templatePath, 'utf8');
|
|
68
|
+
templateHtml = templateHtml.replace(/(<script\s+src=")data\.js(")/, `$1${dataJsName}$2`);
|
|
69
|
+
fs.writeFileSync(outputFileName, templateHtml, 'utf8');
|
|
70
|
+
// 2. Wrap the report data in a JS variable and write the per-report data file
|
|
65
71
|
const outputDir = path.dirname(outputFileName);
|
|
66
|
-
const dataJsPath = path.join(outputDir,
|
|
72
|
+
const dataJsPath = path.join(outputDir, dataJsName);
|
|
67
73
|
const jsContent = `window.snapAllyData = ${JSON.stringify(data)};`;
|
|
68
74
|
fs.writeFileSync(dataJsPath, jsContent, 'utf8');
|
|
69
75
|
// 3. Copy the global CSS and JS rendering engine next to the HTML file
|
package/dist/A11yScanner.js
CHANGED
|
@@ -41,7 +41,7 @@ async function scanA11y(page, testInfo, options = {}) {
|
|
|
41
41
|
// Sanitize pageKey to prevent path traversal attacks
|
|
42
42
|
const rawPageKey = options.pageKey || page.url();
|
|
43
43
|
const pageKey = sanitizePageKey(rawPageKey);
|
|
44
|
-
const overlay = new A11yAuditOverlay_1.A11yAuditOverlay(page
|
|
44
|
+
const overlay = new A11yAuditOverlay_1.A11yAuditOverlay(page);
|
|
45
45
|
// Configure Axe
|
|
46
46
|
let axeBuilder = new playwright_1.default({ page });
|
|
47
47
|
const target = options.include || options.box;
|
|
@@ -24,22 +24,68 @@ export interface AccessibilityReporterOptions {
|
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Playwright reporter for accessibility audits and test steps.
|
|
27
|
-
*
|
|
27
|
+
*
|
|
28
|
+
* Generates:
|
|
29
|
+
* - A per-test execution report (steps, video, screenshots, errors)
|
|
30
|
+
* - A per-scan accessibility report (violations, evidence, ADO integration)
|
|
31
|
+
* - A global execution summary with per-browser breakdowns
|
|
28
32
|
*/
|
|
29
33
|
declare class SnapAllyReporter implements Reporter {
|
|
30
|
-
private
|
|
31
|
-
private
|
|
32
|
-
private
|
|
33
|
-
private
|
|
34
|
-
private
|
|
34
|
+
private readonly outputFolder;
|
|
35
|
+
private readonly assetsManager;
|
|
36
|
+
private readonly renderer;
|
|
37
|
+
private readonly options;
|
|
38
|
+
private readonly colors;
|
|
35
39
|
private projectRoot;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Monotonically increasing test counter.
|
|
42
|
+
* Incremented synchronously in {@link onTestEnd} to avoid race conditions
|
|
43
|
+
* when multiple async {@link processTestResult} calls run concurrently.
|
|
44
|
+
*/
|
|
45
|
+
private testIndex;
|
|
46
|
+
/** Async tasks queued by `onTestEnd`; drained in `onEnd`. */
|
|
47
|
+
private readonly tasks;
|
|
48
|
+
/** Aggregated data for the final summary report. */
|
|
49
|
+
private readonly executionSummary;
|
|
39
50
|
constructor(options?: AccessibilityReporterOptions);
|
|
51
|
+
printsToStdio(): boolean;
|
|
40
52
|
onBegin(config: FullConfig): void;
|
|
41
53
|
onTestEnd(test: TestCase, result: TestResult): void;
|
|
42
|
-
private processTestResult;
|
|
43
54
|
onEnd(result: FullResult): Promise<void>;
|
|
55
|
+
private processTestResult;
|
|
56
|
+
/** Extracts structured metadata from test annotations and result steps. */
|
|
57
|
+
private extractTestMetadata;
|
|
58
|
+
/** Determines the browser name for the current test. */
|
|
59
|
+
private resolveBrowser;
|
|
60
|
+
/** Converts Playwright error objects into HTML-safe strings. */
|
|
61
|
+
private extractErrorLogs;
|
|
62
|
+
/** Return value for {@link processAccessibilityData}. */
|
|
63
|
+
private processAccessibilityData;
|
|
64
|
+
/** Collects all A11y data sources (attachments + annotations) for a test. */
|
|
65
|
+
private collectA11yDataSources;
|
|
66
|
+
/** Attempts to parse a single A11y data source into a ReportData object. */
|
|
67
|
+
private parseA11ySource;
|
|
68
|
+
/** Generates a sanitized HTML filename for an accessibility report. */
|
|
69
|
+
private buildA11yReportName;
|
|
70
|
+
/** Applies reporter-level configuration (colors, ADO, video) to a ReportData object. */
|
|
71
|
+
private applyReportConfig;
|
|
72
|
+
/**
|
|
73
|
+
* Backfills reproduction steps from `test.step` calls into a11y targets
|
|
74
|
+
* that have no steps recorded (e.g. violations found via static scan).
|
|
75
|
+
*/
|
|
76
|
+
private backfillSteps;
|
|
77
|
+
/**
|
|
78
|
+
* Aggregates a11y error counts into both the browser-specific and global
|
|
79
|
+
* summaries. Returns the total error count for this scan.
|
|
80
|
+
*/
|
|
81
|
+
private aggregateA11yErrors;
|
|
82
|
+
/** Updates the browser-specific test counts (passed/failed/skipped). */
|
|
83
|
+
private updateBrowserSummary;
|
|
84
|
+
/** Updates the global execution summary counts. */
|
|
85
|
+
private updateGlobalSummary;
|
|
86
|
+
/** Ensures a file group key exists in the grouped results map. */
|
|
87
|
+
private ensureGroupExists;
|
|
88
|
+
/** Lazily initialises and returns the browser summary for the given browser name. */
|
|
89
|
+
private getOrCreateBrowserSummary;
|
|
44
90
|
}
|
|
45
91
|
export default SnapAllyReporter;
|