test(web): setup frontend test infrastructure (#60)

- Add testing dependencies (vitest, vue-test-utils, testing-library, jsdom, msw)
- Create vitest.config.ts with jsdom environment and coverage settings
- Create setup.ts with Pinia initialization and fake timers
- Add test scripts to package.json (test, test:run, test:coverage)

Closes #56, closes #57
This commit is contained in:
Zihao Xu
2026-01-19 04:48:28 -08:00
committed by GitHub
parent 9677055faa
commit 8bf5f64bc3
3 changed files with 53 additions and 2 deletions

View File

@@ -6,13 +6,22 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
"preview": "vite preview",
"test": "vitest",
"test:run": "vitest run",
"test:coverage": "vitest run --coverage"
},
"devDependencies": {
"@testing-library/vue": "^8.1.0",
"@vitejs/plugin-vue": "^5.2.4",
"@vitest/coverage-v8": "^2.1.8",
"@vue/test-utils": "^2.4.6",
"jsdom": "^25.0.1",
"msw": "^2.7.0",
"sass": "^1.94.1",
"typescript": "~5.9.3",
"vite": "^5.4.21"
"vite": "^5.4.21",
"vitest": "^2.1.8"
},
"dependencies": {
"@vueuse/core": "^14.0.0",

View File

@@ -0,0 +1,15 @@
import { vi, beforeEach, afterEach, beforeAll, afterAll } from 'vitest'
import { createPinia, setActivePinia } from 'pinia'
// Use fake timers globally for consistent async testing.
vi.useFakeTimers()
// Setup fresh Pinia instance for each test.
beforeEach(() => {
setActivePinia(createPinia())
})
// Cleanup after each test.
afterEach(() => {
vi.clearAllMocks()
})

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

@@ -0,0 +1,27 @@
import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
export default defineConfig({
plugins: [vue()],
test: {
environment: 'jsdom',
globals: true,
setupFiles: ['./src/__tests__/setup.ts'],
include: ['src/**/*.test.ts'],
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
exclude: [
'node_modules/',
'src/__tests__/',
'**/*.d.ts',
],
},
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
})