前端测试基建: 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。
This commit is contained in:
yml
2026-06-14 18:13:06 +08:00
parent 8fef037be3
commit 965832c3cb
4 changed files with 563 additions and 3 deletions
+4 -1
View File
@@ -13,7 +13,9 @@
"lint:fix": "eslint . --fix",
"format": "prettier --write .",
"format:check": "prettier --check .",
"check": "npm run format:check && npm run lint:strict && npm run typecheck"
"check": "npm run format:check && npm run lint:strict && npm run typecheck",
"test": "vitest run",
"test:watch": "vitest"
},
"dependencies": {
"@element-plus/icons-vue": "^2.3.1",
@@ -36,6 +38,7 @@
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-vue": "^10.9.2",
"globals": "^17.6.0",
"jsdom": "^29.1.1",
"prettier": "^3.8.3",
"typescript": "~5.9.3",
"typescript-eslint": "^8.60.1",