Skip to content

fix(core): mock object properties lazily#1415

Merged
9aoy merged 8 commits into
mainfrom
9aoy/fix-lazy-automock-large-modules
Jun 15, 2026
Merged

fix(core): mock object properties lazily#1415
9aoy merged 8 commits into
mainfrom
9aoy/fix-lazy-automock-large-modules

Conversation

@9aoy

@9aoy 9aoy commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes { mock: true } and { spy: true } auto-mocking for large modules by making mockObject process 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

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

@9aoy

9aoy commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/core/src/runtime/api/mockObject.ts
@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

Rsdoctor Bundle Diff Analysis

Found 13 projects in monorepo, 2 projects with changes.

📊 Quick Summary
Project Total Size Change
adapter-rsbuild 5.4 KB 0
adapter-rslib 25.6 KB 0
adapter-rspack 9.3 KB 0
browser 2.0 MB 0
browser-react 6.4 KB 0
browser-ui 809.5 KB 0
coverage-istanbul 18.8 KB 0
coverage-v8 19.4 KB 0
core/browser 1.1 MB +2.8 KB (0.3%)
core/loaders 869.0 B 0
core/main 1.9 MB +2.7 KB (0.1%)
vscode/extension 27.0 MB 0
vscode/worker 14.5 KB 0
📋 Detailed Reports (Click to expand)

📁 core/browser

Path: packages/core/.rsdoctor/browser/rsdoctor-data.json

📌 Baseline Commit: 58f592b77e | PR: #1414

Metric Current Baseline Change
📊 Total Size 1.1 MB 1.1 MB +2.8 KB (0.3%)
📄 JavaScript 973.5 KB 970.7 KB +2.8 KB (0.3%)
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 114.6 KB 114.6 KB +6.0 B (0.0%)

📦 Download Diff Report: core/browser Bundle Diff

📁 core/main

Path: packages/core/.rsdoctor/main/rsdoctor-data.json

📌 Baseline Commit: 58f592b77e | PR: #1414

Metric Current Baseline Change
📊 Total Size 1.9 MB 1.9 MB +2.7 KB (0.1%)
📄 JavaScript 1.6 MB 1.6 MB +2.7 KB (0.2%)
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 293.7 KB 293.7 KB +6.0 B (0.0%)

📦 Download Diff Report: core/main Bundle Diff

Generated by Rsdoctor GitHub Action

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 12, 2026

Copy link
Copy Markdown

Deploying rstest with  Cloudflare Pages  Cloudflare Pages

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

View logs

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

📝 Rstest Ecosystem CI: Open

suite result
rsdoctor ✅ success
modernjs ✅ success
examples ✅ success
rspress ✅ success
rsbuild ✅ success
rslib ✅ success

@github-actions

Copy link
Copy Markdown

pkg.pr.new preview 1c6016a45bcad879db511027bd9e6132ed4b4fac · workflow run

  • pnpm add https://pkg.pr.new/web-infra-dev/rstest/@rstest/adapter-rsbuild@1c6016a45bcad879db511027bd9e6132ed4b4fac
  • pnpm add https://pkg.pr.new/web-infra-dev/rstest/@rstest/adapter-rslib@1c6016a45bcad879db511027bd9e6132ed4b4fac
  • pnpm add https://pkg.pr.new/web-infra-dev/rstest/@rstest/adapter-rspack@1c6016a45bcad879db511027bd9e6132ed4b4fac
  • pnpm add https://pkg.pr.new/web-infra-dev/rstest/@rstest/browser@1c6016a45bcad879db511027bd9e6132ed4b4fac
  • pnpm add https://pkg.pr.new/web-infra-dev/rstest/@rstest/browser-react@1c6016a45bcad879db511027bd9e6132ed4b4fac
  • pnpm add https://pkg.pr.new/web-infra-dev/rstest/@rstest/core@1c6016a45bcad879db511027bd9e6132ed4b4fac
  • pnpm add https://pkg.pr.new/web-infra-dev/rstest/@rstest/coverage-istanbul@1c6016a45bcad879db511027bd9e6132ed4b4fac
  • pnpm add https://pkg.pr.new/web-infra-dev/rstest/@rstest/coverage-v8@1c6016a45bcad879db511027bd9e6132ed4b4fac

@9aoy

9aoy commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/core/src/runtime/api/mockObject.ts Outdated
@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown

📝 Rstest Ecosystem CI: Open

suite result
examples ✅ success
rsdoctor ✅ success
rsbuild ✅ success
modernjs ✅ success
rslib ✅ success
rspress ✅ success

@9aoy

9aoy commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/core/src/runtime/api/mockObject.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 mockObject to process object/function properties lazily via accessor properties, with snapshotting support for autospy.
  • 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.

Comment thread packages/core/src/runtime/api/mockObject.ts
Comment thread packages/core/src/runtime/api/mockObject.ts Outdated
@9aoy 9aoy marked this pull request as ready for review June 15, 2026 05:03
@9aoy 9aoy merged commit 072b6dd into main Jun 15, 2026
12 checks passed
@9aoy 9aoy deleted the 9aoy/fix-lazy-automock-large-modules branch June 15, 2026 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants