diff --git a/tsconfig.json b/tsconfig.json index cf9c65d..11f74a2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -30,5 +30,5 @@ ".next/dev/types/**/*.ts", "**/*.mts" ], - "exclude": ["node_modules"] + "exclude": ["node_modules", "vitest.config.ts"] } diff --git a/vitest.config.ts b/vitest.config.ts index 6094f2a..09c011a 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -2,6 +2,15 @@ import { defineConfig } from "vitest/config"; import react from "@vitejs/plugin-react"; import path from "path"; +const shared = { + globals: true, + setupFiles: ["src/__tests__/helpers/setup.ts"], + env: { + AMAP_API_KEY: "test-amap-key", + DEEPSEEK_API_KEY: "test-deepseek-key", + }, +} as const; + export default defineConfig({ plugins: [react()], resolve: { @@ -10,16 +19,27 @@ export default defineConfig({ }, }, test: { - globals: true, - environment: "jsdom", - setupFiles: ["src/__tests__/helpers/setup.ts"], - environmentMatchGlobs: [ - ["src/app/api/**/*.test.ts", "node"], - ["src/lib/**/*.test.ts", "node"], + projects: [ + { + plugins: [react()], + resolve: { alias: { "@": path.resolve(__dirname, "src") } }, + test: { + ...shared, + name: "ui", + environment: "jsdom", + include: ["src/**/*.test.{ts,tsx}"], + exclude: ["src/app/api/**", "src/lib/**/*.test.ts"], + }, + }, + { + resolve: { alias: { "@": path.resolve(__dirname, "src") } }, + test: { + ...shared, + name: "api", + environment: "node", + include: ["src/app/api/**/*.test.ts", "src/lib/**/*.test.ts"], + }, + }, ], - env: { - AMAP_API_KEY: "test-amap-key", - DEEPSEEK_API_KEY: "test-deepseek-key", - }, }, });