Skip to content

Commit fafc6b6

Browse files
committed
test: add core preset propagation regression test
test: normalize renderer path assertion across platforms test: pass preset path via env in subprocess runner test: move core preset subprocess runner to helper
1 parent b7f07b4 commit fafc6b6

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
})

tests/helpers/runCorePreset.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { pathToFileURL } from 'node:url'
2+
import { tsImport } from 'tsx/esm/api'
3+
4+
interface CoreResult {
5+
builderOptions: Record<string, unknown>
6+
builderName: string
7+
channelOptions: {
8+
wsToken?: string
9+
}
10+
disableTelemetry: boolean
11+
renderer: string
12+
}
13+
14+
export async function runCorePreset(presetPath: string): Promise<CoreResult> {
15+
const { core } = await tsImport(
16+
pathToFileURL(presetPath).href,
17+
import.meta.url,
18+
)
19+
20+
const config = {
21+
channelOptions: { wsToken: 'test-token' },
22+
disableTelemetry: true,
23+
}
24+
const framework = { options: { builder: { lazyCompilation: true } } }
25+
const options = {
26+
presets: {
27+
apply: async (name: string) =>
28+
name === 'framework' ? framework : undefined,
29+
},
30+
}
31+
32+
const result = await core(config, options)
33+
34+
return {
35+
channelOptions: result.channelOptions,
36+
disableTelemetry: result.disableTelemetry,
37+
builderOptions: result.builder.options,
38+
builderName: result.builder.name,
39+
renderer: result.renderer,
40+
}
41+
}

0 commit comments

Comments
 (0)