56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
// Vitest 配置
|
||
// 依据:02-architecture-design.md §13 测试策略分层
|
||
import { defineConfig } from "vitest/config";
|
||
import react from "@vitejs/plugin-react";
|
||
import { resolve } from "node:path";
|
||
|
||
export default defineConfig({
|
||
plugins: [react()],
|
||
resolve: {
|
||
alias: {
|
||
"@": resolve(__dirname, "./src"),
|
||
},
|
||
},
|
||
test: {
|
||
environment: "jsdom",
|
||
globals: true,
|
||
setupFiles: ["./src/test/setup.ts"],
|
||
include: [
|
||
"src/**/*.{test,spec}.{ts,tsx}",
|
||
"src/**/__tests__/**/*.{ts,tsx}",
|
||
],
|
||
exclude: ["node_modules", ".next", "e2e"],
|
||
coverage: {
|
||
provider: "v8",
|
||
reporter: ["text", "json", "html"],
|
||
include: ["src/**/*.{ts,tsx}"],
|
||
exclude: [
|
||
"src/**/*.d.ts",
|
||
"src/test/**",
|
||
"src/mocks/**",
|
||
"src/types/**",
|
||
"src/**/*.config.{ts,tsx}",
|
||
// Next.js App Router pages:由 MSW 集成测试 + E2e 覆盖,不纳入单元测试覆盖率
|
||
"src/app/**/page.tsx",
|
||
"src/app/**/layout.tsx",
|
||
"src/app/**/providers.tsx",
|
||
"src/app/**/error.tsx",
|
||
"src/app/**/loading.tsx",
|
||
"src/app/**/not-found.tsx",
|
||
"src/app/api/**",
|
||
// 可观测性 optional modules:依赖 optionalDependencies(@opentelemetry/*、web-vitals、axe-core)
|
||
// 这些模块用 dynamic import 在运行时按需加载,单元测试不覆盖
|
||
"src/lib/observability/**",
|
||
// ErrorBoundary:React 渲染异常兜底,需 React Error Boundary 测试 harness
|
||
"src/lib/error-boundary.tsx",
|
||
],
|
||
thresholds: {
|
||
statements: 85,
|
||
branches: 75,
|
||
functions: 85,
|
||
lines: 85,
|
||
},
|
||
},
|
||
},
|
||
});
|