1- import { defaultDecorateStory , combineParameters , addons , applyHooks , HooksContext , mockChannel } from '@storybook/preview-api' ;
1+ import { defaultDecorateStory , combineParameters , addons , applyHooks , HooksContext , mockChannel , composeConfigs } from '@storybook/preview-api' ;
22import type { ReactRenderer , Args } from '@storybook/react' ;
3- import type { ComponentAnnotations , Store_CSFExports , StoryContext } from '@storybook/types' ;
3+ import type { ComponentAnnotations , ProjectAnnotations , Store_CSFExports , StoryContext } from '@storybook/types' ;
44import { isExportStory } from '@storybook/csf' ;
5+ import { deprecate } from '@storybook/client-logger' ;
56
6- import type { GlobalConfig , StoriesWithPartialProps , TestingStory , TestingStoryPlayContext } from './types' ;
7+ import type { StoriesWithPartialProps , TestingStory , TestingStoryPlayContext } from './types' ;
78import { getStoryName , globalRender , isInvalidStory , objectEntries } from './utils' ;
89
910// Some addons use the channel api to communicate between manager/preview, and this is a client only feature, therefore we must mock it.
1011addons . setChannel ( mockChannel ( ) ) ;
1112
12- let globalStorybookConfig = { } ;
13+ let GLOBAL_STORYBOOK_PROJECT_ANNOTATIONS = { } ;
1314
1415const decorateStory = applyHooks ( defaultDecorateStory ) ;
1516
@@ -23,16 +24,29 @@ const isValidStoryExport = (storyName: string, nonStoryExportsConfig = {}) =>
2324 * Example:
2425 *```jsx
2526 * // setup.js (for jest)
26- * import { setGlobalConfig } from '@storybook/testing-react';
27- * import * as globalStorybookConfig from './.storybook/preview';
27+ * import { setProjectAnnotations } from '@storybook/testing-react';
28+ * import * as projectAnnotations from './.storybook/preview';
2829 *
29- * setGlobalConfig(globalStorybookConfig );
30+ * setProjectAnnotations(projectAnnotations );
3031 *```
3132 *
32- * @param config - e.g. (import * as globalConfig from '../.storybook/preview')
33+ * @param projectAnnotations - e.g. (import * as projectAnnotations from '../.storybook/preview')
3334 */
34- export function setGlobalConfig ( config : GlobalConfig ) {
35- globalStorybookConfig = config ;
35+ export function setProjectAnnotations (
36+ projectAnnotations : ProjectAnnotations < ReactRenderer > | ProjectAnnotations < ReactRenderer > [ ]
37+ ) {
38+ const annotations = Array . isArray ( projectAnnotations ) ? projectAnnotations : [ projectAnnotations ] ;
39+ GLOBAL_STORYBOOK_PROJECT_ANNOTATIONS = composeConfigs ( annotations ) ;
40+ }
41+
42+ /**
43+ * @deprecated Use setProjectAnnotations instead
44+ */
45+ export function setGlobalConfig (
46+ projectAnnotations : ProjectAnnotations < ReactRenderer > | ProjectAnnotations < ReactRenderer > [ ]
47+ ) {
48+ deprecate ( `[@storybook/testing-react] setGlobalConfig is deprecated. Use setProjectAnnotations instead.` ) ;
49+ setProjectAnnotations ( projectAnnotations ) ;
3650}
3751
3852/**
@@ -64,7 +78,7 @@ export function setGlobalConfig(config: GlobalConfig) {
6478export function composeStory < GenericArgs extends Args > (
6579 story : TestingStory < GenericArgs > ,
6680 meta : ComponentAnnotations < ReactRenderer > ,
67- globalConfig : GlobalConfig = globalStorybookConfig
81+ globalConfig : ProjectAnnotations < ReactRenderer > = GLOBAL_STORYBOOK_PROJECT_ANNOTATIONS
6882) {
6983
7084 if ( isInvalidStory ( story ) ) {
@@ -190,7 +204,7 @@ export function composeStory<GenericArgs extends Args>(
190204 * @param storiesImport - e.g. (import * as stories from './Button.stories')
191205 * @param [globalConfig] - e.g. (import * as globalConfig from '../.storybook/preview') this can be applied automatically if you use `setGlobalConfig` in your setup files.
192206 */
193- export function composeStories < TModule extends Store_CSFExports < ReactRenderer > > ( storiesImport : TModule , globalConfig ?: GlobalConfig ) {
207+ export function composeStories < TModule extends Store_CSFExports < ReactRenderer > > ( storiesImport : TModule , globalConfig ?: ProjectAnnotations < ReactRenderer > ) {
194208 const { default : meta , __esModule, __namedExportsOrder, ...stories } = storiesImport ;
195209
196210 // This function should take this as input:
0 commit comments