add unit tests

this adds the groundwork to start unit testing some modules
This commit is contained in:
Bernd Storath
2026-02-11 15:23:04 +01:00
parent 7a219b73d4
commit 71aaec93ef
6 changed files with 641 additions and 29 deletions
+2
View File
@@ -23,4 +23,6 @@ logs
.env.*
!.env.example
coverage/
wg-easy.db
+1
View File
@@ -15,6 +15,7 @@ export default defineNuxtConfig({
'radix-vue/nuxt',
'@vueuse/nuxt',
'@nuxt/eslint',
'@nuxt/test-utils/module',
],
colorMode: {
preference: 'system',
+6 -1
View File
@@ -17,7 +17,8 @@
"check:all": "pnpm typecheck && pnpm lint && pnpm format:check && pnpm build",
"db:generate": "drizzle-kit generate",
"cli:build": "node cli/build.js",
"cli:dev": "tsx cli/index.ts"
"cli:dev": "tsx cli/index.ts",
"test:unit": "vitest run --project unit"
},
"dependencies": {
"@eschricht/nuxt-color-mode": "^1.2.0",
@@ -56,9 +57,12 @@
},
"devDependencies": {
"@nuxt/eslint": "^1.14.0",
"@nuxt/test-utils": "^3.23.0",
"@types/debug": "^4.1.12",
"@types/phc__format": "^1.0.1",
"@types/semver": "^7.7.1",
"@vitest/coverage-v8": "^4.0.18",
"@vitest/ui": "4.0.18",
"drizzle-kit": "^0.31.8",
"esbuild": "^0.27.3",
"eslint": "^9.39.2",
@@ -67,6 +71,7 @@
"prettier-plugin-tailwindcss": "^0.7.2",
"tsx": "^4.21.0",
"typescript": "^5.9.3",
"vitest": "^4.0.18",
"vue-tsc": "^3.2.4"
},
"packageManager": "pnpm@10.29.2"
+594 -28
View File
File diff suppressed because it is too large Load Diff
+20
View File
@@ -0,0 +1,20 @@
import { expect, test, describe } from 'vitest';
import {
hashPassword,
isPasswordValid,
isValidPasswordHash,
} from '../../server/utils/password';
describe('password', () => {
test('password', async () => {
const hash = await hashPassword('password');
await expect(isPasswordValid('password', hash)).resolves.toBe(true);
await expect(isPasswordValid('wrong', hash)).resolves.toBe(false);
expect(isValidPasswordHash('not a hash')).toBe(false);
expect(isValidPasswordHash(hash)).toBe(true);
expect(isValidPasswordHash(hash.replace('argon2', 'argon3'))).toBe(false);
});
});
+18
View File
@@ -0,0 +1,18 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
projects: [
{
test: {
name: 'unit',
include: ['test/unit/*.{test,spec}.ts'],
environment: 'node',
},
},
],
coverage: {
enabled: true,
},
},
});