refactoring and tests

This commit is contained in:
vcoppe committed 2026-10-09 08:58:00 +02:00
1 parent 3bb553d6b5
commit da9abbae5e
45 files changed
+3558 -1564

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
// Resolves the virtual modules of SvelteKit to stubs, so that the code that imports them can be
// tested outside of the framework.
import { fileURLToPath, pathToFileURL } from 'node:url';
const stubs = {
'$app/environment': 'app-environment.ts',
'$app/paths': 'app-paths.ts',
'$app/state': 'app-state.ts',
'$env/static/public': 'env-static-public.ts',
};
export async function resolve(specifier, context, nextResolve) {
const stub = stubs[specifier];
if (stub) {
const url = pathToFileURL(fileURLToPath(new URL(`./stubs/${stub}`, import.meta.url)));
return nextResolve(url.href, context);
}
return nextResolve(specifier, context);
}
// Stylesheets are for the browser: importing one gives nothing.
export async function load(url, context, nextLoad) {
if (url.endsWith('.css')) {
return { format: 'module', source: '', shortCircuit: true };
}
return nextLoad(url, context);
}
+12
View File
@@ -0,0 +1,12 @@
import { register } from 'node:module';
register('./hooks.mjs', import.meta.url);
// The runes of Svelte are compiled away in the app. In the tests, the modules that use them are
// only loaded, never relied on for reactivity: a rune is its value.
globalThis.$state = (value) => value;
globalThis.$state.raw = (value) => value;
globalThis.$derived = (value) => value;
globalThis.$derived.by = (compute) => compute();
globalThis.$effect = () => {};
globalThis.$effect.pre = () => {};
@@ -0,0 +1,8 @@
// The tests run like the browser does, which is where the engine is available.
export const browser = true;
export const dev = false;
export const building = false;
export const version = 'test';
// what the code that checks `browser` reads of the window
(globalThis as { window?: unknown }).window ??= { innerWidth: 1280, innerHeight: 800, URL };
+5
View File
@@ -0,0 +1,5 @@
export const base = '';
export const assets = '';
export function resolve(path: string) {
return path;
}
+2
View File
@@ -0,0 +1,2 @@
export const page = { url: new URL('http://localhost/') };
export const navigating = { from: null, to: null };
@@ -0,0 +1 @@
export const PUBLIC_MAPTILER_KEY = 'test-key';