Merge pull request 'Add Vitest + Svelte Testing Library' (#23) from issue-13 into main
Commit / ci (push) Has been cancelled

Reviewed-on: #23
This commit was merged in pull request #23.
This commit is contained in:
2026-04-03 14:09:29 +02:00
7 changed files with 812 additions and 2 deletions
+3
View File
@@ -34,3 +34,6 @@ jobs:
- name: Type Check (Svelte Check)
# Based on your package.json "check" script
run: pnpm check
- name: Run Tests (Vitest)
run: pnpm run test
+1 -1
View File
@@ -1,4 +1,4 @@
FROM node:25-trixie AS base
FROM public.ecr.aws/docker/library/node:25-trixie AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
# RUN corepack enable
+7 -1
View File
@@ -10,6 +10,8 @@
"prepare": "husky",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"test": "vitest run",
"test:watch": "vitest",
"format": "prettier --write .",
"lint": "prettier --check . && eslint .",
"db:start": "docker compose up",
@@ -28,6 +30,8 @@
"@sveltejs/kit": "^2.49.0",
"@sveltejs/vite-plugin-svelte": "^6.2.1",
"@tailwindcss/vite": "^4.1.17",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/svelte": "^5.3.1",
"@tiptap/core": "3.7.2",
"@types/node": "^20.19.25",
"@types/sanitize-html": "^2.16.1",
@@ -40,6 +44,7 @@
"flowbite-svelte-icons": "^3.0.0",
"globals": "^16.5.0",
"husky": "^9.1.7",
"jsdom": "^29.0.1",
"lowlight": "^3.3.0",
"prettier": "^3.6.2",
"prettier-plugin-svelte": "^3.4.0",
@@ -48,7 +53,8 @@
"tailwindcss": "^4.1.17",
"typescript": "^5.9.3",
"typescript-eslint": "^8.47.0",
"vite": "^7.2.4"
"vite": "^7.2.4",
"vitest": "^4.1.2"
},
"dependencies": {
"@auth/drizzle-adapter": "^1.11.1",
+742
View File
File diff suppressed because it is too large Load Diff
+46
View File
@@ -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');
});
});
+1
View File
@@ -0,0 +1 @@
import '@testing-library/jest-dom/vitest';
+12
View File
@@ -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']
}
});