@ngbracket/a11y-devtools 0.14.0 → 0.15.0

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 CHANGED
@@ -3,6 +3,37 @@
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.15.0
7
+
8
+ ### Added
9
+
10
+ - **Re-render a saved report without scanning.** `--from <report.json>` reads
11
+ a previous run's JSON report (from `--out`) and writes it in whatever
12
+ `--format`s you ask for, so you can add an HTML report or an ACR worksheet
13
+ later without running the scan again. `--baseline` and `--fail-on` work as
14
+ usual; scan options such as `--route` or `--keyboard` are refused. The
15
+ output is byte-for-byte what the original scan would have written. For the
16
+ ACR worksheet, it notes when the report's axe-core version differs from the
17
+ installed one, or when the report predates `checks` (0.14.0).
18
+ From code: `parseReport()`, plus `axeVersion()` for the installed axe-core.
19
+
20
+ ### Changed
21
+
22
+ - Type-checking: the specs are now type-checked in CI, and the browser source
23
+ compiles without Node types (report mode has its own tsconfig). No change to
24
+ the published output.
25
+
26
+ ## 0.14.1
27
+
28
+ ### Fixed
29
+
30
+ - **`componentPath` lists each component once.** With content projection, a
31
+ finding's path could repeat a component, e.g.
32
+ `HomePageComponent > PanelComponent > HomePageComponent > AppComponent` for an
33
+ image projected into a panel. It's now
34
+ `HomePageComponent > PanelComponent > AppComponent`. The attributed
35
+ `component`, "via" notes and baseline matching are unchanged.
36
+
6
37
  ## 0.14.0
7
38
 
8
39
  ### Added
package/README.md CHANGED
@@ -67,7 +67,8 @@ npx ngbr-a11y-report --serve "npx ng serve" --route / --route /settings \
67
67
  ```
68
68
 
69
69
  Preparing a VPAT/ACR? `--format acr` adds an evaluation worksheet: the results by WCAG 2.2
70
- A/AA criterion, with the conformance columns left for a person to fill in.
70
+ A/AA criterion, with the conformance columns left for a person to fill in. Already scanned?
71
+ `--from a11y.json --out a11y --format acr` writes it from the saved JSON report.
71
72
 
72
73
  Next steps, in the docs:
73
74
  [Your first scan](https://ngbracket.com/tools/a11y-devtools/docs/first-scan) ·
@@ -91,7 +92,16 @@ heuristics, labelled "verify manually". It helps you build toward supporting WCA
91
92
  npm install --legacy-peer-deps
92
93
  npm run build # tsc -> dist/ (ESM + .d.ts) + the in-page bundle
93
94
  npm test # vitest + jsdom + Angular TestBed (real axe); the real-browser
94
- # E2E spec runs after a build, once `npx playwright install chromium`
95
+ # E2E specs run after a build, once `npx playwright install chromium`
96
+ ```
97
+
98
+ The real-browser specs are `src/testing/e2e-report.spec.ts` (report mode against plain-HTML
99
+ pages) and `src/testing/e2e-angular.spec.ts` (component attribution against a real Angular
100
+ app). The second builds the fixture app in `e2e/angular-app` itself, with `@angular/build`
101
+ (no Angular CLI needed). To build it by hand, for example to open it in a browser:
102
+
103
+ ```bash
104
+ node scripts/build-angular-fixture.mjs # → e2e/angular-app/dist/{dev,prod}/browser
95
105
  ```
96
106
 
97
107
  CI also runs a production-weight guard: a bundle-graph test that fails if axe-core
@@ -123,4 +133,7 @@ ever becomes reachable through a static import.
123
133
  - **Keyboard & Focus Mode M3** — missing focus-trap detection (uncontained
124
134
  `aria-modal`) and the keyboard-trap walk with real Tab presses.
125
135
  - CI production-weight guard.
