add unit tests
this adds the groundwork to start unit testing some modules
This commit is contained in:
@@ -23,4 +23,6 @@ logs
|
|||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
!.env.example
|
||||||
|
|
||||||
|
coverage/
|
||||||
|
|
||||||
wg-easy.db
|
wg-easy.db
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export default defineNuxtConfig({
|
|||||||
'radix-vue/nuxt',
|
'radix-vue/nuxt',
|
||||||
'@vueuse/nuxt',
|
'@vueuse/nuxt',
|
||||||
'@nuxt/eslint',
|
'@nuxt/eslint',
|
||||||
|
'@nuxt/test-utils/module',
|
||||||
],
|
],
|
||||||
colorMode: {
|
colorMode: {
|
||||||
preference: 'system',
|
preference: 'system',
|
||||||
|
|||||||
+6
-1
@@ -17,7 +17,8 @@
|
|||||||
"check:all": "pnpm typecheck && pnpm lint && pnpm format:check && pnpm build",
|
"check:all": "pnpm typecheck && pnpm lint && pnpm format:check && pnpm build",
|
||||||
"db:generate": "drizzle-kit generate",
|
"db:generate": "drizzle-kit generate",
|
||||||
"cli:build": "node cli/build.js",
|
"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": {
|
"dependencies": {
|
||||||
"@eschricht/nuxt-color-mode": "^1.2.0",
|
"@eschricht/nuxt-color-mode": "^1.2.0",
|
||||||
@@ -56,9 +57,12 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nuxt/eslint": "^1.14.0",
|
"@nuxt/eslint": "^1.14.0",
|
||||||
|
"@nuxt/test-utils": "^3.23.0",
|
||||||
"@types/debug": "^4.1.12",
|
"@types/debug": "^4.1.12",
|
||||||
"@types/phc__format": "^1.0.1",
|
"@types/phc__format": "^1.0.1",
|
||||||
"@types/semver": "^7.7.1",
|
"@types/semver": "^7.7.1",
|
||||||
|
"@vitest/coverage-v8": "^4.0.18",
|
||||||
|
"@vitest/ui": "4.0.18",
|
||||||
"drizzle-kit": "^0.31.8",
|
"drizzle-kit": "^0.31.8",
|
||||||
"esbuild": "^0.27.3",
|
"esbuild": "^0.27.3",
|
||||||
"eslint": "^9.39.2",
|
"eslint": "^9.39.2",
|
||||||
@@ -67,6 +71,7 @@
|
|||||||
"prettier-plugin-tailwindcss": "^0.7.2",
|
"prettier-plugin-tailwindcss": "^0.7.2",
|
||||||
"tsx": "^4.21.0",
|
"tsx": "^4.21.0",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
|
"vitest": "^4.0.18",
|
||||||
"vue-tsc": "^3.2.4"
|
"vue-tsc": "^3.2.4"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@10.29.2"
|
"packageManager": "pnpm@10.29.2"
|
||||||
|
|||||||
Generated
+594
-28
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user