|
| 1 | +import { resolve } from 'node:path' |
| 2 | +import { fileURLToPath } from 'node:url' |
| 3 | +import { describe, expect, it } from 'vitest' |
| 4 | +import { runCorePreset } from './helpers/runCorePreset' |
| 5 | + |
| 6 | +const workspaceRoot = fileURLToPath(new URL('..', import.meta.url)) |
| 7 | + |
| 8 | +interface CaseItem { |
| 9 | + name: string |
| 10 | + modulePath: string |
| 11 | + expectedRendererSegment: string |
| 12 | +} |
| 13 | + |
| 14 | +const CASES: CaseItem[] = [ |
| 15 | + { |
| 16 | + name: 'html', |
| 17 | + modulePath: './packages/framework-html/src/preset.ts', |
| 18 | + expectedRendererSegment: '@storybook/html/dist/preset', |
| 19 | + }, |
| 20 | + { |
| 21 | + name: 'react', |
| 22 | + modulePath: './packages/framework-react/src/preset.ts', |
| 23 | + expectedRendererSegment: '@storybook/react/dist/preset', |
| 24 | + }, |
| 25 | + { |
| 26 | + name: 'react-native-web', |
| 27 | + modulePath: './packages/framework-react-native-web/src/preset.ts', |
| 28 | + expectedRendererSegment: '@storybook/react/dist/preset', |
| 29 | + }, |
| 30 | + { |
| 31 | + name: 'vue3', |
| 32 | + modulePath: './packages/framework-vue3/src/preset.ts', |
| 33 | + expectedRendererSegment: '@storybook/vue3/dist/preset', |
| 34 | + }, |
| 35 | + { |
| 36 | + name: 'web-components', |
| 37 | + modulePath: './packages/framework-web-components/src/preset.ts', |
| 38 | + expectedRendererSegment: '@storybook/web-components/dist/preset', |
| 39 | + }, |
| 40 | +] |
| 41 | +function normalizePathSeparators(value: string): string { |
| 42 | + return value.replaceAll('\\', '/') |
| 43 | +} |
| 44 | + |
| 45 | +describe.each(CASES)('$name core preset', ({ |
| 46 | + modulePath, |
| 47 | + expectedRendererSegment, |
| 48 | +}) => { |
| 49 | + it('preserves incoming core config while applying builder settings', async () => { |
| 50 | + const result = await runCorePreset(resolve(workspaceRoot, modulePath)) |
| 51 | + |
| 52 | + expect(result.channelOptions).toEqual({ wsToken: 'test-token' }) |
| 53 | + expect(result.disableTelemetry).toBe(true) |
| 54 | + expect(result.builderOptions).toEqual({ lazyCompilation: true }) |
| 55 | + expect(result.builderName).toBeTruthy() |
| 56 | + expect(normalizePathSeparators(result.renderer)).toContain( |
| 57 | + expectedRendererSegment, |
| 58 | + ) |
| 59 | + }) |
| 60 | +}) |
0 commit comments