Files
wrong-notebook/vitest.config.mts
margrop 895c64575a perf(test): 将 Vitest 默认环境改为 node,仅 DOM 测试启用 jsdom
- 纯服务端测试不再逐个初始化 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
2026-12-04 17:35:54 +08:00

36 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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,
},
},
},
})