Merged
Conversation
Contributor
Saga4
commented
Mar 3, 2026
- fix: use pattern matching for collocated tests in monorepos
- fix: support Mocha CJS projects and sanitize incorrect framework imports
- fix: resolve Vitest benchmarking showing wall-clock time instead of per-function timing
When testsRoot overlaps moduleRoot (common in JS/TS monorepos like Ghost where both point to "src"), the directory-based filter incorrectly excluded ALL source files. Switch to filename/directory pattern matching (*.test.*, *.spec.*, __tests__/) when roots overlap, preserving the existing directory-based filter for standard layouts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Three related fixes for Mocha test generation in CommonJS projects:
1. inject_test_globals() now accepts module_system param — emits
`require('node:assert/strict')` for CJS instead of ESM import syntax
2. ensure_module_system_compatibility() now converts ESM→CJS even when
the source has mixed imports (was skipping when both ESM and CJS were
detected, leaving the ESM import from inject_test_globals unconverted)
3. New sanitize_mocha_imports() strips vitest/jest/@jest/globals imports
that the AI sometimes generates for Mocha projects — Mocha provides
describe/it/before*/after* as globals
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…er-function timing
Root cause: Vitest performance tests reported "20.0 seconds over 1 loop"
(JUnit XML wall-clock fallback) instead of actual per-function nanosecond
timing. This was a chain of two issues:
1. **stdout interception**: Vitest's default `threads` pool intercepts
process.stdout.write() and console.log(), preventing timing markers
from flowing to the parent process. Fixed by adding `--pool=forks`
to all Vitest commands and config files. The `forks` pool uses child
processes where stdout flows directly to the parent.
2. **test name detection**: Even after markers flowed through (43,000+
found in stdout), the parser couldn't match them to JUnit XML
testcases because all markers had "unknown" as the test name. This
happened because Vitest doesn't inject `beforeEach` as a global
(unlike Jest), so capture.js's Jest-style hook to set
`currentTestName` never fired.
Fixed by adding Vitest-specific test name detection in capture.js:
- Primary: `expect.getState().currentTestName` (full describe path)
- Fallback: `__vitest_worker__.current.fullTestName`
- Defense-in-depth: parser fallback matches "unknown" markers to
the first testcase when no name match is found
Result: cheerio's `isHtml` went from "20.0s / 1 loop" to
"902μs / 20,853 loops" with proper speedup analysis.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
Claude encountered an error —— View job PR Review Summary
|
Contributor
⚡️ Codeflash found optimizations for this PR📄 98% (0.98x) speedup for
|
Contributor
⚡️ Codeflash found optimizations for this PR📄 63% (0.63x) speedup for
|
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.
