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' ;
2
2
import 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' ;
4
4
import { isExportStory } from '@storybook/csf' ;
5
+ import { deprecate } from '@storybook/client-logger' ;
5
6
6
- import type { GlobalConfig , StoriesWithPartialProps , TestingStory , TestingStoryPlayContext } from './types' ;
7
+ import type { StoriesWithPartialProps , TestingStory , TestingStoryPlayContext } from './types' ;
7
8
import { getStoryName , globalRender , isInvalidStory , objectEntries } from './utils' ;
8
9
9
10
// Some addons use the channel api to communicate between manager/preview, and this is a client only feature, therefore we must mock it.
10
11
addons . setChannel ( mockChannel ( ) ) ;
11
12
12
- let globalStorybookConfig = { } ;
13
+ let GLOBAL_STORYBOOK_PROJECT_ANNOTATIONS = { } ;
13
14
14
15
const decorateStory = applyHooks ( defaultDecorateStory ) ;
15
16
@@ -23,16 +24,29 @@ const isValidStoryExport = (storyName: string, nonStoryExportsConfig = {}) =>
23
24
* Example:
24
25
*```jsx
25
26
* // 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';
28
29
*
29
- * setGlobalConfig(globalStorybookConfig );
30
+ * setProjectAnnotations(projectAnnotations );
30
31
*```
31
32
*
32
- * @param config - e.g. (import * as globalConfig from '../.storybook/preview')
33
+ * @param projectAnnotations - e.g. (import * as projectAnnotations from '../.storybook/preview')
33
34
*/
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 ) ;
36
50
}
37
51
38
52
/**
@@ -64,7 +78,7 @@ export function setGlobalConfig(config: GlobalConfig) {
64
78
export function composeStory < GenericArgs extends Args > (
65
79
story : TestingStory < GenericArgs > ,
66
80
meta : ComponentAnnotations < ReactRenderer > ,
67
- globalConfig : GlobalConfig = globalStorybookConfig
81
+ globalConfig : ProjectAnnotations < ReactRenderer > = GLOBAL_STORYBOOK_PROJECT_ANNOTATIONS
68
82
) {
69
83
70
84
if ( isInvalidStory ( story ) ) {
@@ -190,7 +204,7 @@ export function composeStory<GenericArgs extends Args>(
190
204
* @param storiesImport - e.g. (import * as stories from './Button.stories')
191
205
* @param [globalConfig] - e.g. (import * as globalConfig from '../.storybook/preview') this can be applied automatically if you use `setGlobalConfig` in your setup files.
192
206
*/
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 > ) {
194
208
const { default : meta , __esModule, __namedExportsOrder, ...stories } = storiesImport ;
195
209
196
210
// This function should take this as input:
0 commit comments