fix: wrap Svelte HMR configureServer for vitest 3 compat
Deploy Dashboard (Dev) / Backend Tests (push) Successful in 10m12s
Deploy Dashboard (Dev) / Frontend Tests (push) Successful in 51s
Deploy Dashboard (Dev) / Deploy to Dev (push) Failing after 2m2s

Vitest 3 bundles its own Vite which omits server.config.server,
causing the Svelte plugin's hot-update configureServer hook to
throw TypeError. Catches the error safely during test runs.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Gan, Jimmy
2026-05-07 13:15:58 +08:00
parent 50e97c4a70
commit b092ab4583
+25
View File
@@ -1,6 +1,31 @@
import { defineConfig } from 'vitest/config'; import { defineConfig } from 'vitest/config';
import { svelte } from '@sveltejs/vite-plugin-svelte'; import { svelte } from '@sveltejs/vite-plugin-svelte';
const sveltePlugin = svelte({
hot: !process.env.VITEST ? {
preserveLocalState: true
} : false,
compilerOptions: {
dev: true
}
});
// Vitest 3 bundles its own Vite which may not expose `server.config.server`,
// causing the Svelte HMR plugin's configureServer to crash. Wrap it safely.
if (process.env.VITEST) {
const plugins = Array.isArray(sveltePlugin) ? sveltePlugin : [sveltePlugin];
for (const p of plugins) {
if (p.configureServer) {
const orig = p.configureServer;
p.configureServer = function(server) {
try { return orig.call(this, server); } catch (e) {
if (!(e instanceof TypeError)) throw e;
}
};
}
}
}
export default defineConfig({ export default defineConfig({
plugins: [ plugins: [
svelte({ svelte({