126
- - Real-browser E2E test.
136
+ - Real-browser E2E tests, including component attribution in a real Angular app.
137
+ - Report mode can start the dev server (`--serve`).
138
+ - ACR evaluation worksheet by WCAG 2.2 A/AA criterion (`--format acr`).
139
+ - Re-render a saved JSON report in any format without scanning (`--from`).
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFileSync, writeFileSync } from 'node:fs';
3
3
  import {
4
+ axeVersion,
4
5
  diffAgainstBaseline,
5
6
  parseBaseline,
7
+ parseReport,
6
8
  scanPages,
7
9
  startDevServer,
8
10
  toAcrHtml,
@@ -17,6 +19,7 @@ const USAGE = `ngbr-a11y-report — component-attributed a11y scan of a running
17
19
  Usage:
18
20
  ngbr-a11y-report --base <url> --route <path> [--route <path> ...] [options]
19
21
  ngbr-a11y-report --serve "<command>" --route <path> [...] [options]
22
+ ngbr-a11y-report --from <report.json> [--out <prefix>] [--format <list>] [--baseline <file>] [--fail-on <impact>]
20
23
 
21
24
  Options:
22
25
  --base <url> Origin of the running dev server (e.g. http://localhost:4200).
@@ -27,6 +30,10 @@ Options:
27
30
  --serve-timeout <s>
28
31
  Seconds to wait for --serve to answer (default 180)
29
32
  --route <path> Route to scan; repeat for multiple routes
33
+ --from <file> Don't scan: read a previous run's JSON report (from --out)
34
+ and write it in the --format(s) asked for — e.g. add an
35
+ HTML report or ACR worksheet later. --baseline and
36
+ --fail-on work as usual; the scan options don't apply
30
37
  --tags <list> Comma-separated axe tags to scope the ruleset (e.g. wcag22aa,best-practice)
31
38
  --out <prefix> Write <prefix>.md / .json / .html (default: print Markdown to stdout)
32
39
  --format <list> Comma-separated: md, json, html — or both (= md,json) or all
@@ -79,6 +86,7 @@ function parseArgs(argv) {
79
86
  case '--serve': opts.serve = next(); break;
80
87
  case '--serve-timeout': opts.serveTimeout = Number(next()); break;
81
88
  case '--route': opts.routes.push(next()); break;
89
+ case '--from': opts.from = next(); break;
82
90
  case '--tags': opts.tags = next().split(',').map((s) => s.trim()).filter(Boolean); break;
83
91
  case '--out': opts.out = next(); break;
84
92
  case '--format': opts.format = next(); break;
@@ -105,7 +113,25 @@ function parseArgs(argv) {
105
113
  const opts = parseArgs(process.argv.slice(2));
106
114
  if (opts.serve && !opts.base) opts.base = 'http://localhost:4200';
107
115
 
108
- if (opts.help || !opts.base || opts.routes.length === 0) {
116
+ // Options that only mean something when scanning — refused with --from, rather
117
+ // than silently ignored.
118
+ const SCAN_ONLY = {
119
+ base: '--base', serve: '--serve', serveTimeout: '--serve-timeout', routes: '--route', tags: '--tags',
120
+ wait: '--wait', frameworkPrefixes: '--framework-prefixes / --no-skip-primitives', keyboard: '--keyboard',
121
+ focusTraps: '--focus-traps', colorScheme: '--color-scheme', darkClass: '--dark-class',
122
+ darkAttribute: '--dark-attribute', headed: '--headed',
123
+ };
124
+ if (opts.from && !opts.help) {
125
+ const clash = Object.keys(SCAN_ONLY).filter((k) => (k === 'routes' ? opts.routes.length > 0 : opts[k] !== undefined));
126
+ if (clash.length > 0) {
127
+ process.stderr.write(
128
+ `--from re-renders a saved report without scanning, so ${clash.map((k) => SCAN_ONLY[k]).join(', ')} can't be used with it.\n`,
129
+ );
130
+ process.exit(2);
131
+ }
132
+ }
133
+
134
+ if (opts.help || (!opts.from && (!opts.base || opts.routes.length === 0))) {
109
135
  process.stderr.write(USAGE);
110
136
  process.exit(opts.help ? 0 : 1);
111
137
  }
@@ -146,6 +172,29 @@ if (opts.darkAttribute) {
146
172
  darkAttribute = { name: opts.darkAttribute.slice(0, eq), value: opts.darkAttribute.slice(eq + 1) };
147
173
  }
