fix: Superforms SSR import from /server path and Prisma client version mismatch
- Import superValidate from sveltekit-superforms/server instead of default path to avoid pulling SuperDebug.svelte into SSR - Upgrade @prisma/client to match prisma CLI version (7.2.0 -> 7.8.0) so generated client's query_compiler_fast_bg files exist at runtime - Add regression test verifying superValidate works in server context - Add regression test verifying generated Prisma client compiler imports reference real files
This commit is contained in:
@@ -2,6 +2,10 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { createLocals, mockUser } from '$lib/test-utils';
|
||||
import { getModelConfig } from './registry';
|
||||
|
||||
// Ensure superValidate can be imported from server path in Node.js/SSR context
|
||||
import { superValidate } from 'sveltekit-superforms/server';
|
||||
import { zod4 } from 'sveltekit-superforms/adapters';
|
||||
|
||||
vi.mock('$lib/db', () => ({
|
||||
prisma: {
|
||||
userRole: {
|
||||
@@ -122,3 +126,44 @@ describe('crud deleteRecord', () => {
|
||||
expect(result).toEqual({ success: false, error: 'Missing id' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('sveltekit-superforms import compatibility', () => {
|
||||
it('imports superValidate from server path without pulling in SuperDebug.svelte', async () => {
|
||||
expect(superValidate).toBeDefined();
|
||||
});
|
||||
|
||||
it('calls superValidate with a Request and validates against a Zod schema', async () => {
|
||||
const { z } = await import('zod');
|
||||
const schema = z.object({ name: z.string().min(1) });
|
||||
const body = new URLSearchParams({ name: 'test' });
|
||||
const request = new Request('http://localhost', {
|
||||
method: 'POST',
|
||||
body,
|
||||
headers: { 'content-type': 'application/x-www-form-urlencoded' }
|
||||
});
|
||||
const form = await superValidate(request, zod4(schema));
|
||||
expect(form.valid).toBe(true);
|
||||
expect(form.data).toEqual({ name: 'test' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('prisma client version consistency', () => {
|
||||
it('generated client references existing query compiler files', async () => {
|
||||
const fs = await import('fs');
|
||||
const path = await import('path');
|
||||
const runtimeDir = path.resolve(
|
||||
'node_modules/@prisma/client/runtime'
|
||||
);
|
||||
|
||||
const generatedFile = path.resolve(
|
||||
'src/lib/generated/prisma/internal/class.ts'
|
||||
);
|
||||
const content = fs.readFileSync(generatedFile, 'utf-8');
|
||||
const compilerMatch = content.match(
|
||||
/import\(["']@prisma\/client\/runtime\/([^"']+)["']\)/
|
||||
);
|
||||
expect(compilerMatch).not.toBeNull();
|
||||
const compilerPath = path.join(runtimeDir, compilerMatch![1]);
|
||||
expect(fs.existsSync(compilerPath)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { getDelegate, parseId } from './prisma-delegate';
|
||||
import { extractFormData } from './form-data';
|
||||
import type { AdminModelConfig } from './types';
|
||||
import { superValidate } from 'sveltekit-superforms';
|
||||
import { superValidate } from 'sveltekit-superforms/server';
|
||||
import { zod4 } from 'sveltekit-superforms/adapters';
|
||||
import * as Schemas from './schemas';
|
||||
import type { z } from 'zod';
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from '$lib/svelte-admin/crud';
|
||||
import { prisma } from '$lib/db';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { superValidate } from 'sveltekit-superforms';
|
||||
import { superValidate } from 'sveltekit-superforms/server';
|
||||
import { zod4 } from 'sveltekit-superforms/adapters';
|
||||
import * as Schemas from '$lib/svelte-admin/schemas';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user