Convert close_older_issues.test.cjs from Jest to Vitest #10896
Merged
+10
−10
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.
The test file
close_older_issues.test.cjswas written using Jest syntax (@jest/globals,jest.fn(),jest.clearAllMocks()), causing CI failure with "Cannot find module '@jest/globals'". The codebase uses Vitest.Changes
require("@jest/globals")toimport { describe, it, expect, beforeEach, vi } from "vitest"require()to ES moduleimportstatementsjest.fn()→vi.fn()andjest.clearAllMocks()→vi.clearAllMocks()"Old Issue"but test expected it to start with"Prefix"(line 227)Before
After
All 12 tests in
close_older_issues.test.cjsnow pass.Original prompt
This section details on the original issue you should resolve
<issue_title>[CI Failure Doctor] CI Failure Doctor: close_older_issues.test.cjs uses Jest instead of Vitest</issue_title>
<issue_description>## Summary
The CI workflow failed on commit c1c6704 (PR #10882) because the newly added test file
close_older_issues.test.cjsuses Jest test framework syntax (@jest/globalsandjest.fn()) instead of the Vitest framework used throughout the codebase.Failure Details
js(JavaScript tests)Root Cause Analysis
Primary Error
Technical Details
The test file
close_older_issues.test.cjs(334 lines) uses Jest syntax patterns that are incompatible with Vitest:Incorrect imports (Line 3):
Incorrect mocking (Lines 8-10):
Incorrect module loading:
require()instead of ES modulesimportCorrect Patterns Used in Other Test Files
All existing test files use Vitest:
Additional Test Failures
The run also showed 42 other test failures, mostly in
collect_ndjson_output.test.cjsandsafe_outputs_mcp_server_defaults.test.cjs, but these appear to be pre-existing issues unrelated to this specific failure.Recommended Actions
Fix #1: Convert Test File to Vitest (Required)
Replace Jest syntax with Vitest in
close_older_issues.test.cjs:Changes needed:
Update imports (line 3):
Update module imports (line 4):
Update mocking (lines 8-10):
Update all mock functions (lines 18-28 and throughout):
Update beforeEach (line 17):
Fix #2: Run Local Tests Before Committing
Always run the full test suite locally:
This would have caught the error immediately.
Prevention Strategies
1. Add Pre-commit Validation
Update AGENTS.md to emphasize test validation:
Example - Correct test file structure: