Skip to content

fix(aria-snapshot): keep matching regex lines as context in diff output#40980

Open
adityasingh2400 wants to merge 1 commit into
microsoft:mainfrom
adityasingh2400:adityasingh2400/aria-snapshot-regex-diff
Open

fix(aria-snapshot): keep matching regex lines as context in diff output#40980
adityasingh2400 wants to merge 1 commit into
microsoft:mainfrom
adityasingh2400:adityasingh2400/aria-snapshot-regex-diff

Conversation

@adityasingh2400
Copy link
Copy Markdown

Closes #34555.

When toMatchAriaSnapshot fails on a single literal text line, the diff currently marks the surrounding regex-templated expected lines as -/+ even when their regexes actually match the received text. The extra noise masks the real mismatch.

This change pre-processes the received tree before handing it to the jest text differ. For each expected line that parses as a regex via the existing /.../ syntax, if the corresponding received line matches that regex, the received line is replaced with the expected line verbatim. The differ then renders those lines as unchanged context, so only the genuine mismatch surfaces in the output. Alignment between expected and received is preserved with an LCS pass over equality-or-regex-match, which stays correct when the two trees differ in length.

Added a regression test in tests/page/to-match-aria-snapshot.spec.ts covering the regex-match-with-literal-mismatch scenario from the issue: two regex-templated paragraph lines and a literal button line, where only the button text differs. The test asserts the literal mismatch appears in the diff while the matching regex lines do not.

When toMatchAriaSnapshot fails on a single literal text line, the diff
currently marks the surrounding regex-templated expected lines as -/+
even when their regexes actually match the received text. The extra
noise masks the real mismatch.

This change pre-processes the received tree before handing it to the
jest text differ: for each expected line that parses as a regex (via
the existing /.../ syntax for full lines or text values), if the
corresponding received line matches that regex, the received line is
replaced with the expected line verbatim. The differ then renders
those lines as unchanged context, so only the genuine mismatch
surfaces in the output.

Alignment between expected and received is preserved with an LCS pass
over equality-or-regex-match, which stays correct when the trees
differ in length.

Closes microsoft#34555.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] aria snapshot's regex marked as errors if the test fails

1 participant