test: add vitest and svelte testing library (resolves #13)
This commit is contained in:
+7
-1
@@ -10,6 +10,8 @@
|
|||||||
"prepare": "husky",
|
"prepare": "husky",
|
||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||||
|
"test": "vitest run",
|
||||||
|
"test:watch": "vitest",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"lint": "prettier --check . && eslint .",
|
"lint": "prettier --check . && eslint .",
|
||||||
"db:start": "docker compose up",
|
"db:start": "docker compose up",
|
||||||
@@ -28,6 +30,8 @@
|
|||||||
"@sveltejs/kit": "^2.49.0",
|
"@sveltejs/kit": "^2.49.0",
|
||||||
"@sveltejs/vite-plugin-svelte": "^6.2.1",
|
"@sveltejs/vite-plugin-svelte": "^6.2.1",
|
||||||
"@tailwindcss/vite": "^4.1.17",
|
"@tailwindcss/vite": "^4.1.17",
|
||||||
|
"@testing-library/jest-dom": "^6.9.1",
|
||||||
|
"@testing-library/svelte": "^5.3.1",
|
||||||
"@tiptap/core": "3.7.2",
|
"@tiptap/core": "3.7.2",
|
||||||
"@types/node": "^20.19.25",
|
"@types/node": "^20.19.25",
|
||||||
"drizzle-kit": "^0.31.7",
|
"drizzle-kit": "^0.31.7",
|
||||||
@@ -39,6 +43,7 @@
|
|||||||
"flowbite-svelte-icons": "^3.0.0",
|
"flowbite-svelte-icons": "^3.0.0",
|
||||||
"globals": "^16.5.0",
|
"globals": "^16.5.0",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
|
"jsdom": "^29.0.1",
|
||||||
"lowlight": "^3.3.0",
|
"lowlight": "^3.3.0",
|
||||||
"prettier": "^3.6.2",
|
"prettier": "^3.6.2",
|
||||||
"prettier-plugin-svelte": "^3.4.0",
|
"prettier-plugin-svelte": "^3.4.0",
|
||||||
@@ -47,7 +52,8 @@
|
|||||||
"tailwindcss": "^4.1.17",
|
"tailwindcss": "^4.1.17",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
"typescript-eslint": "^8.47.0",
|
"typescript-eslint": "^8.47.0",
|
||||||
"vite": "^7.2.4"
|
"vite": "^7.2.4",
|
||||||
|
"vitest": "^4.1.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@auth/drizzle-adapter": "^1.11.1",
|
"@auth/drizzle-adapter": "^1.11.1",
|
||||||
|
|||||||
Generated
+761
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,46 @@
|
|||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import { extractFormData } from './extractFormData';
|
||||||
|
import * as v from 'valibot';
|
||||||
|
|
||||||
|
describe('extractFormData', () => {
|
||||||
|
it('should successfully extract and validate correct form data', async () => {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('name', 'John Doe');
|
||||||
|
formData.append('age', '30');
|
||||||
|
|
||||||
|
const request = new Request('http://localhost', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
});
|
||||||
|
|
||||||
|
const schema = v.object({
|
||||||
|
name: v.string(),
|
||||||
|
age: v.string()
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await extractFormData(request, schema);
|
||||||
|
|
||||||
|
expect(result.error).toBeNull();
|
||||||
|
expect(result.data).toEqual({ name: 'John Doe', age: '30' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail validation with missing required fields', async () => {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('age', '30');
|
||||||
|
|
||||||
|
const request = new Request('http://localhost', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
});
|
||||||
|
|
||||||
|
const schema = v.object({
|
||||||
|
name: v.string(),
|
||||||
|
age: v.string()
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await extractFormData(request, schema);
|
||||||
|
|
||||||
|
expect(result.data).toBeUndefined();
|
||||||
|
expect(result.error).toBeTypeOf('string');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
import '@testing-library/jest-dom/vitest';
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { defineConfig } from 'vitest/config';
|
||||||
|
import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
|
import { svelteTesting } from '@testing-library/svelte/vite';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [sveltekit(), svelteTesting()],
|
||||||
|
test: {
|
||||||
|
include: ['src/**/*.{test,spec}.{js,ts}'],
|
||||||
|
environment: 'jsdom',
|
||||||
|
setupFiles: ['./vitest-setup.ts']
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user