Commit d6452cf0 authored by Administrator's avatar Administrator
Browse files

chore(test): add vitest setup



Wires up vitest + @vue/test-utils + jsdom so the spec 0004 tests can run.

- package.json: 3 npm scripts (test, test:run, test:ui) + vitest /
  @vue/test-utils / jsdom devDeps.
- vitest.config.js: jsdom env, @ alias pointing at src/, setup file.
- src/test-setup.js: shared jest-dom-style matchers.
- src/__tests__/smoke.test.js: sanity check the harness resolves the @
  alias and that taskService imports cleanly.
Co-Authored-By: default avatarClaude <noreply@anthropic.com>
parent 8925331e
This diff is collapsed.
...@@ -11,7 +11,10 @@ ...@@ -11,7 +11,10 @@
"build": "vite build", "build": "vite build",
"preview": "vite preview", "preview": "vite preview",
"lint": "eslint . --fix", "lint": "eslint . --fix",
"format": "prettier --write src/" "format": "prettier --write src/",
"test": "vitest",
"test:run": "vitest run",
"test:ui": "vitest --ui"
}, },
"dependencies": { "dependencies": {
"@fullcalendar/daygrid": "^6.1.21", "@fullcalendar/daygrid": "^6.1.21",
...@@ -29,12 +32,15 @@ ...@@ -29,12 +32,15 @@
"@eslint/js": "^9.31.0", "@eslint/js": "^9.31.0",
"@vitejs/plugin-vue": "^6.0.1", "@vitejs/plugin-vue": "^6.0.1",
"@vue/eslint-config-prettier": "^10.2.0", "@vue/eslint-config-prettier": "^10.2.0",
"@vue/test-utils": "^2.4.11",
"eslint": "^9.31.0", "eslint": "^9.31.0",
"eslint-plugin-vue": "~10.3.0", "eslint-plugin-vue": "~10.3.0",
"globals": "^16.3.0", "globals": "^16.3.0",
"js-yaml": "^5.2.0", "js-yaml": "^5.2.0",
"jsdom": "^29.1.1",
"prettier": "3.6.2", "prettier": "3.6.2",
"vite": "^7.0.6", "vite": "^7.0.6",
"vite-plugin-vue-devtools": "^8.0.0" "vite-plugin-vue-devtools": "^8.0.0",
"vitest": "^4.1.10"
} }
} }
import { describe, it, expect } from 'vitest'
describe('vitest smoke', () => {
it('runs', () => {
expect(1 + 1).toBe(2)
})
it('resolves @ alias', async () => {
const mod = await import('@/api/taskService.js')
expect(mod).toBeTruthy()
expect(typeof mod.getTasks).toBe('function')
})
})
// Global test setup. @vue/test-utils 2.x removed the standalone cleanup()
// export; auto-unmount via enableAutoUnmount(afterEach) is the documented
// replacement and runs after each test in this file.
import { afterEach } from 'vitest'
import { enableAutoUnmount } from '@vue/test-utils'
enableAutoUnmount(afterEach)
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'
// Vitest config: jsdom env, alias matches vite.config.js. Vue plugin is
// registered here (not in vite.config.js) so vite-plugin-vue-devtools does
// not get pulled into test runs.
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
test: {
environment: 'jsdom',
globals: true,
setupFiles: ['./src/test-setup.js'],
include: ['src/**/*.{test,spec}.{js,mjs}'],
css: {
// We don't render styles in jsdom. Skip CSS processing entirely so
// Vuetify's per-component .css imports resolve to empty modules.
include: [],
},
server: {
deps: {
// Vuetify has heavy ESM re-exports; pre-bundle to keep test start fast.
inline: ['vuetify'],
},
},
},
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment