@surea11y/playwright 1.2.0 → 1.3.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/README.md CHANGED
@@ -24,7 +24,7 @@ await page.goto('https://example.com/');
24
24
  const results = await new A11yCoreBuilder({ page })
25
25
  .include('#main') // optional -- call multiple times for multi-region scans
26
26
  .exclude('.cookie-banner') // optional
27
- .withTags(['wcag2a', 'wcag2aa'])
27
+ .withWcag('2.2', 'AA') // the rules for WCAG 2.2's A and AA criteria
28
28
  .disableRules(['meta-refresh-no-exceptions'])
29
29
  .options({ contrast: { mode: 'auditorAssist' } })
30
30
  .analyze();
@@ -35,17 +35,19 @@ await browser.close();
35
35
 
36
36
  `results` is `@surea11y/core`'s own native result shape — see its [`OUTPUT_SCHEMA.md`](https://github.com/SureA11y/core/blob/main/docs/OUTPUT_SCHEMA.md) — not the `violations`/`passes`/`incomplete`/`inapplicable` shape used by other popular accessibility testing tools. The builder's *method names* are modeled on common conventions in this space for migration familiarity; the richer result schema is kept as-is.
37
37
 
38
- Every result says which `@surea11y/core` release produced it, in `results.engine.version` (for example `"1.10.0"`): quote it in a bug report, and compare it when two runs disagree.
38
+ Every result says which `@surea11y/core` release produced it, in `results.engine.version` (for example `"1.11.1"`): quote it in a bug report, and compare it when two runs disagree.
39
39
 
40
40
  Also see `examples/basic-scan.js` for a runnable script (`npm run example -- <url>`).
41
41
 
