feat(coverage-istanbul): read coverage data without babel#752
feat(coverage-istanbul): read coverage data without babel#7529aoy merged 2 commits intoweb-infra-dev:mainfrom
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 refactors the coverage data extraction in @rstest/coverage-istanbul to use direct string parsing instead of babel/istanbul-lib-instrument, achieving a significant performance improvement (10.9x faster: 8.208s → 752ms for 761 files).
Key changes:
- Introduces a new string-based parser (
readInitialCoverage) that extracts coverage data by searching for a magic value and matching braces - Removes dependency on
istanbul-lib-instrumentand related babel packages - Simplifies the coverage data extraction logic in the provider
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/coverage-istanbul/src/utils.ts | New file containing string-based coverage data parser to replace babel parsing |
| packages/coverage-istanbul/src/provider.ts | Simplified to use new local readInitialCoverage function instead of istanbul-lib-instrument |
| packages/coverage-istanbul/package.json | Removed istanbul-lib-instrument and @types/istanbul-lib-instrument dependencies |
| pnpm-lock.yaml | Updated lockfile reflecting removal of babel-related dependencies |
| packages/core/LICENSE.md | Updated magic-string repository URL format (unrelated to main PR purpose) |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let remainCloseBraceCount = 1; | ||
| while (remainCloseBraceCount > 0) { | ||
| closeBraceIndex++; | ||
| if (closeBraceIndex >= code.length) throw new Error(''); | ||
| const char = code[closeBraceIndex]; | ||
| if (char === '{') remainCloseBraceCount++; | ||
| else if (char === '}') remainCloseBraceCount--; |
There was a problem hiding this comment.
The variable name remainCloseBraceCount is slightly misleading since it tracks the number of braces that still need to be matched (starting from inside the object), not the number remaining to be processed. Consider renaming to braceDepth or closeBraceBalance to better reflect its purpose as a counter that tracks nesting depth.
| let remainCloseBraceCount = 1; | |
| while (remainCloseBraceCount > 0) { | |
| closeBraceIndex++; | |
| if (closeBraceIndex >= code.length) throw new Error(''); | |
| const char = code[closeBraceIndex]; | |
| if (char === '{') remainCloseBraceCount++; | |
| else if (char === '}') remainCloseBraceCount--; | |
| let braceDepth = 1; | |
| while (braceDepth > 0) { | |
| closeBraceIndex++; | |
| if (closeBraceIndex >= code.length) throw new Error(''); | |
| const char = code[closeBraceIndex]; | |
| if (char === '{') braceDepth++; | |
| else if (char === '}') braceDepth--; |
| let remainOpenBraceCount = 1; | ||
| while (remainOpenBraceCount > 0) { | ||
| openBraceIndex--; | ||
| if (openBraceIndex < 0) throw new Error(''); | ||
| const char = code[openBraceIndex]; | ||
| if (char === '}') remainOpenBraceCount++; | ||
| else if (char === '{') remainOpenBraceCount--; | ||
| } | ||
|
|
||
| let closeBraceIndex = magicValueIndex; | ||
| let remainCloseBraceCount = 1; | ||
| while (remainCloseBraceCount > 0) { | ||
| closeBraceIndex++; | ||
| if (closeBraceIndex >= code.length) throw new Error(''); | ||
| const char = code[closeBraceIndex]; | ||
| if (char === '{') remainCloseBraceCount++; | ||
| else if (char === '}') remainCloseBraceCount--; |
There was a problem hiding this comment.
The variable name remainOpenBraceCount is slightly misleading since it tracks the number of braces that still need to be matched (starting from inside the object), not the number remaining to be processed. Consider renaming to braceDepth or openBraceBalance to better reflect its purpose as a counter that tracks nesting depth.
| let remainOpenBraceCount = 1; | |
| while (remainOpenBraceCount > 0) { | |
| openBraceIndex--; | |
| if (openBraceIndex < 0) throw new Error(''); | |
| const char = code[openBraceIndex]; | |
| if (char === '}') remainOpenBraceCount++; | |
| else if (char === '{') remainOpenBraceCount--; | |
| } | |
| let closeBraceIndex = magicValueIndex; | |
| let remainCloseBraceCount = 1; | |
| while (remainCloseBraceCount > 0) { | |
| closeBraceIndex++; | |
| if (closeBraceIndex >= code.length) throw new Error(''); | |
| const char = code[closeBraceIndex]; | |
| if (char === '{') remainCloseBraceCount++; | |
| else if (char === '}') remainCloseBraceCount--; | |
| let braceDepth = 1; | |
| while (braceDepth > 0) { | |
| openBraceIndex--; | |
| if (openBraceIndex < 0) throw new Error(''); | |
| const char = code[openBraceIndex]; | |
| if (char === '}') braceDepth++; | |
| else if (char === '{') braceDepth--; | |
| } | |
| let closeBraceIndex = magicValueIndex; | |
| let braceDepth2 = 1; | |
| while (braceDepth2 > 0) { | |
| closeBraceIndex++; | |
| if (closeBraceIndex >= code.length) throw new Error(''); | |
| const char = code[closeBraceIndex]; | |
| if (char === '{') braceDepth2++; | |
| else if (char === '}') braceDepth2--; |
|
👍 |
Summary
Read coverage data from source code using string matching, babel is not required anymore.
Tested on a project containing 761 unused files,
generateCoverageForUntestedFilesmethod's total execution time was reduced from 8.208s to 752.164ms.Related Links
Checklist