148
174
 
175
+ let saved;
176
+ if (opts.from) {
177
+ try {
178
+ saved = parseReport(readFileSync(opts.from, 'utf8'));
179
+ } catch (err) {
180
+ process.stderr.write(`Can't use --from ${opts.from}: ${err.message}\n`);
181
+ process.exit(2);
182
+ }
183
+ if (formats.has('acr') || formats.has('acr-md')) {
184
+ // The worksheet lists which rules checked each criterion from the installed
185
+ // axe-core, so say when that isn't the version the scan ran.
186
+ if (!saved.checks) {
187
+ process.stderr.write(
188
+ `Note: ${opts.from} doesn't record what was checked (reports from before 0.14.0 don't), so the worksheet counts a rule as run only where it found something.\n`,
189
+ );
190
+ } else if (saved.checks.axeVersion !== axeVersion()) {
191
+ process.stderr.write(
192
+ `Note: the scan ran axe-core ${saved.checks.axeVersion}; the worksheet's rule lists come from the installed axe-core ${axeVersion()}.\n`,
193
+ );
194
+ }
195
+ }
196
+ }
197
+
149
198
  // Read the baseline before the (slow) scan, so a bad path fails fast.
150
199
  let baseline;
151
200
  if (opts.baseline) {
@@ -182,31 +231,35 @@ if (opts.serve) {
182
231
  );
183
232
  }
184
233
 
185
- let report;
186
- try {
187
- report = await scanPages({
188
- baseUrl: opts.base,
189
- routes: opts.routes,
190
- tags: opts.tags,
191
- waitMs: opts.wait,
192
- headed: opts.headed,
193
- frameworkPrefixes: opts.frameworkPrefixes,
194
- keyboard: opts.keyboard,
195
- focusTraps: opts.focusTraps,
196
- colorScheme: opts.colorScheme,
197
- darkClass: opts.darkClass,
198
- darkAttribute,
199
- });
200
- } finally {
201
- if (server && !server.reused) {
202
- await server.stop();
203
- process.stderr.write('Stopped the dev server.\n');
234
+ let report = saved;
235
+ if (!report) {
236
+ try {
237
+ report = await scanPages({
238
+ baseUrl: opts.base,
239
+ routes: opts.routes,
240
+ tags: opts.tags,
241
+ waitMs: opts.wait,
242
+ headed: opts.headed,
243
+ frameworkPrefixes: opts.frameworkPrefixes,
244
+ keyboard: opts.keyboard,
245
+ focusTraps: opts.focusTraps,
246
+ colorScheme: opts.colorScheme,
247
+ darkClass: opts.darkClass,
248
+ darkAttribute,
249
+ });
250
+ } finally {
251
+ if (server && !server.reused) {
252
+ await server.stop();
253
+ process.stderr.write('Stopped the dev server.\n');
254
+ }
204
255
  }
205
256
  }
206
257
 
207
258
  const allFindings = report.pages.flatMap((p) => p.findings);
208
259
  process.stderr.write(
209
- `Scanned ${report.pages.length} route(s) · ${allFindings.length} node-instance(s).\n`,
260
+ saved
261
+ ? `Read ${report.pages.length} route(s) · ${allFindings.length} node-instance(s) from ${opts.from} (scanned ${report.generatedAt}).\n`
262
+ : `Scanned ${report.pages.length} route(s) · ${allFindings.length} node-instance(s).\n`,
210
263
  );
211
264
  const diff = baseline ? diffAgainstBaseline(report, baseline) : undefined;
212
265
  if (diff) {
@@ -52,7 +52,8 @@ export declare function ngDebug(): NgDebugGlobal | undefined;
52
52
  export declare const DEFAULT_FRAMEWORK_PREFIXES: readonly string[];
53
53
  /**
54
54
  * The chain of owning components from the flagged node up to the root, nearest
55
- * first and de-duplicated. Built by walking DOM ancestors and asking Angular's
55
+ * first, each listed once (content projection can bring a component back up the
56
+ * DOM path; only its nearest position is kept). Built by walking DOM ancestors and asking Angular's
56
57
  * debug API who owns each, so a control that is itself a library primitive still
57
58
  * reveals the app component that placed it. Empty when the global is absent (prod).
58
59
  */
@@ -70,7 +70,8 @@ function isPrimitiveComponent(name, prefixes) {
70
70
  }
71
71
  /**
72
72
  * The chain of owning components from the flagged node up to the root, nearest
73
- * first and de-duplicated. Built by walking DOM ancestors and asking Angular's
73
+ * first, each listed once (content projection can bring a component back up the
74
+ * DOM path; only its nearest position is kept). Built by walking DOM ancestors and asking Angular's
74
75
  * debug API who owns each, so a control that is itself a library primitive still
75
76
  * reveals the app component that placed it. Empty when the global is absent (prod).
76
77
  */
@@ -93,7 +94,7 @@ export function resolveComponentPath(node) {
93
94
  owner = null; // node isn't part of a live view
94
95
  }
95
96
  const name = nameOf(owner);
96
- if (name && name !== path[path.length - 1])
97
+ if (name && !path.includes(name))
97
98
  path.push(name);
98
99
  el = el.parentElement;
99
100
  }
@@ -34191,7 +34191,7 @@
34191
34191
  owner = null;
34192
34192
  }
34193
34193
  const name = nameOf(owner);
34194
- if (name && name !== path[path.length - 1])
34194
+ if (name && !path.includes(name))
34195
34195
  path.push(name);
34196
34196
  el = el.parentElement;
34197
34197
  }
