@ngbracket/a11y-devtools 0.18.1 → 0.18.3
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/CHANGELOG.md +26 -0
- package/bin/ngbr-a11y-report.mjs +2 -1
- package/dist/report/headless.js +8 -1
- package/dist/report/serve.d.ts +4 -3
- package/dist/report/serve.js +59 -15
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,32 @@
|
|
|
3
3
|
All notable changes to `@ngbracket/a11y-devtools` are documented here.
|
|
4
4
|
This project adheres to [Semantic Versioning](https://semver.org/).
|
|
5
5
|
|
|
6
|
+
## 0.18.3
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- Report mode now scans pages served with a strict Content-Security-Policy or
|
|
11
|
+
Trusted Types. The scan runs as an injected script, which a policy such as
|
|
12
|
+
`script-src 'self'` or `require-trusted-types-for 'script'` blocked, so the
|
|
13
|
+
page was reported as an error with no findings. The scanning browser now
|
|
14
|
+
ignores the page's CSP, whether it comes from a header or a `<meta>` tag.
|
|
15
|
+
Your app's policy is unchanged. Because the scan runs without the policy,
|
|
16
|
+
anything the policy would block for real users (a web font, an inline style)
|
|
17
|
+
loads during the scan, so a problem caused by the CSP itself isn't reported.
|
|
18
|
+
|
|
19
|
+
## 0.18.2
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- `--serve` stops as soon as the Angular build fails. `ng serve` keeps
|
|
24
|
+
watching after a failed build and never answers, so report mode used to wait
|
|
25
|
+
the full `--serve-timeout` (180 s by default) and then say the server didn't
|
|
26
|
+
answer. It now waits until Angular has printed the build errors, stops the
|
|
27
|
+
server, and exits with code 2 and "The Angular build failed", followed by
|
|
28
|
+
the last lines of output. Both the application builder and the older
|
|
29
|
+
webpack builder are covered. `--serve-timeout` still applies to servers
|
|
30
|
+
that never print a failure.
|
|
31
|
+
|
|
6
32
|
## 0.18.1
|
|
7
33
|
|
|
8
34
|
### Fixed
|
package/bin/ngbr-a11y-report.mjs
CHANGED
|
@@ -28,7 +28,8 @@ Options:
|
|
|
28
28
|
answers, scan, then stop it — e.g. --serve "npx ng serve".
|
|
29
29
|
If --base already answers, that server is used as-is
|
|
30
30
|
--serve-timeout <s>
|
|
31
|
-
Seconds to wait for --serve to answer (default 180)
|
|
31
|
+
Seconds to wait for --serve to answer (default 180).
|
|
32
|
+
A failed Angular build stops it straight away
|
|
32
33
|
--route <path> Route to scan; repeat for multiple routes
|
|
33
34
|
--from <file> Don't scan: read a previous run's JSON report (from --out)
|
|
34
35
|
and write it in the --format(s) asked for — e.g. add an
|
package/dist/report/headless.js
CHANGED
|
@@ -72,7 +72,14 @@ const HIDE_OVERLAY_CSS = `${OVERLAY_EXCLUDE_SELECTOR} { display: none !important
|
|
|
72
72
|
/** Scan every route in one colour scheme, in its own browser context. */
|
|
73
73
|
async function scanPass(browser, colorScheme, config) {
|
|
74
74
|
const { baseUrl, routes, labels, waitMs, axeOptions, inPageScript, frameworkPrefixes } = config;
|
|
75
|
-
|
|
75
|
+
// bypassCSP: the scan runs as an injected inline script (plus a style tag that
|
|
76
|
+
// hides the overlay), which a strict Content-Security-Policy or Trusted Types
|
|
77
|
+
// would block. It only lifts the policy in this scanning browser.
|
|
78
|
+
const context = await browser.newContext({
|
|
79
|
+
viewport: { width: 1280, height: 900 },
|
|
80
|
+
colorScheme,
|
|
81
|
+
bypassCSP: true,
|
|
82
|
+
});
|
|
76
83
|
const pages = [];
|
|
77
84
|
try {
|
|
78
85
|
const page = await context.newPage();
|
package/dist/report/serve.d.ts
CHANGED
|
@@ -26,8 +26,9 @@ export declare function isServing(url: string): Promise<boolean>;
|
|
|
26
26
|
/**
|
|
27
27
|
* Start a dev server and resolve once `url` answers — for report mode in CI,
|
|
28
28
|
* where nothing is running yet. Rejects (after stopping the process) if the
|
|
29
|
-
* command exits first or `timeoutMs` passes; the
|
|
30
|
-
* of its output. Always `stop()` the result when
|
|
31
|
-
* SIGINT/SIGTERM stop the server before the
|
|
29
|
+
* command exits first, the Angular build fails, or `timeoutMs` passes; the
|
|
30
|
+
* error includes the last lines of its output. Always `stop()` the result when
|
|
31
|
+
* the scan is done. Until then, SIGINT/SIGTERM stop the server before the
|
|
32
|
+
* process ends.
|
|
32
33
|
*/
|
|
33
34
|
export declare function startDevServer(options: DevServerOptions): Promise<DevServer>;
|
package/dist/report/serve.js
CHANGED
|
@@ -2,6 +2,16 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
/** Lines of dev-server output kept for the error message when it fails to start. */
|
|
3
3
|
const OUTPUT_TAIL = 30;
|
|
4
4
|
const POLL_MS = 500;
|
|
5
|
+
/**
|
|
6
|
+
* What `ng serve` prints when a build fails: the application builder (esbuild),
|
|
7
|
+
* then the older browser builder (webpack). Either way the server keeps watching
|
|
8
|
+
* and never answers, so waiting for the timeout only wastes CI time.
|
|
9
|
+
*/
|
|
10
|
+
const BUILD_FAILED = /Application bundle generation failed|Failed to compile/;
|
|
11
|
+
/** `ng serve` prints this once it has listed the build errors. */
|
|
12
|
+
const WATCHING = /Watch mode enabled/;
|
|
13
|
+
/** After a failed build, how long to keep collecting its error lines (ms). */
|
|
14
|
+
const BUILD_ERRORS_MS = 2000;
|
|
5
15
|
/** True when something at `url` answers with a non-5xx response. */
|
|
6
16
|
export async function isServing(url) {
|
|
7
17
|
try {
|
|
@@ -16,9 +26,10 @@ export async function isServing(url) {
|
|
|
16
26
|
/**
|
|
17
27
|
* Start a dev server and resolve once `url` answers — for report mode in CI,
|
|
18
28
|
* where nothing is running yet. Rejects (after stopping the process) if the
|
|
19
|
-
* command exits first or `timeoutMs` passes; the
|
|
20
|
-
* of its output. Always `stop()` the result when
|
|
21
|
-
* SIGINT/SIGTERM stop the server before the
|
|
29
|
+
* command exits first, the Angular build fails, or `timeoutMs` passes; the
|
|
30
|
+
* error includes the last lines of its output. Always `stop()` the result when
|
|
31
|
+
* the scan is done. Until then, SIGINT/SIGTERM stop the server before the
|
|
32
|
+
* process ends.
|
|
22
33
|
*/
|
|
23
34
|
export async function startDevServer(options) {
|
|
24
35
|
const { command, url, timeoutMs = 180_000, reuseExisting = true } = options;
|
|
@@ -35,18 +46,43 @@ export async function startDevServer(options) {
|
|
|
35
46
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
36
47
|
});
|
|
37
48
|
const tail = [];
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
// Set when the build fails; `buildErrorsDone` once its error lines are in.
|
|
50
|
+
let buildFailedAt;
|
|
51
|
+
let buildErrorsDone = false;
|
|
52
|
+
const addLine = (line) => {
|
|
53
|
+
if (!line.trim())
|
|
54
|
+
return;
|
|
55
|
+
options.onOutput?.(line);
|
|
56
|
+
tail.push(line);
|
|
57
|
+
if (tail.length > OUTPUT_TAIL)
|
|
58
|
+
tail.shift();
|
|
59
|
+
const plain = stripAnsi(line);
|
|
60
|
+
if (buildFailedAt === undefined && BUILD_FAILED.test(plain))
|
|
61
|
+
buildFailedAt = Date.now();
|
|
62
|
+
else if (buildFailedAt !== undefined && WATCHING.test(plain))
|
|
63
|
+
buildErrorsDone = true;
|
|
64
|
+
};
|
|
65
|
+
// A chunk can end mid-line, so each stream keeps its unfinished last line
|
|
66
|
+
// until the rest arrives (or the stream ends).
|
|
67
|
+
const lineReader = () => {
|
|
68
|
+
let partial = '';
|
|
69
|
+
return {
|
|
70
|
+
data: (chunk) => {
|
|
71
|
+
const lines = (partial + chunk.toString()).split(/\r?\n/);
|
|
72
|
+
partial = lines.pop() ?? '';
|
|
73
|
+
lines.forEach(addLine);
|
|
74
|
+
},
|
|
75
|
+
end: () => {
|
|
76
|
+
addLine(partial);
|
|
77
|
+
partial = '';
|
|
78
|
+
},
|
|
79
|
+
};
|
|
47
80
|
};
|
|
48
|
-
child.stdout
|
|
49
|
-
|
|
81
|
+
for (const stream of [child.stdout, child.stderr]) {
|
|
82
|
+
const reader = lineReader();
|
|
83
|
+
stream?.on('data', reader.data);
|
|
84
|
+
stream?.on('end', reader.end);
|
|
85
|
+
}
|
|
50
86
|
let exitCode;
|
|
51
87
|
const exited = new Promise((done) => {
|
|
52
88
|
child.once('exit', (code, signal) => {
|
|
@@ -91,7 +127,12 @@ export async function startDevServer(options) {
|
|
|
91
127
|
await stop();
|
|
92
128
|
throw withOutput(`Dev server command exited (code ${exitCode}) before ${url} answered: ${command}`);
|
|
93
129
|
}
|
|
94
|
-
if (
|
|
130
|
+
if (buildFailedAt !== undefined &&
|
|
131
|
+
(buildErrorsDone || Date.now() - buildFailedAt >= BUILD_ERRORS_MS)) {
|
|
132
|
+
await stop();
|
|
133
|
+
throw withOutput(`The Angular build failed, so the dev server never started: ${command}`);
|
|
134
|
+
}
|
|
135
|
+
if (buildFailedAt === undefined && (await isServing(url)))
|
|
95
136
|
return { reused: false, stop };
|
|
96
137
|
if (Date.now() >= deadline) {
|
|
97
138
|
await stop();
|
|
@@ -100,6 +141,9 @@ export async function startDevServer(options) {
|
|
|
100
141
|
await Promise.race([exited, new Promise((r) => setTimeout(r, POLL_MS))]);
|
|
101
142
|
}
|
|
102
143
|
}
|
|
144
|
+
function stripAnsi(text) {
|
|
145
|
+
return text.replace(/\x1b\[[0-9;]*m/g, '');
|
|
146
|
+
}
|
|
103
147
|
function killTree(child, signal) {
|
|
104
148
|
if (child.pid === undefined)
|
|
105
149
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngbracket/a11y-devtools",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.3",
|
|
4
4
|
"description": "Finds accessibility problems in Angular apps and names the component behind each one. A dev overlay, or headless reports for CI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Duncan Faulkner",
|