Files
yml 965832c3cb 前端测试基建: vitest.config + jsdom + test script, 3 个死 spec 复活
现状: vitest 已装, 3 个 spec 已存在 (listings composables, 14 用例), 但跑不起来——package.json 无 test script, 无 vitest.config, @/ 别名在测试环境不通 (Cannot find package '@/...')。

修复:
- 新增 vitest.config.ts: jsdom 环境 (提供 window/document/navigator, 让 monitor.ts 等浏览器模块可加载) + @ 别名 (与 vite.config.ts 同口径) + globals + v8 coverage 配置
- package.json 加 test / test:watch / test:coverage script
- 装 jsdom devDependency
- check.sh 前端门禁加 npm run test 步骤 (受 --skip-tests 控制, 与后端测试一致)

验证: npm run test 3 spec 全过 (14 用例); check.sh --skip-backend 全绿 (check + test + build)。

之前 "有测试实际跑不起来" 的债务清掉。后续 composable/api 层测试可直接 npm run test。
2026-06-14 18:13:06 +08:00

20 lines
697 B
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 { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vitest/config'
// Vitest 配置:独立于 vite.config.ts,仅配置测试所需。
// - environment: jsdom 提供 window/document/navigator,支持引用浏览器全局的模块(如 monitor.ts
// - alias: 与 vite.config.ts 保持一致,让 @/ 别名在测试中可用
// - globals: 让 describe/it/expect 全局可用(与现有 spec 的 import 风格兼容,不强制)
export default defineConfig({
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
test: {
environment: 'jsdom',
globals: true,
include: ['src/**/*.{spec,test}.ts'],
},
})