@@ -76,6 +76,13 @@ export declare function impactRank(impact: Impact): number;
76
76
  * output stays a valid baseline for the next run.
77
77
  */
78
78
  export declare function toJson(report: ScanReport, diff?: BaselineDiff): string;
79
+ /**
80
+ * Read a report back from its JSON text (a `toJson` report), so it can be
81
+ * rendered in another format without scanning again. The derived fields
82
+ * (`summary`, per-page counts, `scope`, `baseline`) are dropped — every format
83
+ * recomputes them. Throws a readable error for anything that isn't a report.
84
+ */
85
+ export declare function parseReport(json: string): ScanReport;
79
86
  /** UI primitives and directives a finding came through, for a "via …" note. */
80
87
  export declare function viaNames(finding: A11yFinding): string[];
81
88
  /** Findings sorted most severe first (stable within an impact level). */
@@ -86,6 +86,40 @@ export function toJson(report, diff) {
86
86
  })),
87
87
  }, null, 2);
88
88
  }
89
+ /**
90
+ * Read a report back from its JSON text (a `toJson` report), so it can be
91
+ * rendered in another format without scanning again. The derived fields
92
+ * (`summary`, per-page counts, `scope`, `baseline`) are dropped — every format
93
+ * recomputes them. Throws a readable error for anything that isn't a report.
94
+ */
95
+ export function parseReport(json) {
96
+ let data;
97
+ try {
98
+ data = JSON.parse(json);
99
+ }
100
+ catch {
101
+ throw new Error('not valid JSON — pass a report written by `--out` (the .json file).');
102
+ }
103
+ const { generatedAt, checks, pages } = (data ?? {});
104
+ const isPage = (p) => typeof p?.label === 'string' &&
105
+ typeof p.url === 'string' &&
106
+ Array.isArray(p.findings);
107
+ if (typeof generatedAt !== 'string' || !Array.isArray(pages) || !pages.every(isPage)) {
108
+ throw new Error('not a report-mode JSON report — pass a report written by `--out` (the .json file).');
109
+ }
110
+ return {
111
+ generatedAt,
112
+ ...(checks && { checks }),
113
+ pages: pages.map((p) => ({
114
+ label: p.label,
115
+ url: p.url,
116
+ findings: p.findings,
117
+ ...(p.error !== undefined && { error: p.error }),
118
+ ...(p.colorScheme && { colorScheme: p.colorScheme }),
119
+ ...(p.darkOnly && { darkOnly: true }),
120
+ })),
121
+ };
122
+ }
89
123
  /** UI primitives and directives a finding came through, for a "via …" note. */
