Files
writer-work-flow/apps/web/vitest.config.ts
Yaojia Wang a6f5d085e5 test: 接入 jsdom 测试栈, 把 15 个 React hooks 纳入 80% 覆盖率门禁
新增 jsdom + @testing-library/react, 为 lib/** 全部 use*.ts hooks 写 renderHook 单测:
生成/CRUD(world/character/generator/outline/accept/foreshadow/rules)、
SSE流(draftStream/reviewStream)、定时轮询(autosave/jobPoll/kimiOauth)、
文风与注入(refine/styleLearn/injection)。覆盖率 mock api 客户端+Toast, 不打真实 LLM。
vitest.config.ts 去掉 use*.ts 排除; 前端覆盖率 63%→95%。CLAUDE.md 同步说明。
2026-06-27 06:21:42 +02:00

31 lines
1.0 KiB
TypeScript
Raw Permalink 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 { resolve } from "node:path";
import { defineConfig } from "vitest/config";
// 单测纯逻辑SSE reducer / 自动保存防抖 / 向导流程node 环境,无需 DOM。
export default defineConfig({
resolve: {
alias: { "@": resolve(__dirname, ".") },
},
test: {
environment: "node",
include: ["lib/**/*.test.ts"],
coverage: {
provider: "v8",
// 覆盖范围 = lib/** 全部逻辑层(纯逻辑 + React hooks
// hooks(use*.ts) 用 jsdom + @testing-library/react 的 renderHook 单测(见各 *.test.ts 的
// `// @vitest-environment jsdom` 头)。组件(.tsx)仍由 E2E/人工验收覆盖,不在 vitest 范围。
// 排除项测试文件本身、OpenAPI codegen 生成物。
include: ["lib/**/*.ts"],
exclude: ["lib/**/*.test.ts", "lib/api/schema.d.ts"],
reporter: ["text", "text-summary"],
thresholds: {
lines: 80,
functions: 80,
branches: 80,
statements: 80,
},
},
},
});