Fix vi.mock() path resolution in generated vitest tests#1982
Fix vi.mock() path resolution in generated vitest tests#1982mohammedahmed18 wants to merge 1 commit intomainfrom
Conversation
Extended fix_jest_mock_paths() to handle vitest mock calls (vi.mock()) in
addition to jest.mock(). Previously, only jest.mock() paths were corrected,
causing vitest tests to fail with "Cannot find module" errors.
Problem:
- Source at src/agents/workspace.ts imports ../routing/session-key
- Generated test at test/test_workspace.test.ts used vi.mock('../routing/session-key')
- This resolves to /routing/session-key (wrong - goes up from test/, not found)
- Should be vi.mock('../src/routing/session-key') (correct path from test/)
Solution:
- Updated regex pattern to match both jest.mock() and vi.mock()
- Function now fixes relative paths for both test frameworks
- Added unit tests to verify both jest and vitest paths are corrected
Trace ID: 265059d4-f518-44da-8367-d90ca424092c
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Claude finished @mohammedahmed18's task in 2m 12s —— View job PR Review SummaryTriageSMALL — 7 lines of production code changed in Prek ChecksPassed. No issues. Code Review1. Function name not updated ( The function is still named 2. Weak/redundant assertion in new tests ( assert "../src/routing/session-key" in fixed # ← correct
assert "../routing/session-key" not in fixed or "../src/routing/session-key" in fixed # ← always true if line above passesThe second assertion is always satisfied when the first passes because 3. Tests placed in wrong file New tests added to Duplicate DetectionNo duplicates detected. The regex change is surgical and the existing Core ChangeThe regex fix itself ( Last updated: 2026-04-03 |
Problem
Generated vitest tests fail with module not found errors:
Root Cause
The existing
fix_jest_mock_paths()function only fixedjest.mock()calls but notvi.mock()calls.When source code at
src/agents/workspace.tsimports:The generated test at
test/test_workspace.test.tshad:Should be:
The regex pattern only matched
jest.mock()andjest.doMock(), missingvi.mock().Solution
vi.mock()in addition to jest patternsBefore:
After:
Testing
Added comprehensive unit tests:
test_fix_vitest_mock_paths()- Verifies vi.mock() paths are correctedtest_fix_jest_mock_paths_still_works()- Ensures jest.mock() still worksBoth tests pass:
Affected Trace
265059d4-f518-44da-8367-d90ca424092c🤖 Co-Authored-By: Claude Sonnet 4.5