Files
lingxi/apps/api/vitest.int.config.ts
Stev_Wang b489cb3152
ci / 质量门禁 (push) Canceled after 0s
test(api): 修复集成测试对根部门顺序与文件并行的依赖
背景:
- pnpm ci:local 的 test:int 在本地真实 PG 上失败,与业务代码无关,是测试自身不稳定:
  1) identity 用例断言部门树第一项根部门必须有子级,但管理员可以新建无子级根部门
     并排在最前(本地已有手工部门「111」,sortOrder=0),该断言不成立;
  2) identity.int.spec 清理用 account startsWith('it.'),会误删 departments.int.spec
     的 it.dep.* 夹具;四个 int 文件默认并行且共用同一个真实 PG,beforeAll 偶发失败。

改动:
- identity.int.spec:部门树断言改为「存在带子级的根部门」,不再依赖根部门顺序;
- vitest.int.config:fileParallelism: false,集成测试文件串行执行,并注释原因。

影响面:
- 仅集成测试的断言与执行方式;业务代码、单测、构建不变;
- test:int 改为串行,耗时略增。

回滚方式:
- 回滚本提交即恢复原断言与并行执行。

验证证据:
- pnpm --filter @lingxi/api test:int 连续 3 次:4 个文件 / 33 项全通过;
- pnpm ci:local 第 1–8 步通过(第 10 步 e2e 为 A0 遗留问题,另行处理);
- pnpm format:check / lint / typecheck / test 通过。
2026-11-03 16:17:21 +08:00

14 lines
470 B
TypeScript

import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
environment: 'node',
include: ['src/**/*.int.spec.ts'],
testTimeout: 30_000,
hookTimeout: 30_000,
// 集成测试共用本地真实 PG / Redis,且各文件会清理带前缀的夹具(如 it.* 与 it.dep.* 重叠)。
// 文件级并行会让跨文件的夹具清理 / 数据断言互相干扰,因此串行执行。
fileParallelism: false,
},
});