Skip to content

Commit 9d31a34

Browse files
committed
Migrate test runner from ts-jest to Vitest
Closes #629. Switches the test pipeline from `ts-jest`/Jest to Vitest so the test toolchain aligns with the esbuild-based production build, drops the `TS5107` workaround we needed in `tsconfig.test.json`, and unblocks the TypeScript 7 upgrade (which removes `node10` resolution). - Replace `ts-jest`, `jest`, `jest-environment-jsdom`, `@types/jest` with `vitest`, `@vitest/coverage-v8`, `@vitest/ui`, and `jsdom`. - Add `vitest.config.ts` with jsdom env, path/module aliases that mirror the old `moduleNameMapper`, and a small Vite plugin that loads `.hbs`/`.md`/`.txt` as raw text (replacement for `text-transformer.mjs`). - Rewrite `test/**` and `__mocks__/**` from `jest.fn`/`jest.mock`/ `jest.requireActual`/etc. to their `vi` equivalents. Constructor mocks use `function`/class syntax so vitest 4.x can call them with `new`. - Convert mock modules in `__mocks__/` to ESM and import `vi` from `vitest`. - Use `vi.hoisted()` in `mcp-manager.test.ts` for uppercase mock identifiers vitest's auto-hoist heuristic doesn't recognize. - Replace `require('../models')` in `src/services/model-manager.ts` with `import * as modelsModule from '../models'` (live binding) so the file works under Vite's ESM loader without changing behavior. - Update tsconfig.test.json: `types: ['vitest/globals', 'node']` and drop `ignoreDeprecations: '6.0'`. - `npm test` now runs `vitest run`; `npm run test:watch` runs the watcher. CI's existing `npm test -- --coverage` keeps working because vitest accepts `--coverage`. Docs: AGENTS.md and docs/contributing/tool-development.md now reference Vitest/`vi.fn()`. https://claude.ai/code/session_016L3CBfrG11AHHTRegiW89N
1 parent b792af6 commit 9d31a34

70 files changed

Lines changed: 2910 additions & 5121 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ if (this.plugin.settings.debugMode) {
207207

208208
## Testing Guidelines
209209

210-
- Jest with ts-jest for TypeScript support
211-
- JSDOM environment for DOM testing
212-
- Test pattern: `**/?(*.)+(spec|test).[tj]s`
210+
- Vitest (esbuild-powered) for TypeScript support
211+
- jsdom environment for DOM testing
212+
- Test pattern: `test/**/?(*.)+(spec|test).[tj]s`
213213
- Keep unit tests next to implementations and name them after the unit (`models.test.ts`, `main.test.ts`)
214214
- Assert observable behavior of prompts, services, and tool orchestration; add regression coverage for bugs
215215
- Extend shared fixtures under `__mocks__/` when mocking new APIs

__mocks__/@google/genai.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
// Mock for @google/genai
2+
import { vi } from 'vitest';
23

3-
const GoogleGenAI = jest.fn().mockImplementation(() => ({
4-
models: {
5-
generateContent: jest.fn().mockResolvedValue({
6-
response: {
7-
text: () => 'Mock response text',
8-
candidates: [
9-
{
10-
groundingMetadata: {
11-
webSearchQueries: ['test query'],
12-
groundingAttributions: [
13-
{
14-
uri: 'https://example.com',
15-
content: 'Mock content',
16-
},
17-
],
4+
export const GoogleGenAI = vi.fn().mockImplementation(function () {
5+
return {
6+
models: {
7+
generateContent: vi.fn().mockResolvedValue({
8+
response: {
9+
text: () => 'Mock response text',
10+
candidates: [
11+
{
12+
groundingMetadata: {
13+
webSearchQueries: ['test query'],
14+
groundingAttributions: [
15+
{
16+
uri: 'https://example.com',
17+
content: 'Mock content',
18+
},
19+
],
20+
},
1821
},
19-
},
20-
],
21-
},
22-
}),
23-
},
24-
}));
25-
26-
module.exports = {
27-
GoogleGenAI,
28-
};
22+
],
23+
},
24+
}),
25+
},
26+
};
27+
});

__mocks__/@google/generative-ai.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
// Mock for @google/generative-ai
2+
import { vi } from 'vitest';
23

3-
const GoogleGenerativeAI = jest.fn().mockImplementation(() => ({
4-
getGenerativeModel: jest.fn().mockReturnValue({
5-
generateContent: jest.fn().mockResolvedValue({
6-
response: {
7-
text: () => 'Mock response text',
8-
candidates: [
9-
{
10-
groundingMetadata: {
11-
webSearchQueries: ['test query'],
12-
groundingAttributions: [
13-
{
14-
uri: 'https://example.com',
15-
content: 'Mock content',
16-
},
17-
],
4+
export const GoogleGenerativeAI = vi.fn().mockImplementation(function () {
5+
return {
6+
getGenerativeModel: vi.fn().mockReturnValue({
7+
generateContent: vi.fn().mockResolvedValue({
8+
response: {
9+
text: () => 'Mock response text',
10+
candidates: [
11+
{
12+
groundingMetadata: {
13+
webSearchQueries: ['test query'],
14+
groundingAttributions: [
15+
{
16+
uri: 'https://example.com',
17+
content: 'Mock content',
18+
},
19+
],
20+
},
1821
},
19-
},
20-
],
21-
},
22+
],
23+
},
24+
}),
2225
}),
23-
}),
24-
}));
25-
26-
module.exports = {
27-
GoogleGenerativeAI,
28-
};
26+
};
27+
});

0 commit comments

Comments
 (0)