Skip to content

Commit 3adca93

Browse files
committed
Add vitest support
1 parent 1344a3a commit 3adca93

File tree

5 files changed

+64
-15
lines changed

5 files changed

+64
-15
lines changed

MyApp.Client/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"scripts": {
77
"dev": "vite",
88
"build": "vue-tsc -b && vite build",
9-
"preview": "vite preview"
9+
"preview": "vite preview",
10+
"test": "vitest",
11+
"test:ui": "vitest --ui",
12+
"test:run": "vitest run"
1013
},
1114
"dependencies": {
1215
"@servicestack/client": "^2.1.13",
@@ -19,9 +22,13 @@
1922
"devDependencies": {
2023
"@types/node": "^24.10.1",
2124
"@vitejs/plugin-vue": "^6.0.1",
25+
"@vitest/ui": "^4.0.15",
26+
"@vue/test-utils": "^2.4.6",
2227
"@vue/tsconfig": "^0.8.1",
28+
"happy-dom": "^20.0.11",
2329
"typescript": "~5.9.3",
2430
"vite": "^7.2.4",
31+
"vitest": "^4.0.15",
2532
"vue-tsc": "^3.1.4"
2633
}
2734
}

MyApp.Client/src/lib/auth.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { describe, it, expect } from 'vitest'
2+
import { createAttrs } from './auth'
3+
4+
describe('auth utilities', () => {
5+
describe('createAttrs', () => {
6+
it('should return empty array for null auth', () => {
7+
const result = createAttrs(null)
8+
expect(result).toEqual([])
9+
})
10+
11+
it('should return empty array for undefined auth', () => {
12+
const result = createAttrs(undefined)
13+
expect(result).toEqual([])
14+
})
15+
16+
it('should return auth attr for authenticated user with no roles or permissions', () => {
17+
const result = createAttrs({})
18+
expect(result).toEqual(['auth'])
19+
})
20+
21+
it('should include roles with role: prefix', () => {
22+
const result = createAttrs({
23+
roles: ['Admin', 'Manager']
24+
})
25+
expect(result).toEqual(['auth', 'role:Admin', 'role:Manager'])
26+
})
27+
28+
it('should include permissions with perm: prefix', () => {
29+
const result = createAttrs({
30+
permissions: ['ReadData', 'WriteData']
31+
})
32+
expect(result).toEqual(['auth', 'perm:ReadData', 'perm:WriteData'])
33+
})
34+
35+
it('should include both roles and permissions', () => {
36+
const result = createAttrs({
37+
roles: ['Admin'],
38+
permissions: ['ReadData', 'WriteData']
39+
})
40+
expect(result).toEqual(['auth', 'role:Admin', 'perm:ReadData', 'perm:WriteData'])
41+
})
42+
43+
it('should handle empty roles and permissions arrays', () => {
44+
const result = createAttrs({
45+
roles: [],
46+
permissions: []
47+
})
48+
expect(result).toEqual(['auth'])
49+
})
50+
})
51+
})

MyApp.Client/src/main.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import '../styles/style.css'
66
import App from '@/App.vue'
77
import Index from '@/index.vue'
88
import Profile from '@/profile.vue'
9-
import Test from '@/test.vue'
109
import { isServerRoute, useApp } from '@/lib/gateway'
1110
import { configRouter } from '@/lib/auth'
1211

@@ -21,7 +20,6 @@ if (colorScheme === 'dark') {
2120
export const router = configRouter(createRouter({
2221
history: createWebHistory(),
2322
routes: [
24-
{ path: '/test', component: Test },
2523
{ path: '/profile', component: Profile },
2624
{ path: '/:pathMatch(.*)*', component: Index }
2725
],

MyApp.Client/src/test.vue

Lines changed: 0 additions & 11 deletions
This file was deleted.

MyApp.Client/vite.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig } from 'vite'
1+
import { defineConfig } from 'vitest/config'
22
import tailwindcss from '@tailwindcss/vite'
33
import { fileURLToPath } from 'url'
44

@@ -21,5 +21,9 @@ export default defineConfig({
2121
server: {
2222
host: true, // Listen on all interfaces (both IPv4 and IPv6)
2323
open: false,
24+
},
25+
test: {
26+
environment: 'happy-dom',
27+
globals: true,
2428
}
2529
})

0 commit comments

Comments
 (0)