fix(rstest): rstest.importActual not work when imported from @rstest/core #12908
fix(rstest): rstest.importActual not work when imported from @rstest/core #12908
rstest.importActual not work when imported from @rstest/core #12908Conversation
…hain
Previously, `rstest.importActual` and `rstest.requireActual` only worked
when `rs` or `rstest` were free (global) variables. When imported from
`@rstest/core` via ESM (e.g., `import { rstest } from '@rstest/core'`),
the `for_name` parameter in `call_member_chain` would be the ESM specifier
tag instead of the variable name, causing the check to fail.
This fix extracts the variable name directly from the `call_expr.callee`
AST node, enabling proper handling of ESM imported variables.
There was a problem hiding this comment.
Pull request overview
Fixes rs/rstest.importActual/requireActual handling when rs/rstest is imported from @rstest/core (ESM), and introduces a globals option intended to control whether global rs/rstest variables are processed.
Changes:
- Add
globalsoption to rstest plugin options (Rust + Node binding types) with defaulttrue. - Update parser hook logic to detect
rs/rstestfrom the call expression callee (supporting ESM import usage). - Extend test case to cover
rs.importActual(...)whenrsis imported from@rstest/core.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/rspack-test/configCases/rstest/mock/rspack.config.js | Passes globals: true into the rstest plugin configuration for the test case. |
| tests/rspack-test/configCases/rstest/mock/importActual.js | Adds ESM import of rs from @rstest/core and asserts rs.importActual works. |
| crates/rspack_plugin_rstest/src/plugin.rs | Plumbs new globals option into parser plugin construction. |
| crates/rspack_plugin_rstest/src/parser_plugin.rs | Fixes call_member_chain detection for ESM-imported rs/rstest and adds globals option to the parser plugin. |
| crates/rspack_binding_api/src/rstest.rs | Exposes globals?: boolean to bindings and defaults it to true. |
| crates/node_binding/napi-binding.d.ts | Adds globals?: boolean to TypeScript typings for plugin options. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Rsdoctor Bundle Diff Analysis
Found 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
❌ Size increased by 256bytes from 48.27MB to 48.27MB (⬆️0.00%) |
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
rstest.importActual not works when imported from @rstest/core rstest.importActual not work when imported from @rstest/core
…st/core` (#12908) * fix(rstest): handle ESM imported rs/rstest variables in call_member_chain Previously, `rstest.importActual` and `rstest.requireActual` only worked when `rs` or `rstest` were free (global) variables. When imported from `@rstest/core` via ESM (e.g., `import { rstest } from '@rstest/core'`), the `for_name` parameter in `call_member_chain` would be the ESM specifier tag instead of the variable name, causing the check to fail. This fix extracts the variable name directly from the `call_expr.callee` AST node, enabling proper handling of ESM imported variables. * feat: only handle global `rs` and `rstest` variables when globals true * fix: clippy warnings * fix: remove globals option (other PR) * chore: useless Clippy lint ignore * test: split cases
Summary
rstest.importActualnot works when imported from@rstest/corePreviously,
rstest.importActualandrstest.requireActualonly worked whenrsorrstestwere free (global) variables. When imported from@rstest/corevia ESM (e.g.,import { rstest } from '@rstest/core'), thefor_nameparameter incall_member_chainwould be the ESM specifier tag instead of the variable name, causing the check to fail.Related links
Checklist