From 7772703b7c6eb56ad4971d95a6d0b32c89db0fdd Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 14 Feb 2023 00:42:46 +0100 Subject: [PATCH] test: improve vite config --- tests/unit/setup.ts | 5 ----- vite.config.js | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/unit/setup.ts b/tests/unit/setup.ts index d5a0fbaff..b0dedf2c4 100644 --- a/tests/unit/setup.ts +++ b/tests/unit/setup.ts @@ -1,15 +1,10 @@ import { vi } from 'vitest'; -import * as svelteinternal from 'svelte/internal'; beforeAll(() => { vi.mock('$app/environment', () => ({ browser: true })); - vi.mock('$app/stores', () => ({ - page: null - })); vi.mock('$app/navigation', () => ({ goto: vi.fn() })); - vi.mock('svelte', () => svelteinternal); }); diff --git a/vite.config.js b/vite.config.js index 09dad1de7..1542dc4ea 100644 --- a/vite.config.js +++ b/vite.config.js @@ -17,6 +17,14 @@ const config = { }, server: { port: 3000 + } +}; + +/** @type {import('vite').UserConfig} */ +const testConfig = { + resolve: { + // hotfix for https://github.com/vitest-dev/vitest/issues/2834 + conditions: ['browser'] }, test: { include: ['tests/**/*.test.ts'], @@ -30,4 +38,9 @@ const config = { } }; -export default config; +export default process.env.VITEST + ? { + ...config, + ...testConfig + } + : config;