mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-05 07:49:45 +08:00
- 纯服务端测试不再逐个初始化 jsdom,全量 352 个测试文件由约 122s 环境开销降至 80 个 jsdom 实例。 - 需要 DOM 的 80 个测试文件首行声明 // @vitest-environment jsdom,行为与断言不变。 - 全量 npm test、test:coverage、lint、tsc 均通过。 Refs: https://github.com/margrop/wrong-notebook/issues/98
36 lines
1.5 KiB
TypeScript
36 lines
1.5 KiB
TypeScript
import { defineConfig } from 'vitest/config'
|
||
import react from '@vitejs/plugin-react'
|
||
import { fileURLToPath } from 'node:url'
|
||
|
||
export default defineConfig({
|
||
plugins: [react()],
|
||
test: {
|
||
// 默认 node;需要 DOM 的测试在文件首行用 // @vitest-environment jsdom 声明,
|
||
// 避免纯服务端测试逐个初始化 jsdom(约占全量测试耗时的三分之一)。
|
||
environment: 'node',
|
||
globals: true,
|
||
setupFiles: ['./src/__tests__/setup.ts'],
|
||
alias: {
|
||
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||
'server-only': fileURLToPath(new URL('./src/__tests__/stubs/server-only.ts', import.meta.url)),
|
||
// 测试始终使用默认的 AI 账户实现,不受 AI_ACCOUNT_EXTENSION 影响
|
||
'@wrong-notebook/ai-account': fileURLToPath(new URL('./src/lib/ai/account-default.ts', import.meta.url)),
|
||
},
|
||
include: ['src/__tests__/**/*.test.ts', 'src/__tests__/**/*.test.tsx'],
|
||
exclude: ['node_modules', '.next', 'dist'],
|
||
coverage: {
|
||
provider: 'v8',
|
||
reporter: ['text', 'json', 'json-summary', 'html'],
|
||
include: ['src/lib/**/*.ts', 'src/app/api/**/*.ts'],
|
||
exclude: ['src/__tests__/**', 'node_modules/**'],
|
||
// 略低于当前覆盖率,防止覆盖率下降;补充测试后可逐步提高
|
||
thresholds: {
|
||
statements: 70,
|
||
branches: 65,
|
||
functions: 75,
|
||
lines: 70,
|
||
},
|
||
},
|
||
},
|
||
})
|