test: 添加 vitest 测试基础设施

新增 vitest 配置、jsdom 环境与 jest-dom 匹配器,并在 package.json 中加入 test/test:watch 脚本与相关 devDependencies,为后续特征测试与子 hook 独立测试提供运行环境。
This commit is contained in:
oudecheng 2026-07-08 11:24:10 +08:00
parent 8c6737c999
commit f5ccf490ba
4 changed files with 1209 additions and 3 deletions

1189
web/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,9 @@
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "tsc && vite build", "build": "tsc && vite build",
"preview": "vite preview" "preview": "vite preview",
"test": "vitest run",
"test:watch": "vitest"
}, },
"dependencies": { "dependencies": {
"@types/react": "^19.2.15", "@types/react": "^19.2.15",
@ -20,10 +22,15 @@
}, },
"devDependencies": { "devDependencies": {
"@tailwindcss/postcss": "^4.3.0", "@tailwindcss/postcss": "^4.3.0",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.2",
"@testing-library/user-event": "^14.6.1",
"@vitejs/plugin-react": "^6.0.2", "@vitejs/plugin-react": "^6.0.2",
"autoprefixer": "^10.5.0", "autoprefixer": "^10.5.0",
"jsdom": "^29.1.1",
"postcss": "^8.5.15", "postcss": "^8.5.15",
"tailwindcss": "^4.3.0", "tailwindcss": "^4.3.0",
"vite": "^8.0.14" "vite": "^8.0.14",
"vitest": "^4.1.10"
} }
} }

1
web/src/test/setup.ts Normal file
View File

@ -0,0 +1 @@
import '@testing-library/jest-dom/vitest'

11
web/vitest.config.ts Normal file
View File

@ -0,0 +1,11 @@
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./src/test/setup.ts'],
},
})