fix(core): mock object properties lazily#1415
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d2414462a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Rsdoctor Bundle Diff AnalysisFound 13 projects in monorepo, 2 projects with changes. 📊 Quick Summary
📋 Detailed Reports (Click to expand)📁 core/browserPath:
📦 Download Diff Report: core/browser Bundle Diff 📁 core/mainPath:
📦 Download Diff Report: core/main Bundle Diff Generated by Rsdoctor GitHub Action |
Deploying rstest with
|
| Latest commit: |
5fa15b1
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://ebb0f7f3.rstest.pages.dev |
| Branch Preview URL: | https://9aoy-fix-lazy-automock-large.rstest.pages.dev |
pkg.pr.new preview
|
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1c6016a45b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0231c718ab
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR updates mockObject’s auto-mocking ({ mock: true }) and auto-spying ({ spy: true }) behavior to avoid eagerly traversing large module export graphs by installing lazily-initialized mocked properties, preventing worker heap exhaustion when mocking large modules (e.g. @rsbuild/core).
Changes:
- Refactors
mockObjectto process object/function properties lazily via accessor properties, with snapshotting support forautospy. - Adds/extends unit tests covering lazy nested mocking, overwrite behavior, prototype handling, snapshotting semantics, and aliased function behavior.
- Adds an e2e regression test to ensure
{ mock: true }works against a large real module (@rsbuild/core) without eager traversal.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/core/src/runtime/api/mockObject.ts | Implements lazy property mocking/spying and snapshotting logic to avoid deep eager traversal. |
| packages/core/tests/runtime/api/mockObject.test.ts | Adds unit tests validating lazy initialization, snapshot behavior, constructor prototype handling, and aliasing semantics. |
| e2e/mock/tests/mockLargeModule.test.ts | Adds an e2e regression test for lazily mocking a large module export surface. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Fixes
{ mock: true }and{ spy: true }auto-mocking for large modules by makingmockObjectprocess properties lazily instead of eagerly walking the entire export object graph. This avoids exhausting worker heap when mocking modules such as@rsbuild/core, while preserving function mock/spy behavior when a property is actually accessed.Checklist