From 7d1bb9885fff1e2ca7ff53aa6fdb5f621ebddf09 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 13 Aug 2025 15:19:07 -0700 Subject: [PATCH] chore: remove jest --- .../continue-sdk-cli-and-hub-context.yaml | 2 +- .npmignore | 2 +- .vscode/launch.json | 10 +-- AGENTS.md | 6 +- eslint.config.js | 1 - jest.config.mjs | 78 ------------------- jest.resolver.cjs | 53 ------------- jest.resolver.js | 31 -------- jest.setup.ts | 42 ---------- spec/testing-strategies.md | 14 ++-- src/slashCommands.modes.test.ts | 2 +- src/test-helpers/ui-test-context.ts | 3 - src/tools/runTerminalCommand.test.ts | 8 +- src/ui/TUIChat.test.tsx | 2 +- src/ui/__tests__/TUIChat.dualModeHelper.tsx | 2 +- src/ui/__tests__/TUIChat.setup.ts | 2 +- src/ui/__tests__/TUIChat.testHelper.ts | 2 +- src/ui/__tests__/mockRemoteServer.ts | 2 +- 18 files changed, 26 insertions(+), 236 deletions(-) delete mode 100644 jest.config.mjs delete mode 100644 jest.resolver.cjs delete mode 100644 jest.resolver.js delete mode 100644 jest.setup.ts diff --git a/.continue/rules/continue-sdk-cli-and-hub-context.yaml b/.continue/rules/continue-sdk-cli-and-hub-context.yaml index 3041db0be..a71e68275 100644 --- a/.continue/rules/continue-sdk-cli-and-hub-context.yaml +++ b/.continue/rules/continue-sdk-cli-and-hub-context.yaml @@ -29,7 +29,7 @@ rules: - readline-sync: Provides synchronous CLI user interactions - - Jest: Used for testing framework + - Vitest: Used for testing framework All code should follow established patterns for a Node.js CLI tool diff --git a/.npmignore b/.npmignore index bdce176fe..e65f2a02b 100644 --- a/.npmignore +++ b/.npmignore @@ -5,7 +5,7 @@ test .continue .releaserc.json AGENTS.md -jest.config.mjs +vitest.config.ts tsconfig.json tsconfig.build.json TESTING_STRATEGY.md diff --git a/.vscode/launch.json b/.vscode/launch.json index 884a92f91..07d82ce2a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -24,16 +24,14 @@ ], "preLaunchTask": "watch-logs" }, - - { + { "name": "Debug Tests", "type": "node", "request": "launch", - "program": "${workspaceFolder}/node_modules/.bin/jest", - "args": ["--runInBand", "--no-cache"], + "program": "${workspaceFolder}/node_modules/.bin/vitest", + "args": ["--run", "--no-cache"], "env": { - "NODE_ENV": "test", - "NODE_OPTIONS": "--experimental-vm-modules" + "NODE_ENV": "test" }, "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", diff --git a/AGENTS.md b/AGENTS.md index 577362695..bfe1f0d39 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -5,7 +5,7 @@ This file provides guidance to AI coding agents when working with code in this r ## Development Commands - **Build**: `npm run build` - Compiles TypeScript to JavaScript in dist/ -- **Test**: `npm test` - Runs Jest tests with ESM support +- **Test**: `npm test` - Runs Vitest tests with ESM support - **Type Check**: `npm run lint` - Runs TypeScript compiler without emitting files for type checking - **Format**: `npm run format` - Runs Prettier with --write flag to check + fix formatting - **Start**: `npm start` - Runs the built CLI from dist/index.js @@ -54,8 +54,8 @@ This is a CLI tool for Continue Dev that provides an interactive AI-assisted dev ### Testing Setup -- Uses Jest with TypeScript and ESM support -- Configuration in `jest.config.mjs` +- Uses Vitest with TypeScript and ESM support +- Configuration in `vitest.config.ts` - Tests should be written with `.test.ts` extension - No existing test files found - tests should be added when writing new functionality - Run tests using `npm run test path/or/pattern` diff --git a/eslint.config.js b/eslint.config.js index 1481e9d99..f632d8e68 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -178,7 +178,6 @@ export default [ "coverage/**", "*.d.ts", "src/__mocks__/**", - "jest.setup.ts", "vitest.config.ts", "*.config.js", "*.config.ts", diff --git a/jest.config.mjs b/jest.config.mjs deleted file mode 100644 index 4fe2dc338..000000000 --- a/jest.config.mjs +++ /dev/null @@ -1,78 +0,0 @@ -import path from "path"; -import { fileURLToPath } from "url"; - -export default { - transform: { - "\\.[jt]sx?$": ["ts-jest", { useESM: true }], - }, - - moduleNameMapper: { - "^(\\.{1,2}/.+)\\.js$": "$1", - "^highlight\\.js/lib/languages/(.+)$": - "/src/ui/__mocks__/highlightLanguage.js", - "^lowlight$": "/src/ui/__mocks__/lowlight.js", - "^ink-testing-library$": - "/node_modules/ink-testing-library/build/index.js", - "^./SyntaxHighlighter\\.js$": - "/src/ui/__mocks__/SyntaxHighlighter.ts", - "^./FreeTrialStatus\\.js$": - "/src/ui/__mocks__/FreeTrialStatus.tsx", - }, - extensionsToTreatAsEsm: [".ts", ".tsx"], - preset: "ts-jest/presets/default-esm", - testTimeout: 10000, - testEnvironment: "node", - testPathIgnorePatterns: ["/dist/"], - modulePathIgnorePatterns: ["/dist/"], - transformIgnorePatterns: ["node_modules/(?!(highlight.js|lowlight)/)"], - setupFilesAfterEnv: ["/jest.setup.ts"], - globals: { - __dirname: path.dirname(fileURLToPath(import.meta.url)), - __filename: path.resolve(fileURLToPath(import.meta.url)), - }, - resolver: "/jest.resolver.cjs", - // Force E2E tests to run sequentially to avoid console override conflicts - projects: [ - { - displayName: "e2e", - testMatch: ["/src/e2e/**/*.test.ts"], - maxWorkers: 1, - transform: { - "\\.[jt]sx?$": ["ts-jest", { useESM: true }], - }, - moduleNameMapper: { - "^(\\.{1,2}/.+)\\.js$": "$1", - }, - extensionsToTreatAsEsm: [".ts", ".tsx"], - preset: "ts-jest/presets/default-esm", - testEnvironment: "node", - setupFilesAfterEnv: ["/jest.setup.ts"], - resolver: "/jest.resolver.cjs", - }, - { - displayName: "unit", - testMatch: ["/src/**/*.test.{ts,tsx}"], - testPathIgnorePatterns: ["/src/e2e/"], - transform: { - "\\.[jt]sx?$": ["ts-jest", { useESM: true }], - }, - moduleNameMapper: { - "^(\\.{1,2}/.+)\\.js$": "$1", - "^highlight\\.js/lib/languages/(.+)$": - "/src/ui/__mocks__/highlightLanguage.js", - "^lowlight$": "/src/ui/__mocks__/lowlight.js", - "^ink-testing-library$": - "/node_modules/ink-testing-library/build/index.js", - "^./SyntaxHighlighter\\.js$": - "/src/ui/__mocks__/SyntaxHighlighter.ts", - "^./FreeTrialStatus\\.js$": - "/src/ui/__mocks__/FreeTrialStatus.tsx", - }, - extensionsToTreatAsEsm: [".ts", ".tsx"], - preset: "ts-jest/presets/default-esm", - testEnvironment: "node", - setupFilesAfterEnv: ["/jest.setup.ts"], - resolver: "/jest.resolver.cjs", - }, - ], -}; diff --git a/jest.resolver.cjs b/jest.resolver.cjs deleted file mode 100644 index ac9db7768..000000000 --- a/jest.resolver.cjs +++ /dev/null @@ -1,53 +0,0 @@ -// Custom resolver for Jest to handle .js extensions in ESM project -const path = require("path"); -const fs = require("fs"); - -module.exports = (request, options) => { - // Call the default resolver - const defaultResolver = options.defaultResolver; - - // First try the default resolver - try { - return defaultResolver(request, options); - } catch (e) { - // Only continue if module not found - if (!e.message || !e.message.includes("Cannot find module")) { - throw e; - } - } - - // Handle relative imports - if (request.startsWith(".")) { - const basePath = options.basedir; - const fullPath = path.resolve(basePath, request); - - // Try various extensions - const extensions = ["", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]; - - for (const ext of extensions) { - const testPath = fullPath + ext; - try { - if (fs.existsSync(testPath)) { - return defaultResolver(testPath, options); - } - } catch (e) { - // Continue to next extension - } - } - - // Also try adding /index with various extensions - for (const ext of extensions) { - const testPath = path.join(fullPath, "index" + ext); - try { - if (fs.existsSync(testPath)) { - return defaultResolver(testPath, options); - } - } catch (e) { - // Continue to next extension - } - } - } - - // If still not found, throw original error - throw new Error(`Cannot find module '${request}'`); -}; diff --git a/jest.resolver.js b/jest.resolver.js deleted file mode 100644 index 1e053f75d..000000000 --- a/jest.resolver.js +++ /dev/null @@ -1,31 +0,0 @@ -module.exports = (path, options) => { - // Call the default resolver - const resolver = options.defaultResolver; - - try { - // Try to resolve the path as-is first - return resolver(path, options); - } catch (error) { - // If the path ends with .js and resolution fails, try without the extension - if (path.endsWith(".js")) { - const pathWithoutJs = path.slice(0, -3); - try { - return resolver(pathWithoutJs, options); - } catch { - // If that also fails, try with .ts extension - try { - return resolver(pathWithoutJs + ".ts", options); - } catch { - // If that also fails, try with .tsx extension - try { - return resolver(pathWithoutJs + ".tsx", options); - } catch { - // If all attempts fail, throw the original error - throw error; - } - } - } - } - throw error; - } -}; diff --git a/jest.setup.ts b/jest.setup.ts deleted file mode 100644 index 64ae4e9ad..000000000 --- a/jest.setup.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { jest } from "@jest/globals"; -import { resetConsoleOverrides } from "./src/util/consoleOverride.js"; - -// Disable telemetry for tests -process.env.CONTINUE_CLI_ENABLE_TELEMETRY = "0"; - -// Mock the 'open' package to prevent browser opening during tests -jest.mock("open", () => jest.fn().mockResolvedValue(undefined)); - -// Mock common modules that cause issues -jest.mock("./src/logging.js"); -jest.mock("./src/util/logger.js"); -jest.mock("./src/hooks/useService.js"); -jest.mock("./src/auth/workos.js"); -jest.mock("./src/commands/commands.js"); -jest.mock("./src/services/index.js"); -jest.mock("./src/services/ServiceContainerContext.js"); -jest.mock("./src/config.js"); -jest.mock("./src/configLoader.js"); -jest.mock("./src/args.js"); -jest.mock("./src/services/ServiceContainer.js"); -jest.mock("./src/permissions/permissionsYamlLoader.js"); -jest.mock("./src/permissions/precedenceResolver.js"); - -// Set up global afterEach hook to clear all timers and reset console -afterEach(() => { - // Clear jest timers only if they're available - if (typeof jest !== "undefined" && jest.clearAllTimers) { - try { - jest.clearAllTimers(); - } catch (e) { - // Ignore errors when clearing timers - } - } - - // Reset console overrides to ensure clean state for each test - try { - resetConsoleOverrides(); - } catch (e) { - // Ignore errors when resetting console - } -}); diff --git a/spec/testing-strategies.md b/spec/testing-strategies.md index 39f7ab16f..b0a390e5e 100644 --- a/spec/testing-strategies.md +++ b/spec/testing-strategies.md @@ -15,7 +15,7 @@ This document provides an overview of the different testing strategies used in t - Testing business logic components - Testing error handling and edge cases -**Framework**: Jest with TypeScript support +**Framework**: Vitest with TypeScript support **Examples**: @@ -54,7 +54,7 @@ This document provides an overview of the different testing strategies used in t - Testing component state changes - Testing message display and formatting -**Framework**: Jest + Ink Testing Library + React Testing utilities +**Framework**: Vitest + Ink Testing Library + React Testing utilities **Examples**: @@ -112,7 +112,7 @@ This document provides an overview of the different testing strategies used in t ## Configuration -**Jest Configuration**: [`jest.config.mjs`](../jest.config.mjs) +**Vitest Configuration**: [`vitest.config.ts`](../vitest.config.ts) - TypeScript support with ES modules - React/Ink component testing setup @@ -125,14 +125,14 @@ This document provides an overview of the different testing strategies used in t # Run all tests with linting npm test -# Run tests in watch mode (Jest only) -npx jest --watch +# Run tests in watch mode +npx vitest --watch # Run specific test file -npx jest src/util/formatError.test.ts +npx vitest src/util/formatError.test.ts # Run tests with coverage -npx jest --coverage +npx vitest --coverage ``` ## Best Practices diff --git a/src/slashCommands.modes.test.ts b/src/slashCommands.modes.test.ts index c791ef1da..c6f227f4c 100644 --- a/src/slashCommands.modes.test.ts +++ b/src/slashCommands.modes.test.ts @@ -1,5 +1,5 @@ // Mode-related slash commands have been removed per user request -// This test file is no longer needed but needs a dummy test for Jest +// This test file is no longer needed but needs a dummy test for Vitest import { describe, it, expect } from 'vitest'; diff --git a/src/test-helpers/ui-test-context.ts b/src/test-helpers/ui-test-context.ts index 092f16098..8b979d13d 100644 --- a/src/test-helpers/ui-test-context.ts +++ b/src/test-helpers/ui-test-context.ts @@ -78,9 +78,6 @@ export function createUITestContext( setMaxListeners: vi.fn(), }; - // Note: Jest mocks need to be hoisted, so they can't be called inside functions - // The actual mocking should be done at the top of test files - const cleanup = () => { vi.clearAllMocks(); }; diff --git a/src/tools/runTerminalCommand.test.ts b/src/tools/runTerminalCommand.test.ts index 7b037c802..30a0d8557 100644 --- a/src/tools/runTerminalCommand.test.ts +++ b/src/tools/runTerminalCommand.test.ts @@ -78,7 +78,7 @@ describe("runTerminalCommandTool", () => { expect(elapsed).toBeLessThan(TEST_TIMEOUT_MS + 200); // Allow 200ms margin expect(elapsed).toBeGreaterThan(TEST_TIMEOUT_MS - 100); // Allow 100ms margin expect(result).toContain(`[Command timed out after ${TEST_TIMEOUT_MS / 1000} seconds of no output]`); - }, TEST_TIMEOUT_MS + 2000); // Set Jest timeout with buffer + }, TEST_TIMEOUT_MS + 2000); // Set test timeout with buffer it("should not timeout commands that continuously produce output", async () => { // Create a command that produces output at intervals shorter than timeout @@ -95,7 +95,7 @@ describe("runTerminalCommandTool", () => { expect(result).toContain("output 1"); expect(result).toContain(`output ${iterations}`); expect(result).not.toContain("[Command timed out"); - }, TEST_TIMEOUT_MS * 3); // Set Jest timeout with buffer + }, TEST_TIMEOUT_MS * 3); // Set test timeout with buffer it("should reset timeout when command produces stderr output", async () => { // Create a command that produces stderr output periodically @@ -112,7 +112,7 @@ describe("runTerminalCommandTool", () => { expect(result).toContain("done"); expect(result).toContain("Stderr: error 1"); expect(result).not.toContain("[Command timed out"); - }, TEST_TIMEOUT_MS * 3); // Set Jest timeout with buffer + }, TEST_TIMEOUT_MS * 3); // Set test timeout with buffer it("should include partial output when timing out", async () => { // Create a command that produces some output then stops @@ -123,7 +123,7 @@ describe("runTerminalCommandTool", () => { expect(result).toContain("initial output"); expect(result).toContain(`[Command timed out after ${TEST_TIMEOUT_MS / 1000} seconds of no output]`); - }, TEST_TIMEOUT_MS + 2000); // Set Jest timeout with buffer + }, TEST_TIMEOUT_MS + 2000); // Set test timeout with buffer }); describe("output handling", () => { diff --git a/src/ui/TUIChat.test.tsx b/src/ui/TUIChat.test.tsx index a30b2f3dc..ba4ca2b3b 100644 --- a/src/ui/TUIChat.test.tsx +++ b/src/ui/TUIChat.test.tsx @@ -5,7 +5,7 @@ import "./__tests__/TUIChat.input.test.js"; import "./__tests__/TUIChat.fileSearch.test.js"; import "./__tests__/TUIChat.slashCommands.test.js"; -// Add a dummy test to satisfy Jest +// Add a dummy test to satisfy Vitest describe("TUIChat Test Suite", () => { it("should import all test modules", () => { expect(true).toBe(true); diff --git a/src/ui/__tests__/TUIChat.dualModeHelper.tsx b/src/ui/__tests__/TUIChat.dualModeHelper.tsx index 3b5021ab0..a62b235e8 100644 --- a/src/ui/__tests__/TUIChat.dualModeHelper.tsx +++ b/src/ui/__tests__/TUIChat.dualModeHelper.tsx @@ -6,7 +6,7 @@ import { AppRoot } from "../AppRoot.js"; export type TestMode = "local" | "remote"; -// Dummy test to satisfy Jest +// Dummy test to satisfy Vitest describe("TUIChat dual mode helper", () => { it("exports helper functions", () => { expect(testBothModes).toBeDefined(); diff --git a/src/ui/__tests__/TUIChat.setup.ts b/src/ui/__tests__/TUIChat.setup.ts index 6ac658ad3..dcb9678a0 100644 --- a/src/ui/__tests__/TUIChat.setup.ts +++ b/src/ui/__tests__/TUIChat.setup.ts @@ -54,7 +54,7 @@ export const createProps = (overrides: any = {}) => ({ ...overrides, }); -// Add a dummy test to satisfy Jest requirement +// Add a dummy test to satisfy Vitest requirement describe("TUIChat setup", () => { test("setup should export required functions", () => { expect(createProps).toBeDefined(); diff --git a/src/ui/__tests__/TUIChat.testHelper.ts b/src/ui/__tests__/TUIChat.testHelper.ts index 2c2cc1e3b..8a0fd9289 100644 --- a/src/ui/__tests__/TUIChat.testHelper.ts +++ b/src/ui/__tests__/TUIChat.testHelper.ts @@ -54,7 +54,7 @@ export function runTest( modes.forEach((testMode) => { describe(`[${testMode.toUpperCase()} MODE]`, () => { it(name, async () => { - // Import mocks from Jest setup + // Import mocks from Vitest setup const { useServices, useService } = await import( "../../hooks/useService.js" ); diff --git a/src/ui/__tests__/mockRemoteServer.ts b/src/ui/__tests__/mockRemoteServer.ts index 3831b75eb..fef90966c 100644 --- a/src/ui/__tests__/mockRemoteServer.ts +++ b/src/ui/__tests__/mockRemoteServer.ts @@ -159,7 +159,7 @@ export class MockRemoteServer { } } -// Add a dummy test to satisfy Jest requirement +// Add a dummy test to satisfy Vitest requirement describe("MockRemoteServer", () => { test("should be defined", () => { expect(MockRemoteServer).toBeDefined();