Skip to content

feat: support use toMatchInlineSnapshot outside of test#747

Merged
9aoy merged 2 commits intomainfrom
toMatchInlineSnapshot
Dec 9, 2025
Merged

feat: support use toMatchInlineSnapshot outside of test#747
9aoy merged 2 commits intomainfrom
toMatchInlineSnapshot

Conversation

@9aoy
Copy link
Copy Markdown
Collaborator

@9aoy 9aoy commented Dec 9, 2025

Summary

support use toMatchInlineSnapshot and toThrowErrorMatchingInlineSnapshot outside of test

before:
image

after:

image

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings December 9, 2025 10:52
@netlify
Copy link
Copy Markdown

netlify bot commented Dec 9, 2025

Deploy Preview for rstest-dev ready!

Name Link
🔨 Latest commit e8c1301
🔍 Latest deploy log https://app.netlify.com/projects/rstest-dev/deploys/693802234f98630008c91db7
😎 Deploy Preview https://deploy-preview-747--rstest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.runTests to createRunner.runner.runTests to ensure it's set up before any hooks execute
  • SnapshotPlugin converted to a factory function accepting WorkerState, with chai plugin registration moved inside createExpect
  • toMatchInlineSnapshot made 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.

@9aoy 9aoy merged commit c10a04a into main Dec 9, 2025
17 checks passed
@9aoy 9aoy deleted the toMatchInlineSnapshot branch December 9, 2025 11:10
@9aoy 9aoy mentioned this pull request Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants