feat: add aria snapshot utilities#8
Merged
sheremet-va merged 74 commits intovitest-dev:masterfrom Mar 18, 2026
Merged
Conversation
Collaborator
Author
|
This is finally ready. I ended up doing multiple iterations of both API and internal algorithm. A full context should be available in a huge comment in |
sheremet-va
approved these changes
Mar 18, 2026
Member
sheremet-va
left a comment
There was a problem hiding this comment.
I'm just gonna trust you on this one 😄
The code looks good to me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR add core aria logic required by
toMatchAriaSnapshotimplemented on vitest-dev/vitest#9668.API
Here is a rough picture of API.
Main code
I've structured code in a following way:
Part 1. Playwright fork (
src/aria/folk/)Direct copy from Playwright with minimal divergences (marked with
DIVERGENCE(playwright), list withgrep -rn 'DIVERGENCE(playwright)' src/aria/folk/). Not deeply reviewed — correctness relies on upstream.Part 2. Match algorithm (
src/aria/match.ts)This implements
matchAriaTreewhich provides parital matching/merging mechanism for givenAriaNodeandAriaTemplateNode. While playwright's aria snapshot doesn't have such update mechanism (their snapshot update is all or nothing update based on current node),matchAriaTreestill relies on exactmatchesNodeexported fromsrc/aria/folk.The algorithm, invariants, Playwright comparison, and complexity analysis are documented in the comment at the top of
match.ts.Part 3. Tests (
test/aria.test.ts)Wrote mostly manual brute force style unit tests for above utilities.
Two main testing strategies are:
runPipeline: round-trip invariant — render → parse → match →pass: true.matchhelper withassertInvariant: verifiespass = true ⟺ resolved === expectedon every test case.How to read test cases
Each
match(html, template)call returns three views. Example from'mismatch text and regex match':actualResolvedis what gets written on--update— note how/\d+/survives from the template whileChangedreplacesOriginal.actualResolvedvstemplateis what the user sees in the diff. In this case, Vitest should be able to format it like:pass = falseandactualResolved !== expected(they differ on the paragraph line).Integration with vitest
In vitest#9668, these utilities plug into a
DomainSnapshotAdapterinterface: