Conversation
✅ Deploy Preview for rstest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes support for importing rstest from node_modules by implementing a runtime API system that allows the rstest functions to be accessed even when imported as a dependency rather than running directly in the rstest environment.
- Replaces static type declarations with dynamic API wrappers that check for runtime availability
- Implements global API registration system to make rstest functions available across module boundaries
- Adds comprehensive e2e tests to verify the node_modules import functionality
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/runtime/api/public.ts | Replaces static declarations with dynamic API wrappers and runtime checks |
| packages/core/src/runtime/api/index.ts | Registers the runtime API globally for cross-module access |
| e2e/runner/test/runner.test.ts | Adds e2e test for node_modules import scenario |
| e2e/runner/test/fixtures/test-rstest-import/package.json | Test fixture package configuration |
| e2e/runner/test/fixtures/test-rstest-import/index.js | Test fixture demonstrating rstest import usage |
| e2e/runner/test/fixtures/runner.test.ts | Test runner that imports and uses the fixture |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
packages/core/src/runtime/api/public.ts:1
- The @ts-expect-error comment lacks explanation. Consider using a more specific type assertion or adding a comment explaining why the type error is expected and safe to ignore.
import type { Rstest, RstestUtilities } from '../../types';
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| return globalThis.RSTEST_API![name].call( | ||
| globalThis.RSTEST_API![name], | ||
| // @ts-expect-error | ||
| ...args, | ||
| ); |
There was a problem hiding this comment.
The first argument to .call() should be this context, but you're passing the function itself. This should likely be globalThis.RSTEST_API or null for the context, and the function should be called directly with globalThis.RSTEST_API![name]!(...args).
| return globalThis.RSTEST_API![name].call( | |
| globalThis.RSTEST_API![name], | |
| // @ts-expect-error | |
| ...args, | |
| ); | |
| // @ts-expect-error | |
| return globalThis.RSTEST_API![name]!(...args); |
Summary
Support use rstest test API in
node_modules.Previously, Rstest only exported type definitions for the test API and did not export the actual implementation. When running tests, it relies on Rspack to bundle and replace
@rstest/corewithglobal['@rstest/core']. If the dependencies innode_modulesare not bundled, an error will occur.Related Links
fix: #544
Checklist