From bf0a60bc0af8a8cfbc99ab5b4cb62b53577c1663 Mon Sep 17 00:00:00 2001 From: Michal Date: Sun, 26 Apr 2026 21:31:27 +0100 Subject: [PATCH] fix(test): switch workspace runner to vitest 4 \`projects\` field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The workspace-level \`pnpm test:run\` (which fulldeploy.sh runs as a gate) was failing with \`localStorage is not defined\` on the new src/web tests. Two intertwined causes: 1. vitest 4 deprecated \`vitest.workspace.ts\`. The file was being silently ignored, so per-package configs (cli, mcpd, mcplocal) weren't being honored under workspace mode either — the root config was being used for all of them. 2. With the root config in charge, src/web/tests ran with the default Node environment, no \`localStorage\` global, so the api wrapper's test setup blew up. Fix: - Move workspace projects into the root \`vitest.config.ts\` under the new \`projects\` array (the vitest 4 replacement). - Add a proper \`src/web/vitest.config.ts\` (vitest 4 doesn't auto-pick up vite.config.ts as a test config in workspace mode, even though per-package \`pnpm --filter\` does). - Exclude \`src/web/tests/**\` from the root-level include so we don't double-run them under the wrong env. After: \`pnpm test:run\` runs 1999/1999 across 149 files (was 1992/1996 with 4 web failures). Per-package runs unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/web/vite.config.ts | 1 + src/web/vitest.config.ts | 14 ++++++++++++++ vitest.config.ts | 14 +++++++++++++- vitest.workspace.ts | 4 ++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/web/vitest.config.ts diff --git a/src/web/vite.config.ts b/src/web/vite.config.ts index 9de9b3e..941a628 100644 --- a/src/web/vite.config.ts +++ b/src/web/vite.config.ts @@ -37,5 +37,6 @@ export default defineConfig({ environment: 'jsdom', globals: true, setupFiles: ['./tests/setup.ts'], + include: ['tests/**/*.test.{ts,tsx}'], }, }); diff --git a/src/web/vitest.config.ts b/src/web/vitest.config.ts new file mode 100644 index 0000000..6d8b16b --- /dev/null +++ b/src/web/vitest.config.ts @@ -0,0 +1,14 @@ +/// +import { defineProject } from 'vitest/config'; +import react from '@vitejs/plugin-react'; + +export default defineProject({ + plugins: [react()], + test: { + name: 'web', + include: ['tests/**/*.test.{ts,tsx}'], + environment: 'jsdom', + globals: true, + setupFiles: ['./tests/setup.ts'], + }, +}); diff --git a/vitest.config.ts b/vitest.config.ts index ee87406..a1c7953 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -9,8 +9,20 @@ export default defineConfig({ exclude: ['**/node_modules/**', '**/dist/**', '**/*.config.*'], }, include: ['src/*/tests/**/*.test.ts', 'tests/**/*.test.ts'], - exclude: ['**/node_modules/**', '**/smoke/**', 'src/db/tests/**'], + // src/web tests need jsdom; they're run via the web package's own + // vitest.config.ts under the projects entry below. + exclude: ['**/node_modules/**', '**/smoke/**', 'src/db/tests/**', 'src/web/tests/**'], testTimeout: 10000, + // Vitest 4 uses `projects` (in-config) instead of vitest.workspace.ts. + // Each project below is rooted in a workspace package; vitest reads + // its `vitest.config.ts` (or vite.config.ts) for the test config. + projects: [ + 'src/shared', + 'src/cli', + 'src/mcpd', + 'src/mcplocal', + 'src/web', + ], // DB tests require a test database; run them explicitly via: // pnpm --filter db exec vitest run // globalSetup: ['src/db/tests/global-setup.ts'], diff --git a/vitest.workspace.ts b/vitest.workspace.ts index 62873a7..aef3380 100644 --- a/vitest.workspace.ts +++ b/vitest.workspace.ts @@ -6,4 +6,8 @@ export default defineWorkspace([ 'src/cli', 'src/mcpd', 'src/mcplocal', + // src/web has its own vite.config.ts with `environment: 'jsdom'` — + // listing it here makes the workspace runner pick that up so the + // browser-y tests get the right globals (localStorage, document). + 'src/web', ]);