feat: support output test files in ES module format#735
Merged
Conversation
✅ Deploy Preview for rstest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds support for outputting test files in ES module format through a new output.module configuration option. The implementation allows users to enable ES module output by setting output.module: true in their rstest configuration or via the RSTEST_OUTPUT_MODULE environment variable. This is a significant enhancement that provides better compatibility with modern JavaScript module systems.
- Adds
output.moduleconfiguration to enable ES module output format - Implements a separate ES module loader (
loadEsModule.ts) alongside the existing CommonJS loader - Updates build plugins to handle ES module-specific requirements (externals, banner injection, filename extensions)
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
packages/core/src/types/config.ts |
Adds module to the allowed output config options |
packages/core/src/types/core.ts |
Adds outputModule boolean field to ProjectContext |
packages/core/src/types/worker.ts |
Adds outputModule field to WorkerContext for runtime communication |
packages/core/src/core/rstest.ts |
Initializes outputModule from config or environment variable |
packages/core/src/core/plugins/basic.ts |
Configures module output settings and injects require shim banner for ESM |
packages/core/src/core/plugins/external.ts |
Updates external handling to use 'module-import' type for ES modules |
packages/core/src/core/plugins/mockRuntime.ts |
Adds chunk loading runtime modification for ES module support |
packages/core/src/runtime/worker/loadEsModule.ts |
New file implementing ES module loading using Node.js VM API |
packages/core/src/runtime/worker/index.ts |
Dynamically selects loader based on outputModule flag |
packages/core/src/pool/index.ts |
Propagates outputModule setting to worker context |
packages/core/tests/core/rsbuild.test.ts |
Adds test case for ES module output configuration |
packages/core/tests/core/__snapshots__/rsbuild.test.ts.snap |
Snapshot for ESM output webpack config |
website/docs/en/config/build/output.mdx |
English documentation for output.module |
website/docs/zh/config/build/output.mdx |
Chinese documentation for output.module |
website/theme/components/ConfigOverview.tsx |
Adds output.module to configuration overview UI |
package.json |
Updates e2e test script to include ESM testing |
e2e/package.json |
Adds test:esm script for ES module testing |
e2e/setup/index.test.ts |
Refactors test to use expectLog helper for better assertions |
e2e/mock/tests/mock.test.ts |
Adds ESM-specific test assertion for axios mocking |
e2e/externals/interop.test.ts |
Skips invalid named exports test in ESM mode |
e2e/dom/uncaughtException.test.ts |
Cleans up unused imports and variables |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
output.moduleconfiguration.Related Links
Checklist