Skip to content

Commit

Permalink
SvelteKIT: Support ESM for Vitest test runs
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Sep 19, 2024
1 parent 57ee6e1 commit 987feb4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions code/frameworks/sveltekit/src/plugins/mock-sveltekit-stores.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { resolve } from 'node:path';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

import type { Plugin } from 'vite';

// @ts-expect-error We are building for CJS and ESM, so we have to use import.meta.url for the ESM output
const filename = __filename ?? fileURLToPath(import.meta.url);
const dir = dirname(filename);

export async function mockSveltekitStores() {
return {
name: 'storybook:sveltekit-mock-stores',
config: () => ({
resolve: {
alias: {
'$app/forms': resolve(__dirname, '../src/mocks/app/forms.ts'),
'$app/navigation': resolve(__dirname, '../src/mocks/app/navigation.ts'),
'$app/stores': resolve(__dirname, '../src/mocks/app/stores.ts'),
'$app/forms': resolve(dir, '../src/mocks/app/forms.ts'),
'$app/navigation': resolve(dir, '../src/mocks/app/navigation.ts'),
'$app/stores': resolve(dir, '../src/mocks/app/stores.ts'),
},
},
}),
Expand Down

0 comments on commit 987feb4

Please sign in to comment.