@vitest-agent/mcp 1.0.1 → 1.2.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 +1 -2
- package/bin/vitest-agent-mcp.js +1 -17
- package/index.d.ts +324 -315
- package/index.js +2 -4
- package/middleware/idempotency.js +1 -1
- package/package.json +2 -2
- package/server.js +2 -4
- package/tools/acceptance-metrics.js +1 -1
- package/tools/cache-health.js +1 -1
- package/tools/commit-changes.js +1 -1
- package/tools/configure.js +1 -1
- package/tools/coverage.js +1 -1
- package/tools/errors.js +1 -1
- package/tools/failure-signature-get.js +1 -1
- package/tools/file-coverage.js +1 -1
- package/tools/history.js +1 -1
- package/tools/inventory.js +1 -1
- package/tools/overview.js +1 -1
- package/tools/run-tests.js +15 -3
- package/tools/settings-list.js +1 -1
- package/tools/status.js +1 -1
- package/tools/tdd-artifact.js +1 -1
- package/tools/tdd-task.js +1 -1
- package/tools/test.js +1 -1
- package/tools/trends.js +1 -1
- package/tools/turn-search.js +1 -1
- package/public/patterns/_meta.json +0 -67
- package/public/patterns/authoring-a-custom-vitest-agent-reporter.md +0 -82
- package/public/patterns/known-issues-and-caveats.md +0 -52
- package/public/patterns/operating-vitest-agent-as-an-agent.md +0 -53
- package/public/patterns/running-tests-via-mcp.md +0 -58
- package/public/patterns/silencing-leaking-output-in-tests.md +0 -91
- package/public/patterns/testing-effect-schema-definitions.md +0 -71
- package/public/patterns/testing-effect-services-with-mock-layers.md +0 -63
- package/public/vendor/vitest-docs/ATTRIBUTION.md +0 -5
- package/public/vendor/vitest-docs/api/advanced/artifacts.md +0 -189
- package/public/vendor/vitest-docs/api/advanced/metadata.md +0 -68
- package/public/vendor/vitest-docs/api/advanced/plugin.md +0 -168
- package/public/vendor/vitest-docs/api/advanced/reporters.md +0 -342
- package/public/vendor/vitest-docs/api/advanced/runner.md +0 -334
- package/public/vendor/vitest-docs/api/advanced/test-case.md +0 -302
- package/public/vendor/vitest-docs/api/advanced/test-collection.md +0 -89
- package/public/vendor/vitest-docs/api/advanced/test-module.md +0 -140
- package/public/vendor/vitest-docs/api/advanced/test-project.md +0 -321
- package/public/vendor/vitest-docs/api/advanced/test-specification.md +0 -96
- package/public/vendor/vitest-docs/api/advanced/test-suite.md +0 -230
- package/public/vendor/vitest-docs/api/advanced/vitest.md +0 -684
- package/public/vendor/vitest-docs/api/assert-type.md +0 -22
- package/public/vendor/vitest-docs/api/assert.md +0 -1960
- package/public/vendor/vitest-docs/api/browser/assertions.md +0 -1277
- package/public/vendor/vitest-docs/api/browser/commands.md +0 -154
- package/public/vendor/vitest-docs/api/browser/context.md +0 -338
- package/public/vendor/vitest-docs/api/browser/interactivity.md +0 -681
- package/public/vendor/vitest-docs/api/browser/locators.md +0 -1171
- package/public/vendor/vitest-docs/api/browser/react.md +0 -346
- package/public/vendor/vitest-docs/api/browser/svelte.md +0 -292
- package/public/vendor/vitest-docs/api/browser/vue.md +0 -222
- package/public/vendor/vitest-docs/api/describe.md +0 -374
- package/public/vendor/vitest-docs/api/expect-typeof.md +0 -571
- package/public/vendor/vitest-docs/api/expect.md +0 -2304
- package/public/vendor/vitest-docs/api/hooks.md +0 -463
- package/public/vendor/vitest-docs/api/mock.md +0 -701
- package/public/vendor/vitest-docs/api/test.md +0 -926
- package/public/vendor/vitest-docs/api/vi.md +0 -1372
- package/public/vendor/vitest-docs/config/alias.md +0 -13
- package/public/vendor/vitest-docs/config/allowonly.md +0 -32
- package/public/vendor/vitest-docs/config/api.md +0 -27
- package/public/vendor/vitest-docs/config/attachmentsdir.md +0 -6
- package/public/vendor/vitest-docs/config/bail.md +0 -9
- package/public/vendor/vitest-docs/config/benchmark.md +0 -65
- package/public/vendor/vitest-docs/config/browser/api.md +0 -23
- package/public/vendor/vitest-docs/config/browser/commands.md +0 -6
- package/public/vendor/vitest-docs/config/browser/connecttimeout.md +0 -10
- package/public/vendor/vitest-docs/config/browser/detailspanelposition.md +0 -38
- package/public/vendor/vitest-docs/config/browser/enabled.md +0 -40
- package/public/vendor/vitest-docs/config/browser/expect.md +0 -250
- package/public/vendor/vitest-docs/config/browser/headless.md +0 -7
- package/public/vendor/vitest-docs/config/browser/instances.md +0 -47
- package/public/vendor/vitest-docs/config/browser/isolate.md +0 -11
- package/public/vendor/vitest-docs/config/browser/locators.md +0 -24
- package/public/vendor/vitest-docs/config/browser/orchestratorscripts.md +0 -39
- package/public/vendor/vitest-docs/config/browser/playwright.md +0 -214
- package/public/vendor/vitest-docs/config/browser/preview.md +0 -32
- package/public/vendor/vitest-docs/config/browser/provider.md +0 -79
- package/public/vendor/vitest-docs/config/browser/screenshotdirectory.md +0 -6
- package/public/vendor/vitest-docs/config/browser/screenshotfailures.md +0 -6
- package/public/vendor/vitest-docs/config/browser/testerhtmlpath.md +0 -5
- package/public/vendor/vitest-docs/config/browser/trace.md +0 -43
- package/public/vendor/vitest-docs/config/browser/trackunhandlederrors.md +0 -10
- package/public/vendor/vitest-docs/config/browser/ui.md +0 -7
- package/public/vendor/vitest-docs/config/browser/viewport.md +0 -6
- package/public/vendor/vitest-docs/config/browser/webdriverio.md +0 -64
- package/public/vendor/vitest-docs/config/cache.md +0 -26
- package/public/vendor/vitest-docs/config/chaiconfig.md +0 -29
- package/public/vendor/vitest-docs/config/clearmocks.md +0 -22
- package/public/vendor/vitest-docs/config/coverage.md +0 -455
- package/public/vendor/vitest-docs/config/css.md +0 -47
- package/public/vendor/vitest-docs/config/dangerouslyignoreunhandlederrors.md +0 -23
- package/public/vendor/vitest-docs/config/deps.md +0 -127
- package/public/vendor/vitest-docs/config/detectasyncleaks.md +0 -39
- package/public/vendor/vitest-docs/config/diff.md +0 -96
- package/public/vendor/vitest-docs/config/dir.md +0 -7
- package/public/vendor/vitest-docs/config/disableconsoleintercept.md +0 -15
- package/public/vendor/vitest-docs/config/env.md +0 -5
- package/public/vendor/vitest-docs/config/environment.md +0 -96
- package/public/vendor/vitest-docs/config/environmentoptions.md +0 -30
- package/public/vendor/vitest-docs/config/exclude.md +0 -49
- package/public/vendor/vitest-docs/config/execargv.md +0 -10
- package/public/vendor/vitest-docs/config/expandsnapshotdiff.md +0 -7
- package/public/vendor/vitest-docs/config/expect.md +0 -38
- package/public/vendor/vitest-docs/config/experimental.md +0 -510
- package/public/vendor/vitest-docs/config/faketimers.md +0 -51
- package/public/vendor/vitest-docs/config/fileparallelism.md +0 -11
- package/public/vendor/vitest-docs/config/forcereruntriggers.md +0 -19
- package/public/vendor/vitest-docs/config/globals.md +0 -42
- package/public/vendor/vitest-docs/config/globalsetup.md +0 -72
- package/public/vendor/vitest-docs/config/hideskippedtests.md +0 -7
- package/public/vendor/vitest-docs/config/hooktimeout.md +0 -7
- package/public/vendor/vitest-docs/config/include-source.md +0 -115
- package/public/vendor/vitest-docs/config/include.md +0 -71
- package/public/vendor/vitest-docs/config/includetasklocation.md +0 -17
- package/public/vendor/vitest-docs/config/index.md +0 -85
- package/public/vendor/vitest-docs/config/isolate.md +0 -13
- package/public/vendor/vitest-docs/config/logheapusage.md +0 -7
- package/public/vendor/vitest-docs/config/maxconcurrency.md +0 -9
- package/public/vendor/vitest-docs/config/maxworkers.md +0 -49
- package/public/vendor/vitest-docs/config/mockreset.md +0 -22
- package/public/vendor/vitest-docs/config/mode.md +0 -7
- package/public/vendor/vitest-docs/config/name.md +0 -111
- package/public/vendor/vitest-docs/config/onconsolelog.md +0 -25
- package/public/vendor/vitest-docs/config/onstacktrace.md +0 -32
- package/public/vendor/vitest-docs/config/onunhandlederror.md +0 -35
- package/public/vendor/vitest-docs/config/open.md +0 -7
- package/public/vendor/vitest-docs/config/outputfile.md +0 -7
- package/public/vendor/vitest-docs/config/passwithnotests.md +0 -7
- package/public/vendor/vitest-docs/config/pool.md +0 -45
- package/public/vendor/vitest-docs/config/printconsoletrace.md +0 -6
- package/public/vendor/vitest-docs/config/projects.md +0 -6
- package/public/vendor/vitest-docs/config/provide.md +0 -45
- package/public/vendor/vitest-docs/config/reporters.md +0 -69
- package/public/vendor/vitest-docs/config/resolvesnapshotpath.md +0 -36
- package/public/vendor/vitest-docs/config/restoremocks.md +0 -22
- package/public/vendor/vitest-docs/config/retry.md +0 -140
- package/public/vendor/vitest-docs/config/root.md +0 -6
- package/public/vendor/vitest-docs/config/runner.md +0 -6
- package/public/vendor/vitest-docs/config/sequence.md +0 -158
- package/public/vendor/vitest-docs/config/server.md +0 -68
- package/public/vendor/vitest-docs/config/setupfiles.md +0 -40
- package/public/vendor/vitest-docs/config/silent.md +0 -9
- package/public/vendor/vitest-docs/config/slowtestthreshold.md +0 -7
- package/public/vendor/vitest-docs/config/snapshotenvironment.md +0 -27
- package/public/vendor/vitest-docs/config/snapshotformat.md +0 -28
- package/public/vendor/vitest-docs/config/snapshotserializers.md +0 -6
- package/public/vendor/vitest-docs/config/stricttags.md +0 -30
- package/public/vendor/vitest-docs/config/tags.md +0 -141
- package/public/vendor/vitest-docs/config/teardowntimeout.md +0 -7
- package/public/vendor/vitest-docs/config/testnamepattern.md +0 -21
- package/public/vendor/vitest-docs/config/testtimeout.md +0 -7
- package/public/vendor/vitest-docs/config/typecheck.md +0 -77
- package/public/vendor/vitest-docs/config/ui.md +0 -15
- package/public/vendor/vitest-docs/config/unstubenvs.md +0 -20
- package/public/vendor/vitest-docs/config/unstubglobals.md +0 -20
- package/public/vendor/vitest-docs/config/update.md +0 -16
- package/public/vendor/vitest-docs/config/vmmemorylimit.md +0 -30
- package/public/vendor/vitest-docs/config/watch.md +0 -11
- package/public/vendor/vitest-docs/config/watchtriggerpatterns.md +0 -29
- package/public/vendor/vitest-docs/guide/advanced/index.md +0 -147
- package/public/vendor/vitest-docs/guide/advanced/pool.md +0 -148
- package/public/vendor/vitest-docs/guide/advanced/reporters.md +0 -93
- package/public/vendor/vitest-docs/guide/advanced/tests.md +0 -125
- package/public/vendor/vitest-docs/guide/browser/aria-snapshots.md +0 -470
- package/public/vendor/vitest-docs/guide/browser/component-testing.md +0 -571
- package/public/vendor/vitest-docs/guide/browser/index.md +0 -630
- package/public/vendor/vitest-docs/guide/browser/multiple-setups.md +0 -121
- package/public/vendor/vitest-docs/guide/browser/trace-view.md +0 -126
- package/public/vendor/vitest-docs/guide/browser/visual-regression-testing.md +0 -734
- package/public/vendor/vitest-docs/guide/cli-generated.md +0 -972
- package/public/vendor/vitest-docs/guide/cli.md +0 -234
- package/public/vendor/vitest-docs/guide/common-errors.md +0 -163
- package/public/vendor/vitest-docs/guide/coverage.md +0 -515
- package/public/vendor/vitest-docs/guide/debugging.md +0 -127
- package/public/vendor/vitest-docs/guide/environment.md +0 -101
- package/public/vendor/vitest-docs/guide/extending-matchers.md +0 -160
- package/public/vendor/vitest-docs/guide/features.md +0 -310
- package/public/vendor/vitest-docs/guide/filtering.md +0 -175
- package/public/vendor/vitest-docs/guide/ide.md +0 -43
- package/public/vendor/vitest-docs/guide/improving-performance.md +0 -245
- package/public/vendor/vitest-docs/guide/in-source.md +0 -159
- package/public/vendor/vitest-docs/guide/index.md +0 -128
- package/public/vendor/vitest-docs/guide/learn/async.md +0 -147
- package/public/vendor/vitest-docs/guide/learn/debugging-tests.md +0 -210
- package/public/vendor/vitest-docs/guide/learn/matchers.md +0 -277
- package/public/vendor/vitest-docs/guide/learn/mock-functions.md +0 -277
- package/public/vendor/vitest-docs/guide/learn/setup-teardown.md +0 -240
- package/public/vendor/vitest-docs/guide/learn/snapshots.md +0 -166
- package/public/vendor/vitest-docs/guide/learn/testing-in-practice.md +0 -430
- package/public/vendor/vitest-docs/guide/learn/writing-tests-with-ai.md +0 -127
- package/public/vendor/vitest-docs/guide/learn/writing-tests.md +0 -231
- package/public/vendor/vitest-docs/guide/lifecycle.md +0 -379
- package/public/vendor/vitest-docs/guide/migration.md +0 -863
- package/public/vendor/vitest-docs/guide/mocking/classes.md +0 -158
- package/public/vendor/vitest-docs/guide/mocking/dates.md +0 -52
- package/public/vendor/vitest-docs/guide/mocking/file-system.md +0 -74
- package/public/vendor/vitest-docs/guide/mocking/functions.md +0 -61
- package/public/vendor/vitest-docs/guide/mocking/globals.md +0 -20
- package/public/vendor/vitest-docs/guide/mocking/modules.md +0 -414
- package/public/vendor/vitest-docs/guide/mocking/requests.md +0 -114
- package/public/vendor/vitest-docs/guide/mocking/timers.md +0 -48
- package/public/vendor/vitest-docs/guide/mocking.md +0 -239
- package/public/vendor/vitest-docs/guide/open-telemetry.md +0 -156
- package/public/vendor/vitest-docs/guide/parallelism.md +0 -82
- package/public/vendor/vitest-docs/guide/profiling-test-performance.md +0 -243
- package/public/vendor/vitest-docs/guide/projects.md +0 -291
- package/public/vendor/vitest-docs/guide/recipes.md +0 -59
- package/public/vendor/vitest-docs/guide/reporters.md +0 -723
- package/public/vendor/vitest-docs/guide/snapshot.md +0 -620
- package/public/vendor/vitest-docs/guide/test-annotations.md +0 -103
- package/public/vendor/vitest-docs/guide/test-context.md +0 -902
- package/public/vendor/vitest-docs/guide/test-tags.md +0 -314
- package/public/vendor/vitest-docs/guide/testing-types.md +0 -149
- package/public/vendor/vitest-docs/guide/ui.md +0 -160
- package/public/vendor/vitest-docs/guide/using-plugins.md +0 -5
- package/public/vendor/vitest-docs/manifest.json +0 -1691
- package/resources/index.js +0 -166
- package/resources/indexes.js +0 -77
- package/resources/manifest-schema.js +0 -46
- package/resources/paths.js +0 -20
- package/resources/patterns.js +0 -22
- package/resources/upstream-docs.js +0 -22
|
@@ -1,470 +0,0 @@
|
|
|
1
|
-
# ARIA Snapshots <Badge type="warning">experimental</Badge> <Version>4.1.4</Version>
|
|
2
|
-
|
|
3
|
-
ARIA snapshots let you test the accessibility structure of your pages. Instead of asserting against raw HTML or visual output, you assert against the accessibility tree — the same structure that screen readers and other assistive technologies use.
|
|
4
|
-
|
|
5
|
-
Given this HTML:
|
|
6
|
-
|
|
7
|
-
```html
|
|
8
|
-
<nav aria-label="Main">
|
|
9
|
-
<a href="/">Home</a>
|
|
10
|
-
<a href="/about">About</a>
|
|
11
|
-
</nav>
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
You can assert its accessibility tree:
|
|
15
|
-
|
|
16
|
-
```ts
|
|
17
|
-
await expect.element(page.getByRole('navigation')).toMatchAriaInlineSnapshot(`
|
|
18
|
-
- navigation "Main":
|
|
19
|
-
- link "Home":
|
|
20
|
-
- /url: /
|
|
21
|
-
- link "About":
|
|
22
|
-
- /url: /about
|
|
23
|
-
`)
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
This catches accessibility regressions: missing labels, broken roles, incorrect heading levels, and more — things that DOM snapshots would miss. Even if the underlying HTML structure changes, the assertion would not fail as long as content matches semantically.
|
|
27
|
-
|
|
28
|
-
## Snapshot Workflow
|
|
29
|
-
|
|
30
|
-
ARIA snapshots use the same Vitest snapshot workflow as other snapshot assertions. File snapshots, inline snapshots, `--update` / `-u`, watch mode updates, and CI snapshot behavior all work the same way.
|
|
31
|
-
|
|
32
|
-
See the main [Snapshot guide](/guide/snapshot) for the general snapshot workflow, update behavior, and review guidelines.
|
|
33
|
-
|
|
34
|
-
## Basic Usage
|
|
35
|
-
|
|
36
|
-
Given a page with this HTML:
|
|
37
|
-
|
|
38
|
-
```html
|
|
39
|
-
<form aria-label="Log In">
|
|
40
|
-
<input aria-label="Email" />
|
|
41
|
-
<input aria-label="Password" type="password" />
|
|
42
|
-
<button>Submit</button>
|
|
43
|
-
</form>
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### File Snapshots
|
|
47
|
-
|
|
48
|
-
Use `toMatchAriaSnapshot()` to store the snapshot in a `.snap` file alongside your test:
|
|
49
|
-
|
|
50
|
-
```ts [basic.test.ts]
|
|
51
|
-
import { expect, test } from 'vitest'
|
|
52
|
-
|
|
53
|
-
test('login form', async () => {
|
|
54
|
-
await expect.element(page.getByRole('form')).toMatchAriaSnapshot()
|
|
55
|
-
})
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
On first run, Vitest generates a snapshot file entry:
|
|
59
|
-
|
|
60
|
-
```js [__snapshots__/basic.test.ts.snap]
|
|
61
|
-
// Vitest Snapshot ...
|
|
62
|
-
|
|
63
|
-
exports[`login form 1`] = `
|
|
64
|
-
- form "Log In":
|
|
65
|
-
- textbox "Email"
|
|
66
|
-
- textbox "Password"
|
|
67
|
-
- button "Submit"
|
|
68
|
-
`
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Inline Snapshots
|
|
72
|
-
|
|
73
|
-
Use `toMatchAriaInlineSnapshot()` to store the snapshot directly in the test file:
|
|
74
|
-
|
|
75
|
-
```ts
|
|
76
|
-
import { expect, test } from 'vitest'
|
|
77
|
-
|
|
78
|
-
test('login form', async () => {
|
|
79
|
-
await expect.element(page.getByRole('form')).toMatchAriaInlineSnapshot(`
|
|
80
|
-
- form "Log In":
|
|
81
|
-
- textbox "Email"
|
|
82
|
-
- textbox "Password"
|
|
83
|
-
- button "Submit"
|
|
84
|
-
`)
|
|
85
|
-
})
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## Browser Mode Retry Behavior
|
|
89
|
-
|
|
90
|
-
In [Browser Mode](/guide/browser/), `expect.element()` polls the DOM and waits for the accessibility tree to **stabilize** before evaluating the result. On each poll, the matcher re-queries the element and re-captures the accessibility tree. The snapshot is considered stable when two consecutive polls produce the same output.
|
|
91
|
-
|
|
92
|
-
```ts
|
|
93
|
-
await expect.element(page.getByRole('form')).toMatchAriaInlineSnapshot(`
|
|
94
|
-
- form "Log In":
|
|
95
|
-
- textbox "Email"
|
|
96
|
-
- textbox "Password"
|
|
97
|
-
- button "Submit"
|
|
98
|
-
`)
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
On first run or with `--update`, the stable result is written as the new snapshot.
|
|
102
|
-
|
|
103
|
-
When an existing snapshot is present, the matcher also checks whether the stable result matches. If it does not, polling resets and continues — giving the DOM time to reach the expected state. This handles cases like animations, async rendering, or delayed state updates where the tree may briefly stabilize in an intermediate state before settling into its final form.
|
|
104
|
-
|
|
105
|
-
## Preserving Hand-Edited Patterns
|
|
106
|
-
|
|
107
|
-
When you hand-edit a snapshot to use regex patterns, those patterns survive `--update`. Only the literal parts that changed are overwritten. This lets you write flexible assertions that don't break when content changes.
|
|
108
|
-
|
|
109
|
-
### Example
|
|
110
|
-
|
|
111
|
-
**Step 1.** Your shopping cart page renders this HTML:
|
|
112
|
-
|
|
113
|
-
```html
|
|
114
|
-
<h1>Your Cart</h1>
|
|
115
|
-
<ul aria-label="Cart Items">
|
|
116
|
-
<li>Wireless Headphones — $79.99</li>
|
|
117
|
-
</ul>
|
|
118
|
-
<button>Checkout</button>
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
You run your test for the first time with `--update`. Vitest generates the snapshot:
|
|
122
|
-
|
|
123
|
-
```yaml
|
|
124
|
-
- heading "Your Cart" [level=1]
|
|
125
|
-
- list "Cart Items":
|
|
126
|
-
- listitem: Wireless Headphones — $79.99
|
|
127
|
-
- button "Checkout"
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
**Step 2.** The item names and prices are seeded test data that may change. You hand-edit those lines to regex patterns, but keep the stable structure as literals:
|
|
131
|
-
|
|
132
|
-
```yaml
|
|
133
|
-
- heading "Your Cart" [level=1]
|
|
134
|
-
- list "Cart Items":
|
|
135
|
-
- listitem: /.+ — \$\d+\.\d+/
|
|
136
|
-
- button "Checkout"
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
**Step 3.** Later, a developer renames the button from "Checkout" to "Place Order". Running `--update` updates that literal but preserves your regex patterns:
|
|
140
|
-
|
|
141
|
-
```yaml
|
|
142
|
-
- heading "Your Cart" [level=1]
|
|
143
|
-
- list "Cart Items":
|
|
144
|
-
- listitem: /.+ — \$\d+\.\d+/
|
|
145
|
-
- button "Place Order" 👈 New snapshot updated with new string
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
The regex patterns you wrote in step 2 are preserved because they still match the actual content. Only the mismatched literal "Checkout" was updated to "Place Order".
|
|
149
|
-
|
|
150
|
-
## Snapshot Format
|
|
151
|
-
|
|
152
|
-
ARIA snapshots use a YAML-like syntax. Each line represents a node in the accessibility tree.
|
|
153
|
-
|
|
154
|
-
::: info
|
|
155
|
-
ARIA snapshot templates use a **subset of YAML** syntax. Only the features needed for accessibility trees are supported: scalar values, nested mappings via indentation, and sequences (`- item`). Advanced YAML features like anchors, tags, flow collections, and multi-line scalars are not supported.
|
|
156
|
-
|
|
157
|
-
Captured text is also whitespace-normalized before it is rendered into the snapshot. Newlines, `<br>` line breaks, tabs, and repeated whitespace collapse to single spaces, so multi-line DOM text is emitted as a single-line snapshot value.
|
|
158
|
-
:::
|
|
159
|
-
|
|
160
|
-
Each accessible element in the tree is represented as a YAML node:
|
|
161
|
-
|
|
162
|
-
```yaml
|
|
163
|
-
- role "name" [attribute=value]
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
- `role`: The ARIA role of the element, such as `heading`, `list`, `listitem`, or `button`
|
|
167
|
-
- `"name"`: The [accessible name](https://w3c.github.io/accname/), when present. Quoted strings match exact values, and `/patterns/` match regular expressions
|
|
168
|
-
- `[attribute=value]`: Accessibility states and properties such as `checked`, `disabled`, `expanded`, `level`, `pressed`, or `selected`
|
|
169
|
-
|
|
170
|
-
These values come from ARIA attributes and the browser's accessibility tree, including semantics inferred from native HTML elements.
|
|
171
|
-
|
|
172
|
-
Because ARIA snapshots reflect the browser's accessibility tree, content excluded from that tree, such as `aria-hidden="true"` or `display: none`, does not appear in the snapshot.
|
|
173
|
-
|
|
174
|
-
### Roles and Accessible Names
|
|
175
|
-
|
|
176
|
-
For example:
|
|
177
|
-
|
|
178
|
-
```html
|
|
179
|
-
<button>Submit</button>
|
|
180
|
-
<h1>Welcome</h1>
|
|
181
|
-
<a href="/">Home</a>
|
|
182
|
-
<input aria-label="Email" />
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
```yaml
|
|
186
|
-
- button "Submit"
|
|
187
|
-
- heading "Welcome" [level=1]
|
|
188
|
-
- link "Home"
|
|
189
|
-
- textbox "Email"
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
The role usually comes from the element's native semantics, though it can also be defined with ARIA. The accessible name is computed from text content, associated labels, `aria-label`, `aria-labelledby`, and related naming rules.
|
|
193
|
-
|
|
194
|
-
For a closer look at how names are computed, see [Accessible Name and Description Computation](https://w3c.github.io/accname/).
|
|
195
|
-
|
|
196
|
-
Some content appears in the snapshot as a text node instead of a role-based element:
|
|
197
|
-
|
|
198
|
-
```html
|
|
199
|
-
<span>Hello world</span>
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
```yaml
|
|
203
|
-
- text: Hello world
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
Text values are always serialized on a single line after whitespace normalization. For example:
|
|
207
|
-
|
|
208
|
-
```html
|
|
209
|
-
<p>
|
|
210
|
-
Line 1
|
|
211
|
-
Line 2<br />Line 3
|
|
212
|
-
Line 4
|
|
213
|
-
</p>
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
```yaml
|
|
217
|
-
- paragraph: Line 1 Line 2 Line 3 Line 4
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
### Children
|
|
221
|
-
|
|
222
|
-
Child elements appear nested under their parent:
|
|
223
|
-
|
|
224
|
-
```html
|
|
225
|
-
<ul>
|
|
226
|
-
<li>First</li>
|
|
227
|
-
<li>Second</li>
|
|
228
|
-
<li>Third</li>
|
|
229
|
-
</ul>
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
```yaml
|
|
233
|
-
- list:
|
|
234
|
-
- listitem: First
|
|
235
|
-
- listitem: Second
|
|
236
|
-
- listitem: Third
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
If the parent has an accessible name, the snapshot includes it before the nested children:
|
|
240
|
-
|
|
241
|
-
```html
|
|
242
|
-
<nav aria-label="Main">
|
|
243
|
-
<a href="/">Home</a>
|
|
244
|
-
<a href="/about">About</a>
|
|
245
|
-
</nav>
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
```yaml
|
|
249
|
-
- navigation "Main":
|
|
250
|
-
- link "Home"
|
|
251
|
-
- link "About"
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
If an element only contains a single text child and has no other properties, the text is rendered inline:
|
|
255
|
-
|
|
256
|
-
```html
|
|
257
|
-
<p>Hello world</p>
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
```yaml
|
|
261
|
-
- paragraph: Hello world
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
### Attributes
|
|
265
|
-
|
|
266
|
-
ARIA states and properties appear in brackets:
|
|
267
|
-
|
|
268
|
-
| HTML | Snapshot |
|
|
269
|
-
| ---------------------------------------------------------------------- | ----------------------------------------- |
|
|
270
|
-
| `<input type="checkbox" checked aria-label="Agree">` | `- checkbox "Agree" [checked]` |
|
|
271
|
-
| `<input type="checkbox" aria-checked="mixed" aria-label="Select all">` | `- checkbox "Select all" [checked=mixed]` |
|
|
272
|
-
| `<button aria-disabled="true">Submit</button>` | `- button "Submit" [disabled]` |
|
|
273
|
-
| `<button aria-expanded="true">Menu</button>` | `- button "Menu" [expanded]` |
|
|
274
|
-
| `<h2>Title</h2>` | `- heading "Title" [level=2]` |
|
|
275
|
-
| `<button aria-pressed="true">Bold</button>` | `- button "Bold" [pressed]` |
|
|
276
|
-
| `<button aria-pressed="mixed">Bold</button>` | `- button "Bold" [pressed=mixed]` |
|
|
277
|
-
| `<option selected>English</option>` | `- option "English" [selected]` |
|
|
278
|
-
|
|
279
|
-
Attributes only appear when they are active. A button that is not disabled simply has no `[disabled]` attribute — there is no `[disabled=false]`.
|
|
280
|
-
|
|
281
|
-
### Pseudo-Attributes
|
|
282
|
-
|
|
283
|
-
Some DOM properties that aren't part of ARIA but are useful for testing are exposed with a `/` prefix:
|
|
284
|
-
|
|
285
|
-
#### `/url:`
|
|
286
|
-
|
|
287
|
-
Links include their URL:
|
|
288
|
-
|
|
289
|
-
```html
|
|
290
|
-
<a href="/">Home</a>
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
```yaml
|
|
294
|
-
- link "Home":
|
|
295
|
-
- /url: /
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
#### `/placeholder:`
|
|
299
|
-
|
|
300
|
-
Textboxes can include their placeholder text:
|
|
301
|
-
|
|
302
|
-
```html
|
|
303
|
-
<input aria-label="Email" placeholder="user@example.com" />
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
```yaml
|
|
307
|
-
- textbox "Email":
|
|
308
|
-
- /placeholder: user@example.com
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
::: tip When does `/placeholder:` appear?
|
|
312
|
-
|
|
313
|
-
The `/placeholder:` pseudo-attribute only appears when the placeholder text is **different from the accessible name**. When an input has a placeholder but no `aria-label` or associated `<label>`, the browser uses the placeholder as the accessible name. In that case, the placeholder information is already in the name and is not duplicated.
|
|
314
|
-
|
|
315
|
-
- When placeholder is the accessible name:
|
|
316
|
-
|
|
317
|
-
```html
|
|
318
|
-
<input placeholder="Search" />
|
|
319
|
-
```
|
|
320
|
-
|
|
321
|
-
```yaml
|
|
322
|
-
- textbox "Search"
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
- When placeholder differs from the accessible name:
|
|
326
|
-
|
|
327
|
-
```html
|
|
328
|
-
<input placeholder="Search" aria-label="Search products" />
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
```yaml
|
|
332
|
-
- textbox "Search products":
|
|
333
|
-
- /placeholder: Search
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
:::
|
|
337
|
-
|
|
338
|
-
## Matching
|
|
339
|
-
|
|
340
|
-
### Regular Expressions
|
|
341
|
-
|
|
342
|
-
Use regex patterns to match names flexibly:
|
|
343
|
-
|
|
344
|
-
```html
|
|
345
|
-
<h1>Welcome, Alice</h1>
|
|
346
|
-
<a href="https://example.com/profile/123">Profile</a>
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
```yaml
|
|
350
|
-
- heading /Welcome, .*/
|
|
351
|
-
- link "Profile":
|
|
352
|
-
- /url: /https:\/\/example\.com\/.*/
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
Regex also works in pseudo-attribute values:
|
|
356
|
-
|
|
357
|
-
```html
|
|
358
|
-
<input aria-label="Search" placeholder="Type to search..." />
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
```yaml
|
|
362
|
-
- textbox "Search":
|
|
363
|
-
- /placeholder: /Type .*/
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
::: warning Escaping backslashes in regex patterns
|
|
367
|
-
Snapshots are stored as JavaScript strings — in backtick-delimited template literals for inline snapshots and in `.snap` files. Because of this, backslashes need to be **doubled** when you hand-edit a snapshot to add a regex pattern.
|
|
368
|
-
|
|
369
|
-
For example, to match one or more digits with `\d+`:
|
|
370
|
-
|
|
371
|
-
```ts
|
|
372
|
-
// ✅ Correct — double backslash
|
|
373
|
-
await expect.element(button).toMatchAriaInlineSnapshot(`
|
|
374
|
-
- button: /item \\d+/
|
|
375
|
-
`)
|
|
376
|
-
|
|
377
|
-
// ❌ Wrong — single backslash is consumed by JS, regex sees "d+" instead of "\d+"
|
|
378
|
-
await expect.element(button).toMatchAriaInlineSnapshot(`
|
|
379
|
-
- button: /item \d+/
|
|
380
|
-
`)
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
This applies to both inline snapshots and `.snap` files. When Vitest **auto-generates** or **updates** a snapshot, escaping is handled automatically — you only need to worry about this when hand-editing regex patterns.
|
|
384
|
-
:::
|
|
385
|
-
|
|
386
|
-
### Child Matching
|
|
387
|
-
|
|
388
|
-
The `/children` directive controls how a node's children are compared against the template. There are three modes:
|
|
389
|
-
|
|
390
|
-
#### Partial Matching (default)
|
|
391
|
-
|
|
392
|
-
By default (no `/children` directive), templates use **contain** semantics — extra children in the actual tree are allowed as long as all template children appear as an ordered subsequence. This is the same as `/children: contain`.
|
|
393
|
-
|
|
394
|
-
```html
|
|
395
|
-
<main>
|
|
396
|
-
<h1>Welcome</h1>
|
|
397
|
-
<p>Some intro text</p>
|
|
398
|
-
<button>Get Started</button>
|
|
399
|
-
</main>
|
|
400
|
-
```
|
|
401
|
-
|
|
402
|
-
```ts
|
|
403
|
-
// This passes — the template children are a subset of the actual children
|
|
404
|
-
await expect.element(page.getByRole('main')).toMatchAriaInlineSnapshot(`
|
|
405
|
-
- main:
|
|
406
|
-
- heading "Welcome" [level=1]
|
|
407
|
-
`)
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
This is useful for focused, resilient tests that don't break when unrelated content is added.
|
|
411
|
-
|
|
412
|
-
#### Exact Matching (`/children: equal`)
|
|
413
|
-
|
|
414
|
-
Requires that the node's immediate children match the template exactly — same count, same order. No extra children are allowed at this level.
|
|
415
|
-
|
|
416
|
-
```html
|
|
417
|
-
<ul aria-label="Features">
|
|
418
|
-
<li>Feature A</li>
|
|
419
|
-
<li>Feature B</li>
|
|
420
|
-
<li>Feature C</li>
|
|
421
|
-
</ul>
|
|
422
|
-
```
|
|
423
|
-
|
|
424
|
-
```ts
|
|
425
|
-
// This FAILS — the list has 3 items but the template only lists 2
|
|
426
|
-
await expect.element(page.getByRole('list')).toMatchAriaInlineSnapshot(`
|
|
427
|
-
- list "Features":
|
|
428
|
-
- /children: equal
|
|
429
|
-
- listitem: Feature A
|
|
430
|
-
- listitem: Feature B
|
|
431
|
-
`)
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
```ts
|
|
435
|
-
// This PASSES — all 3 items are listed
|
|
436
|
-
await expect.element(page.getByRole('list')).toMatchAriaInlineSnapshot(`
|
|
437
|
-
- list "Features":
|
|
438
|
-
- /children: equal
|
|
439
|
-
- listitem: Feature A
|
|
440
|
-
- listitem: Feature B
|
|
441
|
-
- listitem: Feature C
|
|
442
|
-
`)
|
|
443
|
-
```
|
|
444
|
-
|
|
445
|
-
The strict matching only applies at the level where `/children` is placed. Descendants of each `listitem` still use the default contain semantics.
|
|
446
|
-
|
|
447
|
-
#### Deep Exact Matching (`/children: deep-equal`)
|
|
448
|
-
|
|
449
|
-
Like `equal`, but the strict matching **propagates to all descendants**. Every level of nesting must match exactly — same count, same order, no extra nodes at any depth.
|
|
450
|
-
|
|
451
|
-
```ts
|
|
452
|
-
await expect.element(page.getByRole('navigation')).toMatchAriaInlineSnapshot(`
|
|
453
|
-
- navigation "Main":
|
|
454
|
-
- /children: deep-equal
|
|
455
|
-
- link "Home":
|
|
456
|
-
- /url: /
|
|
457
|
-
- link "About":
|
|
458
|
-
- /url: /about
|
|
459
|
-
`)
|
|
460
|
-
```
|
|
461
|
-
|
|
462
|
-
With `deep-equal`, every child of each `link` must also match exactly. If a link had an extra child node not listed in the template, the assertion would fail.
|
|
463
|
-
|
|
464
|
-
#### Comparison
|
|
465
|
-
|
|
466
|
-
| Mode | Directive | Behavior |
|
|
467
|
-
| --- | --- | --- |
|
|
468
|
-
| Partial | _(default)_ or `/children: contain` | Template children are an ordered subsequence — extra actual children are ignored |
|
|
469
|
-
| Exact | `/children: equal` | Immediate children must match exactly; descendants still use partial matching |
|
|
470
|
-
| Deep exact | `/children: deep-equal` | All children at every depth must match exactly |
|