Skip to content

fix(rstest): always hoist @rstest/core init fragment#12363

Merged
9aoy merged 1 commit intomainfrom
rstest-all-hoist
Dec 4, 2025
Merged

fix(rstest): always hoist @rstest/core init fragment#12363
9aoy merged 1 commit intomainfrom
rstest-all-hoist

Conversation

@fi3ework
Copy link
Copy Markdown
Member

@fi3ework fi3ework commented Dec 3, 2025

Summary

currently, following code will raise an error Cannot read properties of undefined (reading 'rs'). since using rs function is a common pattern, so we hoist it anyway.

import { foo } from '../src/foo';
import { expect, it, rs } from '@rstest/core';

rs.mock('../src/foo', () => {
  return {
    foo: rs.fn(),
  };
});

Related links

Checklist

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

Copilot AI review requested due to automatic review settings December 3, 2025 12:19
@fi3ework fi3ework requested a review from LingyuCoder as a code owner December 3, 2025 12:19
@netlify
Copy link
Copy Markdown

netlify bot commented Dec 3, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 3f58120
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/69302ae273953a00082eca7e

@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: bug fix release: bug related release(mr only) labels Dec 3, 2025
@fi3ework fi3ework requested a review from 9aoy December 3, 2025 12:20
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 fixes a bug where using rs functions (like rs.fn()) in mock factory functions would cause a "Cannot read properties of undefined" error. The fix ensures that the @rstest/core import is always hoisted to the top of the module, not just when rs.hoisted() is used.

Key changes:

  • Removed the condition that only hoisted @rstest/core for MockMethod::Hoisted
  • Updated the comment to reflect that hoisting now applies to all hoisted code

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 3, 2025

Rsdoctor Bundle Diff Analysis

Found 5 project(s) in monorepo.

📁 react-10k

Path: ../build-tools-performance/cases/react-10k/dist/rsdoctor-data.json

📌 Baseline Commit: 39f82ff660 | PR: #12362

Metric Current Baseline Change
📊 Total Size 5.7 MB 5.7 MB 0 B (0.0%)
📄 JavaScript 5.7 MB 5.7 MB 0 B (0.0%)
🎨 CSS 21.0 B 21.0 B 0 B (0.0%)
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: react-10k Bundle Diff

📁 react-1k

Path: ../build-tools-performance/cases/react-1k/dist/rsdoctor-data.json

📌 Baseline Commit: 39f82ff660 | PR: #12362

Metric Current Baseline Change
📊 Total Size 822.6 KB 822.6 KB 0 B (0.0%)
📄 JavaScript 822.6 KB 822.6 KB 0 B (0.0%)
🎨 CSS 0 B 0 B N/A
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: react-1k Bundle Diff

📁 react-5k

Path: ../build-tools-performance/cases/react-5k/dist/rsdoctor-data.json

📌 Baseline Commit: 39f82ff660 | PR: #12362

Metric Current Baseline Change
📊 Total Size 2.7 MB 2.7 MB 0 B (0.0%)
📄 JavaScript 2.7 MB 2.7 MB 0 B (0.0%)
🎨 CSS 21.0 B 21.0 B 0 B (0.0%)
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: react-5k Bundle Diff

📁 rome

Path: ../build-tools-performance/cases/rome/dist/rsdoctor-data.json

📌 Baseline Commit: 39f82ff660 | PR: #12362

Metric Current Baseline Change
📊 Total Size 984.3 KB 984.3 KB 0 B (0.0%)
📄 JavaScript 984.3 KB 984.3 KB 0 B (0.0%)
🎨 CSS 0 B 0 B N/A
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: rome Bundle Diff

📁 ui-components

Path: ../build-tools-performance/cases/ui-components/dist/rsdoctor-data.json

📌 Baseline Commit: 39f82ff660 | PR: #12362

Metric Current Baseline Change
📊 Total Size 2.1 MB 2.1 MB 0 B (0.0%)
📄 JavaScript 2.0 MB 2.0 MB 0 B (0.0%)
🎨 CSS 83.0 KB 83.0 KB 0 B (0.0%)
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: ui-components Bundle Diff

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 3, 2025

📦 Binary Size-limit

Comparing 3f58120 to chore(deps): bump Rslib v0.18.3 (#12362) by Timeless0911

🎉 Size decreased by 128bytes from 47.72MB to 47.72MB (⬇️0.00%)

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Dec 3, 2025

CodSpeed Performance Report

Merging #12363 will not alter performance

Comparing rstest-all-hoist (3f58120) with main (39f82ff)

Summary

✅ 17 untouched

@9aoy 9aoy merged commit 4adc554 into main Dec 4, 2025
61 checks passed
@9aoy 9aoy deleted the rstest-all-hoist branch December 4, 2025 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants