Conversation
✅ Deploy Preview for rstest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
6b80654 to
e1c0239
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR removes support for async mock factories in Rstest to improve performance and build reliability. The change replaces the async rs.importActual pattern within mock factories with synchronous alternatives using import attributes or query parameters.
- Introduces synchronous
importActualmethods via import attributes (with { "rstest": "importActual" }) and query parameters (?rstest=importActual) - Updates mock factory signatures to be synchronous only
- Adds configuration option
importActualMethodsto control which synchronous import methods are supported
Reviewed Changes
Copilot reviewed 60 out of 62 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| website/docs/{en,zh}/config/test/importActualMethods.mdx | New documentation for importActualMethods configuration option |
| website/docs/{en,zh}/api/rstest/mockModules.mdx | Updated API documentation removing async factory support and adding synchronous import examples |
| packages/core/src/types/config.ts | Added importActualMethods configuration type definition |
| packages/core/src/config.ts | Added default configuration for importActualMethods |
| packages/core/src/core/rsbuild.ts | Added mock loader setup for import attributes support |
| packages/core/src/core/plugins/mockRuntime.ts | Refactored runtime code generation to use external file |
| packages/core/src/core/plugins/mockRuntimeCode.js | New external runtime code file replacing inline generation |
| packages/core/src/core/plugins/external.ts | Enhanced external handling to support query-based actual imports |
| packages/core/src/utils/helper.ts | Added utility functions for parsing and manipulating rstest query parameters |
| e2e/mock/tests/* | Updated test files to use synchronous mock factories and new import patterns |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
42b2e27 to
e63bd1e
Compare
9aoy
reviewed
Oct 17, 2025
This was referenced Oct 20, 2025
9aoy
reviewed
Oct 21, 2025
9aoy
approved these changes
Oct 21, 2025
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
implementing async mock factories comes at a significant cost. besides requiring extensive runtime modifications, properly handling circular dependencies necessitates deep AST analysis and transformations. this would severely impact performance, and because static imports are converted to dynamic imports, the test files' build would inevitably diverge from the source code, leading to unknown errors.
we are dropping support for async mock factories. after investigation, we found that async mock factories are primarily used to configure partial mocks using
importActual, and the asynchronous nature ofimportActualnecessitates an async mock factory.in this PR, we introduce a new synchronous replacement for
rs.importActualby using import attributes:and, of course,
rs.importActualwill be retained. You can continue to use it withinit / testtest functions to import original modules that are not being mocked. however, it can no longer be used within mock factories, as the second parameter of the mock factory no longer accepts async functions.Related Links
Checklist