-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: improve asymmetric matcher diff readability by unwrapping container matchers #9330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sheremet-va
merged 10 commits into
main
from
copilot/show-clearer-diff-asymmetric-matcher
Dec 26, 2025
+168
−11
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6039252
Initial plan
Copilot dbdc3a7
Improve asymmetric matcher diff display
Copilot 2731629
Update tests and fix linting issues
Copilot e27de87
Add safety check for sample property access
Copilot a091b45
Improve test quality by validating error.diff with inline snapshots
Copilot 2da0426
Move asymmetric matcher tests to diff.test.ts and use existing helper
Copilot 30f32e0
Add test case demonstrating need for recursion in container matcher p…
Copilot 344f5c3
Remove test that doesn't demonstrate recursion necessity
Copilot 705cb6d
refactor: simplify happy path
hi-ogawa 80368bc
refactor: moving around
hi-ogawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import { stripVTControlCharacters } from 'node:util' | ||
| import { processError } from '@vitest/utils/error' | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| describe('asymmetric matcher diff display', () => { | ||
| it('shows clear diff when simple property mismatch', () => { | ||
| const actual = { | ||
| user: { | ||
| name: 'John', | ||
| age: 25, | ||
| email: 'john@example.com', | ||
| }, | ||
| } | ||
|
|
||
| // Test should fail - name doesn't contain "Jane" | ||
| try { | ||
| expect(actual).toMatchObject({ | ||
| user: expect.objectContaining({ | ||
| name: expect.stringContaining('Jane'), | ||
| age: expect.any(Number), | ||
| email: expect.stringContaining('example.com'), | ||
| }), | ||
| }) | ||
| expect.unreachable() | ||
| } | ||
| catch (err) { | ||
| const error = processError(err) | ||
| expect(stripVTControlCharacters(error.diff)).toMatchInlineSnapshot(` | ||
| "- Expected | ||
| + Received | ||
|
|
||
| { | ||
| "user": { | ||
| "age": 25, | ||
| "email": "john@example.com", | ||
| - "name": StringContaining "Jane", | ||
| + "name": "John", | ||
| }, | ||
| }" | ||
| `) | ||
| } | ||
| }) | ||
|
|
||
| it('shows clear diff with nested objectContaining - complex case', () => { | ||
| // Actual data structure similar to the issue example | ||
| const actual = { | ||
| model: 'veo-3.1-generate-preview', | ||
| instances: [ | ||
| { | ||
| prompt: 'walk', // This doesn't match the expected regex | ||
| referenceImages: [ | ||
| { | ||
| image: { | ||
| gcsUri: 'gs://example/person1.jpg', | ||
| mimeType: 'image/png', // Mismatch: expected jpeg | ||
| }, | ||
| referenceType: 'asset', | ||
| }, | ||
| { | ||
| image: { | ||
| gcsUri: 'gs://example/person.jpg', // Mismatch: doesn't contain "person2.png" | ||
| mimeType: 'image/png', | ||
| }, | ||
| referenceType: 'asset', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| parameters: { | ||
| durationSeconds: '8', // Mismatch: string instead of number | ||
| aspectRatio: '16:9', | ||
| generateAudio: true, | ||
| }, | ||
| } | ||
|
|
||
| // This should fail with multiple mismatches | ||
| try { | ||
| expect(actual).toMatchObject({ | ||
| model: expect.stringMatching(/^veo-3\.1-(fast-)?generate-preview$/), | ||
| instances: expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| prompt: expect.stringMatching(/^(?=.*walking)(?=.*together)(?=.*park).*/i), | ||
| referenceImages: expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| image: expect.objectContaining({ | ||
| gcsUri: expect.stringContaining('person1.jpg'), | ||
| mimeType: 'image/jpeg', | ||
| }), | ||
| referenceType: expect.stringMatching(/^(asset|style)$/), | ||
| }), | ||
| expect.objectContaining({ | ||
| image: expect.objectContaining({ | ||
| gcsUri: expect.stringContaining('person2.png'), | ||
| mimeType: 'image/png', | ||
| }), | ||
| referenceType: expect.stringMatching(/^(asset|style)$/), | ||
| }), | ||
| ]), | ||
| }), | ||
| ]), | ||
| parameters: expect.objectContaining({ | ||
| durationSeconds: expect.any(Number), | ||
| aspectRatio: '16:9', | ||
| generateAudio: expect.any(Boolean), | ||
| }), | ||
| }) | ||
| expect.unreachable() | ||
| } | ||
| catch (err) { | ||
| const error = processError(err) | ||
| expect(stripVTControlCharacters(error.diff)).toMatchInlineSnapshot(` | ||
| "- Expected | ||
| + Received | ||
|
|
||
| { | ||
| "instances": [ | ||
| { | ||
| - "prompt": StringMatching /^(?=.*walking)(?=.*together)(?=.*park).*/i, | ||
| + "prompt": "walk", | ||
| "referenceImages": [ | ||
| { | ||
| "image": { | ||
| "gcsUri": "gs://example/person1.jpg", | ||
| - "mimeType": "image/jpeg", | ||
| + "mimeType": "image/png", | ||
| }, | ||
| "referenceType": "asset", | ||
| }, | ||
| { | ||
| "image": { | ||
| - "gcsUri": StringContaining "person2.png", | ||
| + "gcsUri": "gs://example/person.jpg", | ||
| "mimeType": "image/png", | ||
| }, | ||
| "referenceType": "asset", | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| "model": "veo-3.1-generate-preview", | ||
| "parameters": { | ||
| "aspectRatio": "16:9", | ||
| - "durationSeconds": Any<Number>, | ||
| + "durationSeconds": "8", | ||
| "generateAudio": true, | ||
| }, | ||
| }" | ||
| `) | ||
| } | ||
| }) | ||
| }) |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.