Files
cms-website/vitest.config.ts
T
浅念 f1c181de02 test(db): 空库一键迁移验收 + globalSetup 临时库 + 公共夹具收敛(阶段1验收)
- vitest globalSetup:每次运行 CREATE sf_test_<ts> 临时库 → drizzle-orm 程序化迁移器
  全量迁移(apps/api/src/db/migrate.ts,drizzle-kit 无法指向运行时建库)→ 设
  DATABASE_URL_TEST 让 getDb() 自动回退到临时库;teardown DROP(WITH FORCE)。
  有 default 导出时 vitest 不捕获具名 teardown,故用双具名导出。
- db.full-migrate.test.ts:21 表齐 + 四张不可变触发器在库 + sf_test_* 护栏断言
  (current_database 不符即红,杜绝静默连开发库)。
- helpers.ts 收敛:rand/rejectionMessage/createSiteFixture/withImmutableCleanup/
  withTestDb,Task 6–12 七文件内联版替换为 import(断言、对照组、清场顺序不变)。
- scripts/migrate-test.sh:docker compose up --wait + pnpm test 一键验收。
- 实证:75 测试全绿(72+3);开发库 21 表行数总和 0(零写入);无 sf_test_* 残留。

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-20 20:43:13 +08:00

16 lines
928 B
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'
export default defineConfig({
test: {
include: ['tests/**/*.test.ts', 'packages/*/test/**/*.test.ts', 'apps/*/test/**/*.test.ts'],
// 集成测试库供给(Task 13):setup 建 sf_test_<ts> 临时库并全量迁移,
// 设 DATABASE_URL_TEST 让所有 getDb() 自动指过去;teardown 负责 DROP。
globalSetup: ['tests/integration/global-setup.ts'],
testTimeout: 30000,
// 集成测试共库且清场会做全局态变更(不可变表 DISABLE/ENABLE TRIGGER 是库级 DDL,
// 对所有会话可见):文件级并行时 A 文件清场窗口会与 B 文件的不可变断言竞态(实测
// db.media 清场 disable content_revisions_immutable 期间,db.content 恰好断言该触发器
// → UPDATE 意外放行)。串行执行文件消除该竞态;套件仅数秒,并行无收益。
fileParallelism: false,
},
})