fix: 修复 Vitest 4.x 构建兼容性问题
environmentMatchGlobs 在 Vitest 4 中已移除,改用 projects 配置; 排除 vitest.config.ts 不参与 Next.js 类型检查。
This commit is contained in:
+1
-1
@@ -30,5 +30,5 @@
|
||||
".next/dev/types/**/*.ts",
|
||||
"**/*.mts"
|
||||
],
|
||||
"exclude": ["node_modules"]
|
||||
"exclude": ["node_modules", "vitest.config.ts"]
|
||||
}
|
||||
|
||||
+30
-10
@@ -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",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user