90
124
  export function viaNames(finding) {
91
125
  // e.g. an `<button nbButton>` shows as "via NbButtonComponent" under its app owner.
@@ -88,3 +88,5 @@ export interface ScanPagesOptions {
88
88
  * to the component that rendered it — with no change to the target app.
89
89
  */
90
90
  export declare function scanPages(options: ScanPagesOptions): Promise<ScanReport>;
91
+ /** Version of the installed axe-core — the one a scan run now would use. */
92
+ export declare function axeVersion(): string;
@@ -179,6 +179,7 @@ export async function scanPages(options) {
179
179
  };
180
180
  return { generatedAt: new Date().toISOString(), checks, pages };
181
181
  }
182
- function axeVersion() {
182
+ /** Version of the installed axe-core — the one a scan run now would use. */
183
+ export function axeVersion() {
183
184
  return createRequire(import.meta.url)('axe-core/package.json').version;
184
185
  }
@@ -1,5 +1,5 @@
1
- export { scanPages, type ColorScheme, type ScanPagesOptions, type ThemeContext, } from './headless.js';
2
- export { groupByComponent, distinctRuleCount, toJson, toMarkdown, DARK_ONLY_NOTE, type PageReport, type ScanChecks, type ScanReport, } from './format.js';
1
+ export { axeVersion, scanPages, type ColorScheme, type ScanPagesOptions, type ThemeContext, } from './headless.js';
2
+ export { groupByComponent, distinctRuleCount, parseReport, toJson, toMarkdown, DARK_ONLY_NOTE, type PageReport, type ScanChecks, type ScanReport, } from './format.js';
3
3
  export { toHtml } from './html.js';
4
4
  export { diffAgainstBaseline, findingKey, findingsNotIn, parseBaseline, type BaselineDiff, type BaselineReport, type NewFinding, } from './baseline.js';
5
5
  export { isServing, startDevServer, type DevServer, type DevServerOptions } from './serve.js';
@@ -1,5 +1,5 @@
1
- export { scanPages, } from './headless.js';
2
- export { groupByComponent, distinctRuleCount, toJson, toMarkdown, DARK_ONLY_NOTE, } from './format.js';
1
+ export { axeVersion, scanPages, } from './headless.js';
2
+ export { groupByComponent, distinctRuleCount, parseReport, toJson, toMarkdown, DARK_ONLY_NOTE, } from './format.js';
3
3
  export { toHtml } from './html.js';
4
4
  export { diffAgainstBaseline, findingKey, findingsNotIn, parseBaseline, } from './baseline.js';
5
5
  export { isServing, startDevServer } from './serve.js';
package/dist/scan.d.ts CHANGED
@@ -26,7 +26,7 @@ export interface A11yFinding {
26
26
  helpUrl: string;
27
27
  /** Owning component name, or null when attribution isn't available (prod). */
28
28
  component: string | null;
29
- /** Owning components from the flagged node up to the root, nearest first; [] in prod. */
29
+ /** Owning components from the flagged node up to the root, nearest first, each once; [] in prod. */
30
30
  componentPath: string[];
31
31
  /** Directives on the flagged node (incl. hostDirectives); [] when none/unavailable. */
32
32
  directives: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngbracket/a11y-devtools",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Dev-only in-app accessibility auditing for Angular that maps each axe violation back to the component that rendered it — the attribution React overlay tools can't do.",
5
5
  "license": "MIT",
6
6
  "author": "Duncan Faulkner",
@@ -48,8 +48,9 @@
48
48
  "node": "^20.19.0 || ^22.12.0 || >=24.0.0"
49
49
  },
50
50
  "scripts": {
51
- "build": "tsc -p tsconfig.json && node scripts/build-inpage.mjs",
51
+ "build": "tsc -p tsconfig.json && tsc -p tsconfig.report.json && node scripts/build-inpage.mjs",
52
52
  "test": "vitest run",
53
+ "typecheck": "tsc -p tsconfig.spec.json --noEmit",
53
54
  "test:watch": "vitest",
54
55
  "demo:console": "vitest run --config vitest.demo.config.ts --disableConsoleIntercept",
55
56
  "prepublishOnly": "npm run build"