b092ab4583
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>
58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
import { defineConfig } from 'vitest/config';
|
|
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({
|
|
plugins: [
|
|
svelte({
|
|
hot: !process.env.VITEST ? {
|
|
preserveLocalState: true
|
|
} : false,
|
|
compilerOptions: {
|
|
dev: true
|
|
}
|
|
})
|
|
],
|
|
test: {
|
|
globals: true,
|
|
environment: 'jsdom',
|
|
setupFiles: ['./tests/setup.js'],
|
|
resetMocks: true,
|
|
coverage: {
|
|
provider: 'v8',
|
|
reporter: ['text', 'html', 'lcov'],
|
|
exclude: ['node_modules/', 'tests/', 'dist/', '*.config.js']
|
|
}
|
|
},
|
|
resolve: {
|
|
conditions: ['browser'],
|
|
alias: {
|
|
'@': '/src'
|
|
}
|
|
}
|
|
});
|