feat: support use toMatchInlineSnapshot outside of test#747
Merged
Conversation
✅ Deploy Preview for rstest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enables the use of toMatchInlineSnapshot outside of test contexts (e.g., in beforeAll or beforeEach hooks). The implementation refactors snapshot client initialization and modifies the SnapshotPlugin to accept WorkerState, allowing it to fall back to worker-level metadata when test context is unavailable.
Key Changes
- Snapshot client initialization moved from
TestRunner.runTeststocreateRunner.runner.runTeststo ensure it's set up before any hooks execute SnapshotPluginconverted to a factory function acceptingWorkerState, with chai plugin registration moved insidecreateExpecttoMatchInlineSnapshotmade test-context-optional by using worker state metadata as fallback
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
packages/core/src/runtime/runner/runner.ts |
Removed snapshot client initialization and import; now receives client as parameter |
packages/core/src/runtime/runner/index.ts |
Added snapshot client initialization before test execution |
packages/core/src/runtime/api/snapshot.ts |
Converted SnapshotPlugin to factory function accepting WorkerState; made test context optional for toMatchInlineSnapshot with fallback metadata; renamed getTestNames to getTestMeta |
packages/core/src/runtime/api/expect.ts |
Moved chai plugin registration from module scope into createExpect function; SnapshotPlugin now receives workerState |
e2e/snapshot/index.test.ts |
Added test case demonstrating toMatchInlineSnapshot usage in beforeAll hook |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
support use
toMatchInlineSnapshotandtoThrowErrorMatchingInlineSnapshotoutside of testbefore:

after:
Related Links
Checklist