-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix(snapshot): reject multiple toMatchInlineSnapshot
updates at the same location
#6332
Merged
sheremet-va
merged 4 commits into
vitest-dev:main
from
hi-ogawa:fix-reject-inline-snapshot-loop
Aug 13, 2024
Merged
Changes from all commits
Commits
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 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
23 changes: 23 additions & 0 deletions
23
test/cli/fixtures/fails/inline-snapshop-inside-loop-update-all.test.ts
This file contains 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,23 @@ | ||
import {test, expect} from "vitest"; | ||
|
||
test("ok", () => { | ||
expect("ok").toMatchInlineSnapshot(`"ok"`); | ||
}); | ||
|
||
test("fail 1", () => { | ||
for (const str of ["foo", "bar"]) { | ||
expect(str).toMatchInlineSnapshot(); | ||
} | ||
}); | ||
|
||
test("fail 3", () => { | ||
for (const str of ["ok", "ok"]) { | ||
expect(str).toMatchInlineSnapshot(); | ||
} | ||
}); | ||
|
||
test("somehow ok", () => { | ||
for (const str of ["ok", "ok"]) { | ||
expect(str).toMatchInlineSnapshot(`"ok"`); | ||
} | ||
}); |
9 changes: 9 additions & 0 deletions
9
test/cli/fixtures/fails/inline-snapshop-inside-loop-update-none.test.ts
This file contains 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,9 @@ | ||
import {test, expect} from "vitest"; | ||
|
||
// this test causes infinite re-run when --watch and --update | ||
// since snapshot update switches between "foo" and "bar" forever. | ||
test("fail 2", () => { | ||
for (const str of ["foo", "bar"]) { | ||
expect(str).toMatchInlineSnapshot(`"bar"`); | ||
} | ||
}); |
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we do something about this? this message implies that it's not fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is not ideal but I couldn't come up with a quick solution from what's available currently.
I think this is rather an edge case compared to OP's case, so we could postpone a proper fix later until someone comes across this. Btw, this behavior is same for current Vitest so that's unchanged. Jest also ends up with infinite re-run for this case.
Mentioning an idea for a proper fix, it would probably require keeping track of all
toMatchInlineSnapshot
call locations, not only failed ones. CurrentlyparseErrorStacktrace
is not used whentoMatchInlineSnapshot
succeeds, so I need to move up some code fromSnapshotState._addSnapshot
and also adjust states probably.