42
- `withTags()`/`disableRules()` above have counterparts: `.withRules([...])` (only run these specific rule IDs) and `.disableTags([...])` (never run rules carrying any of these tags). All four compose the same way similar allow/deny-list options do in other accessibility testing tools, with one non-obvious rule worth knowing: a "disable" always wins over a "with" on the same ID/tag (e.g. `.withRules(['a']).disableRules(['a'])` drops `'a'` entirely), and combining `.withRules()` **and** `.withTags()` together requires a rule to satisfy *both* (`@surea11y/core`'s default `includeMode: 'and'`), not either one.
42
+ `.withWcag(version, level)` selects by conformance target: `.withWcag('2.2', 'AA')` runs the rules for WCAG 2.2's Level A and AA criteria, by the level each criterion has in that version (4.1.1 Parsing, which 2.2 removed, is part of a `'2.1'` target and not of a `'2.2'` one). `.withBestPractices()` adds the rules that name no WCAG criterion, such as `region` and `heading-order`; on its own it runs only those. `.withRules()` and `.withTags()` add to a target's rules, and the disable methods apply after. A version other than `'2.0'`, `'2.1'` or `'2.2'`, or a level other than `'A'`, `'AA'` or `'AAA'`, throws a `TypeError` with `code: 'INVALID_RUN_ONLY'` at the call. Both need `@surea11y/core` 1.11 or later.
43
+
44
+ `withTags()`/`disableRules()` have counterparts: `.withRules([...])` (only run these specific rule IDs) and `.disableTags([...])` (never run rules carrying any of these tags). All four compose the same way similar allow/deny-list options do in other accessibility testing tools, with one non-obvious rule worth knowing: a "disable" always wins over a "with" on the same ID/tag (e.g. `.withRules(['a']).disableRules(['a'])` drops `'a'` entirely), and combining `.withRules()` **and** `.withTags()` together requires a rule to satisfy *both* (`@surea11y/core`'s default `includeMode: 'and'`), not either one.
43
45
 
44
46
  The four take a string or an array of strings. `undefined` (a missing config value) or an empty string throws a `TypeError` with `code: 'INVALID_RUN_ONLY'` at the call. A rule ID or tag the engine doesn't know is ignored, with a warning in the page's console, as long as another one in the list is known; when none is, `.analyze()` rejects with an `EngineError` (below), so a typo such as `.withTags(['wcag2.2aa'])` can't run no rules and pass.
45
47
 
46
48
  `.exclude(selector)` above excludes globally. Pass a second argument to scope it to specific rule IDs instead: `.exclude('.mat-select', { rules: ['aria-required-children'] })` skips `.mat-select` for that rule only — every other rule still sees it. Global and rule-scoped `.exclude()` calls compose freely.
47
49
 
48
- **Create one builder per scan.** `A11yCoreBuilder` is a mutable object with no reset between `.analyze()` calls — `include()`/`exclude()`/`withRules()`/`disableRules()`/`withTags()`/`disableTags()`/`options()`/`withCustomRules()` all push onto or merge into internal state that persists for the instance's lifetime. Calling one of them again before a second `.analyze()` call *accumulates* on top of the first scan's scope rather than replacing it (this is exactly what makes "call `.include()` several times for one scan," above, work — the same accumulation just also applies across separate scans if you reuse an instance). `.reportOnly()`/`.frames()`/`.elementRef()` are the exception: each call replaces the previous value instead of merging with it.
50
+ **Create one builder per scan.** `A11yCoreBuilder` is a mutable object with no reset between `.analyze()` calls — `include()`/`exclude()`/`withRules()`/`disableRules()`/`withTags()`/`disableTags()`/`options()`/`withCustomRules()`/`withPacks()` all push onto or merge into internal state that persists for the instance's lifetime. Calling one of them again before a second `.analyze()` call *accumulates* on top of the first scan's scope rather than replacing it (this is exactly what makes "call `.include()` several times for one scan," above, work — the same accumulation just also applies across separate scans if you reuse an instance). `.reportOnly()`/`.frames()`/`.elementRef()`/`.withWcag()`/`.withBestPractices()` are the exception: each call replaces the previous value instead of merging with it.
49
51
 
50
52
  ### When `.include()` matches nothing, or doesn't parse
51
53
 
@@ -60,7 +62,7 @@ const gaps = getScanGaps(results);
60
62
  // message: 'Nothing was scanned: the scan scope matched no element ("#main").' }]
61
63
  ```
62
64
 
63
- Each gap has a `kind`: `'context-not-found'` (nothing was scanned), `'context-partly-not-found'` (some of several selectors matched nothing), or `'custom-rule-skipped'` (a custom rule the engine could not run, one per rule, from `results.skippedCustomRules`).
65
+ Each gap has a `kind`: `'context-not-found'` (nothing was scanned), `'context-partly-not-found'` (some of several selectors matched nothing), `'custom-rule-skipped'` (a custom rule the engine could not run, one per rule, from `results.skippedCustomRules`), or `'pack-skipped'` (a pack that did not run, one per pack, from `results.skippedPacks`; see [Scanning with packs](#scanning-with-packs-standards-checklists-and-your-own-rules)).
64
66
 
65
67
  `.analyze()` also prints each gap with `console.warn`, once per scanned frame, prefixed with the frame's URL, for example `@surea11y/playwright (https://example.com/): Nothing was scanned: the scan scope matched no element ("#main").` The engine warns too, but in the page's console, which a Playwright run doesn't show. The warning doesn't fail anything: to fail a test on a gap, assert on `getScanGaps(results)` as below.
66
68
 
@@ -70,6 +72,8 @@ When the engine refuses its input, `.analyze()` rejects with an `EngineError` (e
70
72
 
71
73
  - `INVALID_RUN_ONLY`: none of the rule IDs given to `.withRules()`, or none of the tags given to `.withTags()`, is one the engine knows.
72
74
  - `INVALID_CONTEXT_SELECTOR`: an `.include()` selector the browser can't parse; `err.selector` names it.
75
+ - `INVALID_ENGINE_OPTIONS`: with `.options({ strictOptions: true })`, an option the engine doesn't read or a value it can't use. The message names each, with the closest known option (`lcoale`: did you mean `locale`?). Without `strictOptions`, a likely typo is only warned about in the page's console.
76
+ - `PAGE_BUILTINS_BROKEN`: the page's own scripts broke a JavaScript built-in the engine relies on (`Array.prototype.filter`, `Map`, `JSON.stringify`, ...), so no result it gave could be trusted. The message names each one.
73
77
 
74
78
  ```js
75
79
  const { A11yCoreBuilder, EngineError } = require('@surea11y/playwright');
@@ -105,7 +109,7 @@ test('page has no accessibility violations', async ({ page }) => {
105
109
  });
106
110
  ```
107
111
 
108
- To also fail when the scan left something out (an `.include()` that matched nothing, a custom rule that didn't run), assert on `getScanGaps(results)` too: `expect(getScanGaps(results), formatFailures(results)).toEqual([])`.
112
+ To also fail when the scan left something out (an `.include()` that matched nothing, a custom rule or a pack that didn't run), assert on `getScanGaps(results)` too: `expect(getScanGaps(results), formatFailures(results)).toEqual([])`.
109
113
 
110
114
  See `examples/playwright-test-example.spec.js` for a fuller, runnable version (`npm run example:e2e`) — one test proving real violations get caught (unlabeled button, missing `alt`), one proving a well-formed page passes cleanly.
111
115
 
@@ -115,15 +119,15 @@ See `examples/playwright-test-example.spec.js` for a fuller, runnable version (`
115
119
 
116
120
  ```
117
121
  Error: 1) button-name-present (serious): This button has no accessible name.
118
- at html > body > button
119
- Provide visible button text or a programmatic accessible-name mechanism (for example aria-label) so assistive technologies can identify the button.
120
- 2) img-alt-present (serious): Missing alt attribute on <img>.
121
- at html > body > img
122
- Add an alt attribute (use alt="" only for decorative images).
122
+ at main > button
123
+ Give the button visible text, or name it with aria-label, so screen reader users know what it does.
124
+ 2) img-alt-present (serious): This <img> has no alt attribute.
125
+ at main > img
126
+ Add an alt attribute that says what the image shows, or alt="" if the image is purely decorative.
123
127
 
124
128
  Part of the scan scope was not scanned: no element matched "#sidebar".
125
129
 
126
- Scanned with @surea11y/core 1.10.0.
130
+ Scanned with @surea11y/core 1.11.1.
127
131
  ```
128
132
 
129
133
  Given the whole result, as here, it also lists what the scan left out (see `getScanGaps()` above; a scan whose `.include()` matched nothing never reads as "No accessibility violations found.") and ends with the core release that produced the result. It still accepts `results.checksResults` alone, without those two parts. A finding inside a shadow tree is located through its shadow hosts, as `my-app >>> my-card >>> img` (`formatOccurrenceLocation(occurrence)` gives that line on its own); that notation is for reading, not a selector `document.querySelector()` takes. For a `.frames(true)` scan, format `results.topFrame` and each frame on its own: both functions throw a `TypeError` for the `{ topFrame, frames }` shape rather than report it as clean.
@@ -145,6 +149,16 @@ Unlike script-injection-based accessibility tools (which need a `postMessage`-ba
145
149
 
146
150
  `results.frames` is a flat list of every sub-frame, however deeply nested. A frame that couldn't be scanned (it detached or navigated away mid-scan, or is sandboxed against scripts) is an entry `{ url, error }` instead of a result, so check for `error` before reading `checksResults`.
147
151
 
152
+ `@surea11y/core`'s reporters take this result as it is (core 1.11.1 and later): `renderSarifReport(results)`, `renderJunitReport(results)`, `renderHtmlReport(results)` and the baseline functions report every frame's findings, and a frame that couldn't be scanned as not scanned, so it never reads as a pass.
153
+
154
+ ```js
155
+ const fs = require('node:fs');
156
+ const { renderSarifReport } = require('@surea11y/core/sarif');
157
+
158
+ const results = await new A11yCoreBuilder({ page }).frames(true).analyze();
159
+ fs.writeFileSync('a11y.sarif', renderSarifReport(results));
160
+ ```
161
+
148
162
  `.include()` scopes the top frame only: each sub-frame is scanned whole, as `@surea11y/core`'s own `runa11yCoreAcrossFrames` does. (A sub-frame rarely holds the element the top frame's selector names, and since core 1.10.0 a selector that matches nothing scans nothing.) `.exclude()` applies in every frame. An `EngineError` (above) rejects the whole scan, since the top frame is scanned first with the same rule and tag lists.
149
163
 
150
164
  ### Trimming the result to just violations
@@ -161,6 +175,8 @@ console.log(results.checksResults); // only fail/cantTell entries, pass/notAppli
161
175
 
162
176
  Valid outcome values are `'pass'`, `'fail'`, `'cantTell'`, `'notApplicable'`. This is pure binding-layer filtering — the engine itself still computes every rule; nothing about the scan itself changes. Combines with `.frames(true)`: the filter is applied to `results.topFrame` and each entry of `results.frames` independently.
163
177
 
178
+ A result trimmed this way is no longer the whole scan to `@surea11y/core`'s reporters: JUnit counts one test per rule it finds, and EARL makes one assertion per rule. To keep a result small and still hand it to them, ask the engine for a compact one instead, with `.options({ output: { detail: 'findings' } })`: a rule that passed or did not apply keeps only its outcome, and every reporter reads it as the full result. An empty page's result goes from about 236 KB to 80 KB.
179
+
164
180
  ### Getting a live element handle, not just a selector string
165
181
 
166
182
  By default each occurrence carries a CSS selector + HTML snippet, not a live reference to the element. Opt in to a real Playwright `ElementHandle` with `.elementRef(true)`:
@@ -211,22 +227,50 @@ const results = await new A11yCoreBuilder({ page })
211
227
 
212
228
  Invalid input (a missing/empty `id`, or a `runInPage`/`applicability` that's neither a function nor a non-empty string) throws immediately from `.withCustomRules()` itself, rather than surfacing later as a silently-skipped rule deep inside the page — easier to catch during development. (Note: a *raw* `.options({ customRules })` call bypasses this check entirely and defers to `@surea11y/core`'s own engine-side behavior, which skips an invalid descriptor rather than throwing, and lists it in `results.skippedCustomRules`.)
213
229
 
230
+ ### Scanning with packs: standards, checklists and your own rules
231
+
232
+ A pack brings rules, variants of core's rules, a standard or a checklist, and their profiles and messages, from a package of its own: a national standard such as RGAA, or your organisation's accessibility policy. `@surea11y/core` runs a pack as it runs its own rules and standards, so its results, rollups and report entries look like core's. Packs need `@surea11y/core` 1.11.1 or later.
233
+
234
+ `.withPacks()` registers packs in the page, and in every frame with `.frames(true)`, before the scan; a pack's profile is chosen with `.options({ profile })`:
235
+
236
+ ```js
237
+ const acmePolicy = require('@acme/a11y-policy'); // a pack
238
+
239
+ const results = await new A11yCoreBuilder({ page })
240
+ .withPacks(acmePolicy)
241
+ .options({ profile: 'acme-web-2026' })
242
+ .analyze();
243
+
244
+ results.engine.packs; // ['@acme/a11y-policy@1.0.0']
245
+ results.engine.profile; // 'acme-web-2026'
246
+
247
+ // A checklist's items, each one result, beside core's WCAG rollups:
248
+ results.rulesResults.filter((r) => r.meta && r.meta.standard === 'Acme web policy');
249
+ ```
250
+
251
+ A pack's own rules appear in `checksResults` like core's, with ids that start with its namespace (`acme-no-autoplay`). Without its profile, a pack's rules run only when selected, with `.withRules()` or by a tag. `@surea11y/core`'s HTML, SARIF and JUnit reports show a standard's or a checklist's items in a section of their own. Pass an array, or call `.withPacks()` again, to scan with several packs.
252
+
253
+ **Writing a pack.** A pack is an object made with `definePack` from `@surea11y/core/pack`. [`examples/acme-policy-pack.js`](./examples/acme-policy-pack.js) is a small one: a house rule, a checklist profile (WCAG 2.2 A and AA, `region`, and the house rule) and two checklist items. `npm run example:pack` scans a page with it, and [`examples/playwright-test-example.spec.js`](./examples/playwright-test-example.spec.js) uses it as a test gate. For a pack of your own, `npx surea11y-pack new <folder>` (from `@surea11y/core`) writes a package that works as generated, with its tests, docs and lint; core's [`PACKS.md`](https://github.com/SureA11y/core/blob/main/docs/PACKS.md) is the guide.
254
+
255
+ **When a pack doesn't run.** `.withPacks()` builds the page's script with the `@surea11y/core` this binding loads, and checks each pack as it does: `.analyze()` throws before scanning for a pack that core can't run, such as one whose `core` range leaves out the installed core, or whose profile names a rule that doesn't exist. A pack the page then doesn't run (one named with a raw `.options({ packs })` and never registered, or a page running another core version, when two copies of core are installed) is listed in `results.skippedPacks` with the reason. `getScanGaps()` reports that as `'pack-skipped'`, and `.analyze()` warns about it, so a test gate that asserts on `getScanGaps(results)` fails rather than passing with the pack's checks never run. Install the pack beside the binding, so npm resolves one core for both.
256
+
214
257
  ### Element addressing beyond a CSS selector
215
258
 
216
259
  Every occurrence already carries `selector` and (with `.elementRef(true)`, above) a live `ElementHandle`. For an element inside a shadow tree, `selector` holds inside its shadow root, and `shadowHostSelectors` lists the shadow hosts that lead there, outermost first, each resolved in the tree that holds it. It also carries `structuralPath` — a sibling-index path from the document root down to the flagged element (e.g. `[1, 0, 2]`) — a more robust identity than a selector string alone, since it survives some DOM changes a selector wouldn't (an id/class rename, for instance). No opt-in needed; it's already on every `fail`/`cantTell` occurrence today. See [`OUTPUT_SCHEMA.md`](https://github.com/SureA11y/core/blob/main/docs/OUTPUT_SCHEMA.md) for the full field description.
217
260
 
218
261
  ## TypeScript
219
262
 
220
- `src/A11yCoreBuilder.d.ts` (re-exported from `src/index.d.ts`, wired up via `package.json`'s `types` field) ships types for the whole builder API and the result (`A11yCoreResult`, `CheckResult`, `Occurrence`, `CompositeResult`, etc.). The result types are built on the ones `@surea11y/core` ships, so they carry every field the engine returns (`engine.version`, `engine.environment`, `contextMatch`, `skippedCustomRules`, `shadowHostSelectors`, `margin`, ...); this package adds `elementHandle` and the `.frames(true)` shape. `EngineError`/`EngineErrorCode`, `getScanGaps()`/`ScanGap` and `formatOccurrenceLocation()` are typed too. `analyze()` is typed `Promise<A11yCoreResult | A11yCoreMultiFrameResult>` — narrow on `'topFrame' in results` (or cast, if you already know which mode you called) to get the specific shape back, since a fluent builder can't statically track that `.frames(true)` was called earlier in the chain. `playwright` is a `peerDependencies` entry (not just `devDependencies`) since the class's `page` argument and `Occurrence#elementHandle` both come from it — consumers need their own `playwright` install for the types to resolve, same as they already do to construct a `Page` in the first place.
263
+ `src/A11yCoreBuilder.d.ts` (re-exported from `src/index.d.ts`, wired up via `package.json`'s `types` field) ships types for the whole builder API and the result (`A11yCoreResult`, `CheckResult`, `Occurrence`, `CompositeResult`, etc.). The result types are built on the ones `@surea11y/core` ships, so they carry every field the engine returns (`engine.version`, `engine.environment`, `contextMatch`, `skippedCustomRules`, `shadowHostSelectors`, `margin`, ...); this package adds `elementHandle` and the `.frames(true)` shape. `EngineError`/`EngineErrorCode`, `getScanGaps()`/`ScanGap` and `formatOccurrenceLocation()` are typed too, and so are `withWcag()` (`WcagVersion`, `WcagLevel`) and `withPacks()`, which takes a pack made with `definePack` (`PackLike`). Code that handles every `ScanGap` kind it knows and treats the rest in an `else` branch needs a branch for `'pack-skipped'`, which carries `pack` rather than `selectors`. `analyze()` is typed `Promise<A11yCoreResult | A11yCoreMultiFrameResult>` — narrow on `'topFrame' in results` (or cast, if you already know which mode you called) to get the specific shape back, since a fluent builder can't statically track that `.frames(true)` was called earlier in the chain. `playwright` is a `peerDependencies` entry (not just `devDependencies`) since the class's `page` argument and `Occurrence#elementHandle` both come from it — consumers need their own `playwright` install for the types to resolve, same as they already do to construct a `Page` in the first place.
221
264
 
222
- ## Rule changes in `@surea11y/core` 1.10.0
265
+ ## What changes with `@surea11y/core` 1.11
223
266
 
224
- The binding passes rule IDs and tags through to the engine, so these show in results without a change here (see core's [`CHANGELOG.md`](https://github.com/SureA11y/core/blob/main/CHANGELOG.md) for the full list):
267
+ The binding passes rule IDs, tags and options through to the engine, so these show in results without a change here (see core's [`CHANGELOG.md`](https://github.com/SureA11y/core/blob/main/CHANGELOG.md) for the full list):
225
268
 
226
- - `landmark-role-name-present` is new: an element with `role="region"` or `role="form"` and no accessible name (best practice, reported as `cantTell`).
227
- - `label-title-only` is deprecated, replaced by `form-control-programmatic-label-quality`, which reported the same fields. It now always reports `notApplicable`; its ID still resolves, so a `.withRules()` or `.disableRules()` list naming it keeps working until core 2.0.0.
228
- - Several `manual` rules, including the landmark rules, report `pass` when they checked something and found it fine, where they reported `notApplicable`. Under `.include()`, rules that compare elements across the page (`landmark-unique`, `heading-order`, `accesskeys`, ...) report `notApplicable`, since a scan of one region can't see the rest.
229
- - A rule that measures against a threshold (contrast, target size, text spacing) can carry `margin` on its result: how close the closest passing element came. It is never a finding.
269
+ - **Messages are reworded** in all five languages to say plainly what is wrong and what to do (`This <img> has no alt attribute.`). Message keys, rule IDs, reason codes and baselines are unchanged; a test that matches message text needs the new wording.
270
+ - **Contrast and target size measure what is on screen.** In a browser, the contrast rules check only text a reader can see, measure it against what is painted under it, and measure form field values and placeholders. `target-size-minimum` measures the area a pointer can hit, and exempts only links in a sentence. Expect new findings, and some old ones gone.
271
+ - **`aria-hidden-focus` maps to 4.1.2 only**, no longer to 2.4.7 Focus Visible, so `.withTags('wcag2aa')` alone no longer selects it.
272
+ - **A custom rule counts toward its WCAG criterion.** A `.withCustomRules()` rule with `meta.wcagSc` (or a WCAG `normativeMappings` entry) fails that criterion's rollup when it fails, and custom rules run after core's.
273
+ - **On/off options read as meant**: `.options({ perfStats: 'false' })` is off, where it was on. `.options({ strictOptions: true })` rejects any option the engine doesn't read (see [Errors from the engine](#errors-from-the-engine)).
230
274
 
231
275
  ## Building another framework binding?
232
276
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@surea11y/playwright",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Playwright binding for surea11y -- scan real, live-rendered pages for accessibility issues.",
5
5
  "keywords": [
6
6
  "accessibility",
@@ -39,20 +39,21 @@
39
39
  "LICENSE"
40
40
  ],
41
41
  "dependencies": {
42
- "@surea11y/binding-base": "^1.2.0",
43
- "@surea11y/core": "^1.10.0"
42
+ "@surea11y/binding-base": "^1.3.1",
43
+ "@surea11y/core": "^1.11.1"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "playwright": ">=1.0.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/node": "^20.19.43",
50
- "playwright": "^1.61.1",
51
- "typescript": "^5.9.3"
50
+ "playwright": "^1.64.0",
51
+ "typescript": "^7.0.2"
52
52
  },
53
53
  "scripts": {
54
54
  "test": "node --test tests/*.test.js",
55
55
  "example": "node examples/basic-scan.js",
56
- "example:e2e": "playwright test examples/playwright-test-example.spec.js"
56
+ "example:e2e": "playwright test examples/playwright-test-example.spec.js",
57
+ "example:pack": "node examples/scan-with-pack.js"
57
58
  }
58
59
  }
@@ -49,11 +49,14 @@ export type {
49
49
  /**
50
50
  * What analyze() rejects with when @surea11y/core refuses its input, with
51
51
  * the engine's `code`: `INVALID_RUN_ONLY` (withRules()/withTags() named no
52
- * rule or tag it knows) or `INVALID_CONTEXT_SELECTOR` (an include()
53
- * selector the browser can't parse; `selector` names it).
52
+ * rule or tag it knows), `INVALID_CONTEXT_SELECTOR` (an include() selector
53
+ * the browser can't parse; `selector` names it), `INVALID_ENGINE_OPTIONS`
54
+ * (an option `strictOptions: true` rejects) or `PAGE_BUILTINS_BROKEN` (the
55
+ * page's scripts broke a JavaScript built-in the engine relies on).
54
56
  */
55
57
  export { EngineError } from '@surea11y/binding-base';
56
- export type { EngineErrorCode } from '@surea11y/binding-base';
58
+ export type { EngineErrorCode, PackLike, WcagVersion, WcagLevel } from '@surea11y/binding-base';
59
+ import type { PackLike, WcagVersion, WcagLevel } from '@surea11y/binding-base';
57
60
 
58
61
  export type Category = Core.RuleMeta['category'];
59
62
  export type LocaleResolutionReason = Core.LocaleResolution['reason'];
@@ -138,10 +141,23 @@ export class A11yCoreBuilder {
138
141
  withRules(ruleIds: string | string[]): this;
139
142
  /** Never run these specific rule IDs (applied after withRules). */
140
143
  disableRules(ruleIds: string | string[]): this;
144
+ /**
145
+ * Run the rules for a WCAG conformance target: `withWcag('2.2', 'AA')`
146
+ * runs those of WCAG 2.2's A and AA criteria. withTags()/withRules() add
147
+ * to them. A later call replaces the target.
148
+ */
149
+ withWcag(version: WcagVersion | 2.0 | 2.1 | 2.2, level?: WcagLevel): this;
150
+ /** Also run the best-practice rules, those that name no WCAG criterion. */
151
+ withBestPractices(enabled?: boolean): this;
141
152
  /** Merge arbitrary engineOptions (locale, contrast.mode, policyContract, ...). */
142
153
  options(partialEngineOptions: Record<string, unknown>): this;
143
154
  /** Register one or more custom rules for just this scan. Call multiple times to accumulate. */
144
155
  withCustomRules(rules: CustomRuleDescriptor | CustomRuleDescriptor[]): this;
156
+ /**
157
+ * Packs from `@surea11y/core/pack` (core 1.11 or later): registered in each
158
+ * frame before the scan, and named in `engineOptions.packs`.
159
+ */
160
+ withPacks(packs: PackLike | PackLike[]): this;
145
161
  /** Post-filter checksResults down to only the given outcomes. */
146
162
  reportOnly(outcomes: Outcome | Outcome[]): this;
147
163
  /** Opt in to also scanning every sub-frame on the page (including cross-origin iframes). */
@@ -152,7 +168,7 @@ export class A11yCoreBuilder {
152
168
  /**
153
169
  * Runs the scan. Returns { topFrame, frames } instead of a single result
154
170
  * when .frames(true) was used. Rejects with an EngineError when the engine
155
- * refuses the rule/tag lists or an include() selector.
171
+ * refuses its input (see EngineError).
156
172
  */
157
173
  analyze(): Promise<A11yCoreResult | A11yCoreMultiFrameResult>;
158
174
  }
@@ -178,8 +194,9 @@ export function formatFailures(
178
194
  * What a scan result says it left out, which its checksResults alone would
179
195
  * pass over as clean: an include() scope that matched no element
180
196
  * (`context-not-found`, nothing was scanned), some include() selectors that
181
- * matched nothing (`context-partly-not-found`), and each custom rule that
182
- * did not run (`custom-rule-skipped`). Each gap has a `message`. Throws a
197
+ * matched nothing (`context-partly-not-found`), each custom rule that did
198
+ * not run (`custom-rule-skipped`), and each pack that did not run
199
+ * (`pack-skipped`). Each gap has a `message`. Throws a
183
200
  * TypeError for a frames(true) result: call it on `topFrame` and on each
184
201
  * scanned frame.
185
202
  */
@@ -173,11 +173,15 @@ class A11yCoreBuilder extends A11yCoreBuilderBase {
173
173
  */
174
174
  async analyze() {
175
175
  const { contextSelector, engineOptions, runOnly } = this._buildEngineArgs();
176
+ // The script that registers withPacks()'s packs in a frame, which the
177
+ // scan names in engineOptions.packs; null without packs.
178
+ const packScript = this._packScript();
176
179
 
177
180
  // A Playwright Page and a Frame both expose the same .evaluate(fn, arg)
178
181
  // and .url() shape, so this works unchanged for either.
179
182
  const runInFrame = async (frameOrPage, frameContextSelector) => {
180
183
  const frameUrl = this._url || (typeof frameOrPage.url === 'function' ? frameOrPage.url() : null);
184
+ if (packScript) await frameOrPage.evaluate(packScript);
181
185
  const result = rethrowEngineError(await frameOrPage.evaluate(scanInPage, {
182
186
  url: frameUrl,
183
187
  contextSelector: frameContextSelector,