-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: support snapshot with expect.soft
#9231
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
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
b46594e
fix: add expect.soft support to toMatchSnapshot (#8673)
iumehara 81bddb7
Fix imported types in chai.ts
iumehara 135dbc1
Move expect.soft Snapshot tests to snapshot directory to test across …
iumehara 84e80f7
Fix linting errors
iumehara 48e2175
Merge branch 'main' into soft-snapshot
hi-ogawa ddb7747
test: add e2e
hi-ogawa 654bb37
test: remove artificial tests
hi-ogawa 10b2914
test: update
hi-ogawa ad74f7e
test: update
hi-ogawa 4e43f49
test: test toThrowErrorMatchingInlineSnapshot
hi-ogawa ffa7cf4
wip: is this needed?
hi-ogawa a7305c1
chore: comment
hi-ogawa 4da1cf4
Merge branch 'main' into soft-snapshot
hi-ogawa 686f7da
chore: cleanup unused
hi-ogawa bc08a4c
chore(test/snapshots): document test infra and rename test:snaps to t…
hi-ogawa d49fb31
refactor: reduce types
hi-ogawa 71449ab
fix: support soft inline snapshot
hi-ogawa bd60ae4
fix: allow soft
hi-ogawa d3ac41b
chore: comment
hi-ogawa b24963b
test: test soft inline snapshot
hi-ogawa b65a986
fix: use __INLINE_SNAPSHOT_OFFSET_3__ to tweak stack
hi-ogawa c2a0c90
fix: webkit ptc
hi-ogawa add5a14
fix: use try/finally to prevent WebKit TCO optimization
hi-ogawa 445a8f4
chore: comment
hi-ogawa 834aed2
chore: todo
hi-ogawa 9aad5a4
fix: make wrapAssertion and recordAsyncExpect work together
hi-ogawa dbd3bd3
test: test soft file snapshot warning
hi-ogawa 59f03fa
fix: fix non awaited soft warning
hi-ogawa 893628e
chore: cleanup
hi-ogawa 847a2bd
test: update
hi-ogawa a03645f
fix: soft async tracking
hi-ogawa 6b6bdf4
chore: comment
hi-ogawa 7d754ab
test: update
hi-ogawa 658a1a1
refactor: no wrapAssertion for toMatchFileSnapshot
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
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
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a quick guide for snapshot test suites. We can likely simplify |
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,55 @@ | ||
| # Snapshot Tests | ||
|
|
||
| This directory contains integration tests for Vitest's snapshot functionality. It uses a meta-testing approach where integration tests programmatically run fixture tests to validate snapshot behavior. | ||
|
|
||
| ## Directory Structure | ||
|
|
||
| ``` | ||
| test/snapshots/ | ||
| ├── test/ # Integration tests that validate snapshot features | ||
| │ └── fixtures/ # Test fixture files (copied to test-update/) | ||
| ├── test-update/ # Generated directory - populated from fixtures | ||
| ├── generate.mjs # Resets test-update/ from fixtures | ||
| └── vitest.config.ts # Test configuration | ||
| ``` | ||
|
|
||
| ## Test Scripts | ||
|
|
||
| | Script | Purpose | | ||
| |--------|---------| | ||
| | `test` | Runs the complete test suite (all scripts below in sequence) | | ||
| | `test:generate` | Resets `test-update/` by copying fresh fixtures | | ||
| | `test:update` | Runs tests with `-u` flag to update existing snapshots | | ||
| | `test:update-new` | Runs with `CI=false` to create new snapshots | | ||
| | `test:update-none` | Runs with `CI=true` to validate without updates (strict mode) | | ||
| | `test:integration` | Runs the main integration tests in `test/` | | ||
|
|
||
| ## How It Works | ||
|
|
||
| 1. **`generate.mjs`** copies fixture files from `test/fixtures/test-update/` to `test-update/` | ||
| 2. **`test:update*` scripts** run the fixture tests with different snapshot update modes | ||
| 3. **`test:integration`** runs integration tests that use `runVitest()` to programmatically execute fixtures and assert on the results | ||
|
|
||
| This setup allows testing snapshot features like: | ||
| - Inline snapshots (`toMatchInlineSnapshot`) | ||
| - File-based snapshots (`toMatchFileSnapshot`) | ||
| - Snapshot update behavior with `-u` flag | ||
| - CI vs non-CI snapshot creation modes | ||
| - Custom serializers, soft assertions, retry logic, etc. | ||
|
|
||
| ## Running Tests | ||
|
|
||
| ```bash | ||
| # Run all snapshot tests | ||
| pnpm test | ||
|
|
||
| # Or run individual stages | ||
| # - Reset fixtures | ||
| pnpm test:generate | ||
| # - Run integration tests only | ||
| pnpm test:integration | ||
| pnpm test:integration test/summary.test.ts | ||
|
|
||
| # Run one of fixtures directly | ||
| pnpm test:fixtures --root test/fixtures/summary | ||
| ``` |
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,11 @@ | ||
| import { expect, test } from 'vitest' | ||
|
|
||
| test('toMatchInlineSnapshot', () => { | ||
| expect.soft('--snap-1--').toMatchInlineSnapshot(`"--snap-1--"`) | ||
| expect.soft('--snap-2--').toMatchInlineSnapshot(`"--snap-2--"`) | ||
| }) | ||
|
|
||
| test('toThrowErrorMatchingInlineSnapshot', () => { | ||
| expect.soft(() => { throw new Error('--error-1--') }).toThrowErrorMatchingInlineSnapshot(`[Error: --error-1--]`) | ||
| expect.soft(() => { throw new Error('--error-2--') }).toThrowErrorMatchingInlineSnapshot(`[Error: --error-2--]`) | ||
| }) |
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 @@ | ||
| __snapshots__ |
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,16 @@ | ||
| import { expect, test } from 'vitest' | ||
|
|
||
| test('toMatchSnapshot', () => { | ||
| expect.soft('--snap-1--').toMatchSnapshot() | ||
| expect.soft('--snap-2--').toMatchSnapshot() | ||
| }) | ||
|
|
||
| test('toMatchFileSnapshot', async () => { | ||
| await expect.soft('--file-1--').toMatchFileSnapshot('./__snapshots__/custom1.txt') | ||
| await expect.soft('--file-2--').toMatchFileSnapshot('./__snapshots__/custom2.txt') | ||
| }) | ||
|
|
||
| test('toThrowErrorMatchingSnapshot', () => { | ||
| expect.soft(() => { throw new Error('--error-1--') }).toThrowErrorMatchingSnapshot() | ||
| expect.soft(() => { throw new Error('--error-2--') }).toThrowErrorMatchingSnapshot() | ||
| }) |
Oops, something went wrong.
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.
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.
Added minor enhancement on
@vitest/snapshotside to support more flexible inline snapshot stack offset.