-
-
Notifications
You must be signed in to change notification settings - Fork 12
Closed
Description
What problem does this feature solve?
Background & Motivation
Test coverage is a critical metric in JavaScript/TypeScript projects. Currently, rstest lacks built-in coverage collection and reporting. This RFC proposes adding coverage support via a pluggable provider system, initially supporting Istanbul instrumentation with future plans for V8 and custom providers.
Goals
- Add
coverageconfig inrstest.config.ts - Support code instrumentation and runtime coverage collection
- Merge coverage data from multiple workers
- Generate coverage reports (HTML and JSON)
- Provide a CoverageProvider interface for custom implementations
What does the proposed API look like?
Configuration Example
export default defineConfig({
coverage: {
enabled: true,
provider: 'istanbul', // future: 'v8'
},
});CoverageProvider Interface
export interface CoverageProvider {
init(): void;
collect(): CoverageMap | null;
generateReports(coverageMap: CoverageMap, options: CoverageOptions): Promise<void>;
cleanup(): void;
}Instrumentation Implementation Notes
We explored three approaches for Istanbul instrumentation:
| Strategy | Description | Status | Notes |
|---|---|---|---|
| rsbuild-plugin-istanbul | rsbuild Babel plugin instrumentation | Failed | Rspack transforms code earlier; source maps unavailable |
| Manual Babel transform in rspack | Babel transform applied in rspack plugin | Working | Functional but performance untested |
| SWC plugin swc-plugin-coverage-instrument | Native SWC instrumentation | Unusable | swc-core version mismatch with rspack |
Currently, the manual Babel transform in rspack is used.
Future Plans
- Add V8 coverage support
- Support configurable reporters
- Benchmark instrumentation strategies
Appendix: Implementation Notes
Originally tried rsbuild-plugin-istanbul but rspack’s pre-transform breaks source map chain. Switched to manual Babel transform inside rspack plugin. Also attempted SWC plugin but incompatible versions blocked usage.
andriyor
Metadata
Metadata
Assignees
Labels
No labels