-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat: drop support of async mock factory #618
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
Conversation
✅ Deploy Preview for rstest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
6b80654 to
e1c0239
Compare
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.
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
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.importActual: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