The test setup for reactive reads set resolve.conditions for every mode. Outside tests the empty list replaced Vite's defaults, so Svelte resolved to its server build, where onMount is a no-op that the bundler drops. The layout then never resolved its sign-in gate and showed "Loading…" forever. The conditions are now only set for vitest.
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import { sveltekit } from '@sveltejs/kit/vite';
|
|
import { defineConfig } from 'vitest/config';
|
|
import { VitePWA } from 'vite-plugin-pwa';
|
|
|
|
// A revision that changes on every build, so the SW always re-fetches index.html
|
|
// when the app is redeployed. index.html is not picked up by globPatterns because
|
|
// the static adapter creates it AFTER the service worker precache manifest is
|
|
// generated — so we add it explicitly here instead.
|
|
const buildId = Date.now().toString();
|
|
|
|
export default defineConfig(({ mode }) => ({
|
|
// Vitest needs the `browser` export of Svelte so that effects re-run in tests like in the app.
|
|
// Builds must not set `resolve.conditions`: an explicit list replaces Vite's defaults and
|
|
// resolves Svelte to its server build, where onMount is a no-op that gets tree-shaken away.
|
|
...(mode === 'test' ? { resolve: { conditions: ['browser'] } } : {}),
|
|
plugins: [
|
|
sveltekit(),
|
|
VitePWA({
|
|
registerType: 'autoUpdate',
|
|
strategies: 'generateSW',
|
|
injectRegister: false,
|
|
workbox: {
|
|
globPatterns: ['**/*.{js,css,svg,png,ico,woff,woff2}'],
|
|
additionalManifestEntries: [
|
|
{ url: '/', revision: buildId },
|
|
{ url: '/index.html', revision: buildId },
|
|
{ url: '/today', revision: buildId }
|
|
],
|
|
cleanupOutdatedCaches: true,
|
|
clientsClaim: true,
|
|
navigateFallback: '/index.html',
|
|
navigateFallbackDenylist: [/^\/api/, /^\/_/, /^\/healthz/]
|
|
},
|
|
devOptions: {
|
|
enabled: true,
|
|
type: 'module'
|
|
},
|
|
manifest: {
|
|
name: 'Wotra — Working Time Tracker',
|
|
short_name: 'Wotra',
|
|
description: 'Track your working hours, close days and weeks, compute overtime.',
|
|
theme_color: '#1a1a2e',
|
|
background_color: '#f8f9fa',
|
|
display: 'standalone',
|
|
start_url: '/today',
|
|
icons: [
|
|
{ src: '/icon-192.png', sizes: '192x192', type: 'image/png' },
|
|
{ src: '/icon-512.png', sizes: '512x512', type: 'image/png' }
|
|
]
|
|
}
|
|
})
|
|
],
|
|
server: {
|
|
proxy: {
|
|
'/api': { target: 'http://127.0.0.1:8080', changeOrigin: true },
|
|
'/_': { target: 'http://127.0.0.1:8080', changeOrigin: true }
|
|
}
|
|
},
|
|
test: {
|
|
environment: 'jsdom',
|
|
globals: true,
|
|
include: ['src/**/*.test.ts'],
|
|
setupFiles: ['./src/lib/test-setup.ts']
|
|
}
|
|
}));
|