fix(aria-snapshot): keep matching regex lines as context in diff output#40980
Open
adityasingh2400 wants to merge 1 commit into
Open
fix(aria-snapshot): keep matching regex lines as context in diff output#40980adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
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.
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.
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.