Browse Source

add unit tests

this adds the groundwork to start unit testing some modules
pull/2477/head
Bernd Storath 4 months ago
parent
commit
71aaec93ef
  1. 2
      src/.gitignore
  2. 1
      src/nuxt.config.ts
  3. 7
      src/package.json
  4. 622
      src/pnpm-lock.yaml
  5. 20
      src/test/unit/password.spec.ts
  6. 18
      src/vitest.config.ts

2
src/.gitignore

@ -23,4 +23,6 @@ logs
.env.*
!.env.example
coverage/
wg-easy.db

1
src/nuxt.config.ts

@ -15,6 +15,7 @@ export default defineNuxtConfig({
'radix-vue/nuxt',
'@vueuse/nuxt',
'@nuxt/eslint',
'@nuxt/test-utils/module',
],
colorMode: {
preference: 'system',

7
src/package.json

@ -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": "[email protected]"

622
src/pnpm-lock.yaml

File diff suppressed because it is too large

20
src/test/unit/password.spec.ts

@ -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
src/vitest.config.ts

@ -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,
},
},
});
Loading…
Cancel
Save