-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29808 from storybookjs/norbert/vitest-support-pre…
…view-html AddonTest: Add support for previewHead
- Loading branch information
Showing
6 changed files
with
115 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { join, relative, resolve } from 'node:path'; | ||
|
||
import { | ||
getProjectRoot, | ||
loadAllPresets, | ||
loadMainConfig, | ||
resolveAddonName, | ||
validateFrameworkName, | ||
} from '@storybook/core/common'; | ||
import { oneWayHash } from '@storybook/core/telemetry'; | ||
import type { BuilderOptions, CLIOptions, LoadOptions, Options } from '@storybook/core/types'; | ||
import { global } from '@storybook/global'; | ||
|
||
export async function loadStorybook( | ||
options: CLIOptions & | ||
LoadOptions & | ||
BuilderOptions & { | ||
storybookVersion?: string; | ||
previewConfigPath?: string; | ||
} | ||
): Promise<Options> { | ||
const configDir = resolve(options.configDir); | ||
|
||
const rootDir = getProjectRoot(); | ||
const cacheKey = oneWayHash(relative(rootDir, configDir)); | ||
|
||
options.configType = 'DEVELOPMENT'; | ||
options.configDir = configDir; | ||
options.cacheKey = cacheKey; | ||
|
||
const config = await loadMainConfig(options); | ||
const { framework } = config; | ||
const corePresets = []; | ||
|
||
let frameworkName = typeof framework === 'string' ? framework : framework?.name; | ||
if (!options.ignorePreview) { | ||
validateFrameworkName(frameworkName); | ||
} | ||
if (frameworkName) { | ||
corePresets.push(join(frameworkName, 'preset')); | ||
} | ||
|
||
frameworkName = frameworkName || 'custom'; | ||
|
||
// Load first pass: We need to determine the builder | ||
// We need to do this because builders might introduce 'overridePresets' which we need to take into account | ||
// We hope to remove this in SB8 | ||
|
||
let presets = await loadAllPresets({ | ||
corePresets, | ||
overridePresets: [ | ||
require.resolve('@storybook/core/core-server/presets/common-override-preset'), | ||
], | ||
...options, | ||
isCritical: true, | ||
}); | ||
|
||
const { renderer } = await presets.apply('core', {}); | ||
const resolvedRenderer = renderer && resolveAddonName(options.configDir, renderer, options); | ||
|
||
// Load second pass: all presets are applied in order | ||
|
||
presets = await loadAllPresets({ | ||
corePresets: [ | ||
require.resolve('@storybook/core/core-server/presets/common-preset'), | ||
...(resolvedRenderer ? [resolvedRenderer] : []), | ||
...corePresets, | ||
], | ||
overridePresets: [ | ||
require.resolve('@storybook/core/core-server/presets/common-override-preset'), | ||
], | ||
...options, | ||
}); | ||
|
||
const features = await presets.apply('features'); | ||
global.FEATURES = features; | ||
|
||
return { | ||
...options, | ||
presets, | ||
features, | ||
} as Options; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
test-storybooks/portable-stories-kitchen-sink/react/.storybook/preview-head.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<style> | ||
body { | ||
background-color: rgb(250, 250, 210); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters