@khanacademy/wonder-blocks-testing 6.1.0 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/es/index.js +17 -187
  3. package/dist/index.js +90 -463
  4. package/package.json +2 -2
  5. package/src/__docs__/_overview_fixtures.stories.mdx +2 -6
  6. package/src/__docs__/exports.fixtures.stories.mdx +9 -31
  7. package/src/__docs__/types.fixture-fn.stories.mdx +46 -0
  8. package/src/__docs__/types.fixture-props.stories.mdx +20 -0
  9. package/src/fixtures/__tests__/fixtures.test.js +89 -466
  10. package/src/fixtures/fixtures.basic.stories.js +30 -50
  11. package/src/fixtures/fixtures.defaultwrapper.stories.js +26 -40
  12. package/src/fixtures/fixtures.js +50 -103
  13. package/src/fixtures/types.js +15 -181
  14. package/src/index.js +2 -11
  15. package/src/__docs__/exports.fixture-adapters.stories.mdx +0 -49
  16. package/src/__docs__/exports.setup-fixtures.stories.mdx +0 -22
  17. package/src/__docs__/types.custom-mount-props.stories.mdx +0 -35
  18. package/src/__docs__/types.fixtures-adapter-factory.stories.mdx +0 -23
  19. package/src/__docs__/types.fixtures-adapter-fixture-options.stories.mdx +0 -35
  20. package/src/__docs__/types.fixtures-adapter-group-options.stories.mdx +0 -37
  21. package/src/__docs__/types.fixtures-adapter-group.stories.mdx +0 -43
  22. package/src/__docs__/types.fixtures-adapter-options.stories.mdx +0 -21
  23. package/src/__docs__/types.fixtures-adapter.stories.mdx +0 -35
  24. package/src/__docs__/types.fixtures-configuration.stories.mdx +0 -35
  25. package/src/__docs__/types.fixtures-options.stories.mdx +0 -51
  26. package/src/fixtures/__tests__/combine-options.test.js +0 -65
  27. package/src/fixtures/__tests__/combine-top-level.test.js +0 -100
  28. package/src/fixtures/__tests__/setup.test.js +0 -71
  29. package/src/fixtures/adapters/__tests__/__snapshots__/adapter-group.test.js.snap +0 -9
  30. package/src/fixtures/adapters/__tests__/__snapshots__/adapter.test.js.snap +0 -13
  31. package/src/fixtures/adapters/__tests__/adapter-group.test.js +0 -223
  32. package/src/fixtures/adapters/__tests__/adapter.test.js +0 -97
  33. package/src/fixtures/adapters/__tests__/storybook.test.js +0 -369
  34. package/src/fixtures/adapters/adapter-group.js +0 -88
  35. package/src/fixtures/adapters/adapter.js +0 -63
  36. package/src/fixtures/adapters/adapters.js +0 -2
  37. package/src/fixtures/adapters/storybook.js +0 -128
  38. package/src/fixtures/combine-options.js +0 -25
  39. package/src/fixtures/combine-top-level.js +0 -44
  40. package/src/fixtures/setup.js +0 -30
@@ -1,23 +1,14 @@
1
1
  // @flow
2
2
  import * as React from "react";
3
3
 
4
- import {
5
- setupFixtures,
6
- fixtures,
7
- fixtureAdapters as adapters,
8
- } from "../index.js";
9
-
10
- // Normally would call setup from the storybook.preview.js for a project.
11
- setupFixtures({
12
- adapter: adapters.storybook(),
13
- });
4
+ import {fixtures} from "../index.js";
14
5
 
15
6
  type Props = {|
16
7
  propA: string,
17
8
  propB?: string,
18
9
  |};
19
10
 
20
- const MyComponent = (props: Props) =>
11
+ const MyComponent = (props: Props): React.Node =>
21
12
  `I am a component. Here are my props: ${JSON.stringify(props, null, 2)}`;
22
13
 
23
14
  const Wrapper = (props) => (
@@ -28,46 +19,35 @@ const Wrapper = (props) => (
28
19
  </>
29
20
  );
30
21
 
31
- const stories: Array<mixed> = Object.values(
32
- fixtures<typeof MyComponent, _>(
33
- {
34
- component: MyComponent,
35
- title: "Testing / Fixtures / Basic",
36
- },
37
- (fixture) => {
38
- fixture("This is a fixture with some regular props", {
39
- propA: "this is a prop",
40
- propB: "this is another",
41
- });
22
+ const fixture = fixtures(MyComponent);
42
23
 
43
- fixture(
44
- "This is a fixture with props from functions, and a bit of logging",
45
- ({log}) => {
46
- log(
47
- "This is a log from a fixture during props generation",
48
- {
49
- and: "some data",
50
- },
51
- );
52
- return {
53
- propA: "prop was made from a function",
54
- };
55
- },
56
- );
24
+ export const F1: mixed = fixture("This is a fixture with some regular props", {
25
+ propA: "this is a prop",
26
+ propB: "this is another",
27
+ });
28
+
29
+ export const F2: mixed = fixture(
30
+ "This is a fixture with props from functions, and a bit of logging",
31
+ ({log}) => {
32
+ log("This is a log from a fixture during props generation", {
33
+ and: "some data",
34
+ });
35
+ return {
36
+ propA: "prop was made from a function",
37
+ };
38
+ },
39
+ );
57
40
 
58
- fixture(
59
- "This fixture uses a custom wrapper",
60
- {
61
- propA: "some props again",
62
- propB: "this one",
63
- },
64
- Wrapper,
65
- );
66
- },
67
- ) ?? {},
41
+ export const F3: mixed = fixture(
42
+ "This fixture uses a custom wrapper",
43
+ {
44
+ propA: "some props again",
45
+ propB: "this one",
46
+ },
47
+ Wrapper,
68
48
  );
69
49
 
70
- export default stories[0];
71
- export const F1 = stories[1];
72
- export const F2 = stories[2];
73
- export const F3 = stories[3];
50
+ export default {
51
+ title: "Testing / Fixtures / Basic",
52
+ component: MyComponent,
53
+ };
@@ -1,18 +1,12 @@
1
1
  // @flow
2
2
  import * as React from "react";
3
3
 
4
- import {
5
- setupFixtures,
6
- fixtures,
7
- fixtureAdapters as adapters,
8
- } from "../index.js";
4
+ import {fixtures} from "../index.js";
9
5
 
10
- // Normally would call setup from the storybook.preview.js for a project.
11
- setupFixtures({
12
- adapter: adapters.storybook(),
13
- });
6
+ type Props = {...};
14
7
 
15
- const MyComponent = (props) => `My props: ${JSON.stringify(props, null, 2)}`;
8
+ const MyComponent = (props: Props) =>
9
+ `My props: ${JSON.stringify(props, null, 2)}`;
16
10
 
17
11
  const Wrapper = (props) => (
18
12
  <>
@@ -22,7 +16,7 @@ const Wrapper = (props) => (
22
16
  </>
23
17
  );
24
18
 
25
- const DefaultWrapper = (props) => (
19
+ const DefaultWrapper = (props: Props): React.Node => (
26
20
  <>
27
21
  DefaultWrapper &gt;&gt;&gt;
28
22
  <MyComponent {...props} />
@@ -30,34 +24,26 @@ const DefaultWrapper = (props) => (
30
24
  </>
31
25
  );
32
26
 
33
- const stories: Array<mixed> = Object.values(
34
- fixtures<typeof MyComponent, _>(
35
- {
36
- component: MyComponent,
37
- title: "Testing / Fixtures / DefaultWrapper",
38
- defaultWrapper: DefaultWrapper,
39
- },
40
- (fixture) => {
41
- fixture(
42
- "This is a fixture with some regular props and the default wrapper",
43
- {
44
- see: "this is a prop",
45
- and: "this is another",
46
- },
47
- );
48
-
49
- fixture(
50
- "This fixture uses a custom wrapper",
51
- {
52
- just: "some props again",
53
- like: "this one",
54
- },
55
- Wrapper,
56
- );
57
- },
58
- ) ?? {},
27
+ const fixture = fixtures(DefaultWrapper);
28
+
29
+ export const F1: mixed = fixture(
30
+ "This is a fixture with some regular props and the default wrapper",
31
+ {
32
+ see: "this is a prop",
33
+ and: "this is another",
34
+ },
35
+ );
36
+
37
+ export const F2: mixed = fixture(
38
+ "This fixture uses a custom wrapper",
39
+ {
40
+ just: "some props again",
41
+ like: "this one",
42
+ },
43
+ Wrapper,
59
44
  );
60
45
 
61
- export default stories[0];
62
- export const F1 = stories[1];
63
- export const F2 = stories[2];
46
+ export default {
47
+ title: "Testing / Fixtures / DefaultWrapper",
48
+ component: DefaultWrapper,
49
+ };
@@ -1,55 +1,8 @@
1
1
  // @flow
2
2
  import * as React from "react";
3
- import {getConfiguration} from "./setup.js";
4
- import {combineOptions} from "./combine-options.js";
3
+ import {action} from "@storybook/addon-actions";
5
4
 
6
- import type {FixturesOptions, GetPropsOptions} from "./types.js";
7
-
8
- type FixtureProps<TProps: {...}> =
9
- | $ReadOnly<TProps>
10
- | ((options: $ReadOnly<GetPropsOptions>) => $ReadOnly<TProps>);
11
-
12
- const normalizeOptions = <
13
- TComponent: React.ComponentType<any>,
14
- TProps: React.ElementConfig<TComponent>,
15
- >(
16
- componentOrOptions:
17
- | TComponent
18
- | $ReadOnly<FixturesOptions<TComponent, TProps>>,
19
- ): $ReadOnly<FixturesOptions<TComponent, TProps>> => {
20
- // To differentiate between a React component and a FixturesOptions object,
21
- // we have to do some type checking.
22
- //
23
- // Alternatives I considered were:
24
- // - Use an additional parameter for the options and then do an arg number
25
- // check, but that always makes typing a function harder and often breaks
26
- // types. I didn't want that battle today.
27
- // - Use a tuple when providing component and options with the first element
28
- // being the component and the second being the options. However that
29
- // feels like an obscure API even though it's really easy to do the
30
- // typing.
31
- if (
32
- // Most React components, whether functional or class-based, are
33
- // inherently functions in JavaScript, so a check for functions is
34
- // usually sufficient.
35
- typeof componentOrOptions === "function" ||
36
- // However, the return of React.forwardRef is not a function,
37
- // so we also have to cope with that.
38
- // A forwardRef has $$typeof = Symbol(react.forward_ref) and a
39
- // render function.
40
- // $FlowIgnore[prop-missing]
41
- typeof componentOrOptions.render === "function"
42
- ) {
43
- return {
44
- // $FlowIgnore[incompatible-return]
45
- component: componentOrOptions,
46
- };
47
- }
48
- // We can't test for React.ComponentType at runtime.
49
- // Let's assume our simple heuristic above is sufficient.
50
- // $FlowIgnore[incompatible-return]
51
- return componentOrOptions;
52
- };
5
+ import type {FixtureFn, FixtureProps} from "./types.js";
53
6
 
54
7
  /**
55
8
  * Describe a group of fixtures for a given component.
@@ -57,71 +10,65 @@ const normalizeOptions = <
57
10
  * Only one `fixtures` call should be used per fixture file as it returns
58
11
  * the exports for that file.
59
12
  *
60
- * @param {FixtureOptions<TProps>} options Options describing the
13
+ * @param {component: React.ComponentType<any>} options Options describing the
61
14
  * fixture group.
62
15
  * @param {FixtureFn<TProps> => void} fn A function that provides a `fixture`
63
16
  * function for defining fixtures.
64
- * @returns {Exports} The object to be exported as `module.exports`.
65
- *
66
- * TODO(somewhatabstract): Determine a way around this requirement so we
67
- * can support named exports and default exports via the adapters in a
68
- * deterministic way. Currently this is imposed on us because of how
69
- * storybook, the popular framework, uses both default and named exports for
70
- * its interface.
17
+ * @returns {(
18
+ * description: string,
19
+ * props: FixtureProps<TProps>,
20
+ * wrapper?: React.ComponentType<TProps>,
21
+ * ) => mixed} A function to create a CSF compatible story.
71
22
  */
72
23
  export const fixtures = <
73
24
  TComponent: React.ComponentType<any>,
74
25
  TProps: React.ElementConfig<TComponent>,
75
26
  >(
76
- componentOrOptions:
77
- | TComponent
78
- | $ReadOnly<FixturesOptions<TComponent, TProps>>,
79
- fn: (
80
- fixture: (
81
- description: string,
82
- props: FixtureProps<TProps>,
83
- wrapper?: React.ComponentType<TProps>,
84
- ) => void,
85
- ) => void,
86
- ): ?$ReadOnly<mixed> => {
87
- const {adapter, defaultAdapterOptions} = getConfiguration();
27
+ Component: TComponent,
28
+ ): FixtureFn<TProps> => {
29
+ const templateMap = new WeakMap();
30
+ // We use this to make sure each story gets a unique name.
31
+ let storyNumber = 1;
88
32
 
89
- const {
90
- title,
91
- component,
92
- description: groupDescription,
93
- defaultWrapper,
94
- additionalAdapterOptions,
95
- } = normalizeOptions<TComponent, TProps>(componentOrOptions);
33
+ const getPropsOptions = {
34
+ log: (message, ...args) => action(message)(...args),
35
+ logHandler: action,
36
+ };
96
37
 
97
- // 1. Create a new adapter group.
98
- const group = adapter.declareGroup<TProps>({
99
- title,
100
- description: groupDescription,
101
- getDefaultTitle: () =>
102
- component.displayName || component.name || "Component",
103
- });
38
+ const makeStory = (
39
+ description: string,
40
+ props: FixtureProps<TProps>,
41
+ wrapper: ?React.ComponentType<TProps> = null,
42
+ ): mixed => {
43
+ const storyName = `${storyNumber++} ${description}`;
44
+ const getProps = (options) =>
45
+ typeof props === "function" ? props(options) : props;
104
46
 
105
- // 2. Invoke fn with a function that can add a new fixture.
106
- const addFixture = (description, props, wrapper = null): void => {
107
- group.declareFixture({
108
- description,
109
- getProps: (options) =>
110
- typeof props === "function" ? props(options) : props,
111
- component: wrapper ?? defaultWrapper ?? component,
112
- });
113
- };
114
- fn(addFixture);
47
+ const RealComponent = wrapper || Component;
115
48
 
116
- // 3. Combine the adapter options from the fixture group with the
117
- // defaults from our setup.
118
- const groupAdapterOverrides =
119
- additionalAdapterOptions?.[adapter.name] ?? {};
120
- const combinedAdapterOptions = combineOptions(
121
- defaultAdapterOptions,
122
- groupAdapterOverrides,
123
- );
49
+ // We create a “template” of how args map to rendering
50
+ // for each type of component as the component here could
51
+ // be the component under test, or wrapped in a wrapper
52
+ // component. We don't use decorators for the wrapper
53
+ // because we may not be in a storybook context and it
54
+ // keeps the framework API simpler this way.
55
+ let Template = templateMap.get((RealComponent: any));
56
+ if (Template == null) {
57
+ Template = (args) => <RealComponent {...args} />;
58
+ templateMap.set((RealComponent: any), Template);
59
+ }
124
60
 
125
- // 4. Call close on the group and return the result.
126
- return group.closeGroup(combinedAdapterOptions);
61
+ // Each story that shares that component then reuses that
62
+ // template.
63
+ const story = Template.bind({});
64
+ story.args = getProps(getPropsOptions);
65
+ // Adding a story name here means that we don't have to
66
+ // care about naming the exports correctly, if we don't
67
+ // want (useful if we need to autogenerate or manually
68
+ // expose ESM exports).
69
+ story.storyName = storyName;
70
+
71
+ return story;
72
+ };
73
+ return makeStory;
127
74
  };
@@ -1,6 +1,5 @@
1
1
  // @flow
2
2
  import * as React from "react";
3
- import type {StorybookOptions} from "./adapters/storybook.js";
4
3
 
5
4
  /**
6
5
  * Options injected to the function that returns the fixture props.
@@ -19,194 +18,29 @@ export type GetPropsOptions = {|
19
18
  logHandler: (name: string) => (...args: Array<any>) => void,
20
19
  |};
21
20
 
22
- /**
23
- * Adapter options keyed by the adapter name.
24
- */
25
- export type FixturesAdapterOptions = {|
26
- storybook?: StorybookOptions,
27
- [adapterName: string]: {...},
28
- |};
21
+ export type FixtureProps<TProps: {...}> =
22
+ | $ReadOnly<TProps>
23
+ | ((options: $ReadOnly<GetPropsOptions>) => $ReadOnly<TProps>);
29
24
 
30
25
  /**
31
- * Options to describe a collection of fixtures.
26
+ * A function for defining a fixture.
32
27
  */
33
- export type FixturesOptions<
34
- TComponent: React.ComponentType<any>,
35
- TProps: React.ElementConfig<TComponent>,
36
- > = {|
37
- /**
38
- * The component being tested by the fixtures.
39
- */
40
- component: TComponent,
41
-
28
+ export type FixtureFn<TProps: {...}> = (
42
29
  /**
43
- * Optional title of the fixture collection.
44
- *
45
- * Adapters may enforce a title, otherwise the component name is used.
30
+ * The name of the fixture.
46
31
  */
47
- title?: string,
32
+ description: string,
48
33
 
49
34
  /**
50
- * Optional description of the fixture collection.
35
+ * The props for the fixture or a function that returns the props.
36
+ * The function is injected with an API to facilitate logging.
51
37
  */
52
- description?: string,
38
+ props: FixtureProps<TProps>,
53
39
 
54
40
  /**
55
- * Optional default wrapper to apply around the component under test.
41
+ * An alternative component to render for the fixture.
42
+ * Useful if the fixture requires some additional setup for testing the
43
+ * component.
56
44
  */
57
- defaultWrapper?: React.ComponentType<TProps>,
58
-
59
- /**
60
- * Additional options to apply to specific adapters.
61
- */
62
- additionalAdapterOptions?: FixturesAdapterOptions,
63
- |};
64
-
65
- /**
66
- * Describes a single fixture.
67
- */
68
- export type FixturesAdapterFixtureOptions<TProps: {...}> = {|
69
- /**
70
- * Description of the fixture.
71
- */
72
- +description: string,
73
-
74
- /**
75
- * Method to obtain props for the fixture.
76
- */
77
- +getProps: (options: $ReadOnly<GetPropsOptions>) => $ReadOnly<TProps>,
78
-
79
- /**
80
- * The component to render for this fixture.
81
- */
82
- +component: React.ComponentType<TProps>,
83
- |};
84
-
85
- // TODO(somewhatabstract): Allow for adapters to extend group/fixture options
86
- // with specific support. For example, storybook subcomponents, etc.?
87
-
88
- /**
89
- * Describes a group of fixtures.
90
- */
91
- export type FixturesAdapterGroupOptions = {|
92
- /**
93
- * The title of the group.
94
- *
95
- * If omitted, the adapter is free to generate a default or ask for one
96
- * using the passed getDefaultTitle() function.
97
- */
98
- +title: ?string,
99
-
100
- /**
101
- * Description of the group.
102
- */
103
- +description: ?string,
104
-
105
- /**
106
- * Function that will generate a default title if an adapter cannot
107
- * generate its own.
108
- */
109
- +getDefaultTitle: () => string,
110
- |};
111
-
112
- /**
113
- * Describes props that an adapter will inject for custom mounting components.
114
- */
115
- export type CustomMountProps<TProps: {...}> = {|
116
- /**
117
- * The fixture props for the component to be rendered.
118
- */
119
- props: TProps,
120
-
121
- /**
122
- * The component to render.
123
- */
124
- component: React.ComponentType<TProps>,
125
-
126
- /**
127
- * The log callback for logging information.
128
- */
129
- log: (message: string, ...args: Array<any>) => mixed,
130
- |};
131
-
132
- /**
133
- * Declares the API for describing a fixture group provided by an adapter.
134
- */
135
- export interface FixturesAdapterGroup<
136
- TProps: {...},
137
- TAdapterOptions: {...},
138
- TAdapterExports: {...},
139
- > {
140
- /**
141
- * Declare a fixture.
142
- */
143
- declareFixture(
144
- options: $ReadOnly<FixturesAdapterFixtureOptions<TProps>>,
145
- ): void;
146
-
147
- /**
148
- * Close the group and obtain the exports, if the adapter requires any.
149
- *
150
- * @param {Options} adapterOptions Some options to pass to the adapter.
151
- * Allows callers to tailor things to a specific adapter. How these options
152
- * are used is adapter-specific.
153
- *
154
- * @returns {?Exports} The exports that the adapter requires fixture files
155
- * to export.
156
- */
157
- closeGroup(
158
- adapterOptions: $ReadOnly<Partial<TAdapterOptions>>,
159
- ): ?$ReadOnly<TAdapterExports>;
160
- }
161
-
162
- /**
163
- * Declares the API for an adapter.
164
- */
165
- export interface FixturesAdapter<
166
- TAdapterOptions: {...},
167
- TAdapterExports: {...},
168
- > {
169
- /**
170
- * The name of the adapter.
171
- */
172
- get name(): string;
173
-
174
- /**
175
- * Declare a fixture group.
176
- *
177
- * @returns {AdapterGroup<TProps, TAdapterOptions, TAdapterExports>} The
178
- * declared group.
179
- */
180
- declareGroup<TProps: {...}>(
181
- options: $ReadOnly<FixturesAdapterGroupOptions>,
182
- ): FixturesAdapterGroup<TProps, TAdapterOptions, TAdapterExports>;
183
- }
184
-
185
- /**
186
- * Describes the configuration for the fixture framework.
187
- */
188
- export type FixturesConfiguration<
189
- TAdapterOptions: {...},
190
- TAdapterExports: {...},
191
- > = {|
192
- /**
193
- * The adapter to use for declaring fixtures.
194
- */
195
- +adapter: FixturesAdapter<TAdapterOptions, TAdapterExports>,
196
-
197
- /**
198
- * Default options to apply to every fixture group.
199
- *
200
- * Each top-level option in this object will be merged with the equivalent
201
- * top-level option that a specific fixture requests. Where collisions
202
- * occur, the fixture options win.
203
- */
204
- +defaultAdapterOptions?: $ReadOnly<Partial<TAdapterOptions>>,
205
- |};
206
-
207
- export type FixturesAdapterFactory<
208
- TAdapterOptions: {...},
209
- TAdapterExports: {...},
210
- > = (
211
- MountingComponent: ?React.ComponentType<CustomMountProps<any>>,
212
- ) => FixturesAdapter<TAdapterOptions, TAdapterExports>;
45
+ wrapper?: React.ComponentType<TProps>,
46
+ ) => mixed;
package/src/index.js CHANGED
@@ -1,19 +1,10 @@
1
1
  // @flow
2
2
 
3
3
  // Fixtures framework
4
- export * as fixtureAdapters from "./fixtures/adapters/adapters.js";
5
4
  export {fixtures} from "./fixtures/fixtures.js";
6
- export {setup as setupFixtures} from "./fixtures/setup.js";
7
5
  export type {
8
- CustomMountProps,
9
- FixturesAdapter,
10
- FixturesAdapterFactory,
11
- FixturesAdapterFixtureOptions,
12
- FixturesAdapterGroup,
13
- FixturesAdapterGroupOptions,
14
- FixturesAdapterOptions,
15
- FixturesConfiguration,
16
- FixturesOptions,
6
+ FixtureFn,
7
+ FixtureProps,
17
8
  GetPropsOptions,
18
9
  } from "./fixtures/types.js";
19
10
 
@@ -1,49 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Fixtures / Exports / fixtureAdapters"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # fixtureAdapters
13
-
14
- ```ts
15
- type StoryContext = {|
16
- args: $ReadOnly<any>,
17
- argTypes: $ReadOnly<any>,
18
- globals: $ReadOnlyArray<any>,
19
- hooks: $ReadOnlyArray<any>,
20
- parameters: $ReadOnly<any>,
21
- viewMode: mixed,
22
- |};
23
-
24
- type StorybookOptions = {|
25
- decorators?: Array<
26
- (story: React.ComponentType<any>, context: StoryContext) => React.Node,
27
- >,
28
- parameters?: $ReadOnly<any>,
29
- |};
30
-
31
- type DefaultExport = {|
32
- title?: ?string,
33
- ...StorybookOptions,
34
- |};
35
-
36
- type Exports<TProps: {...}> = {|
37
- default: DefaultExport,
38
- [story: string]: React.ComponentType<TProps>,
39
- |};
40
-
41
-
42
- const fixtureAdapters = {
43
- storybook: AdapterFactory<StorybookOptions, Exports<any>>,
44
- }
45
- ```
46
-
47
- These are the adapters available for use with the fixtures framework. If an adapter is not listed here for the framework you want, you can create your own conforming to the [`FixturesAdapterFactory`](/docs/testing-fixtures-types-fixturesadapterfactory--page) type.
48
-
49
- To configure the fixtures framework, use an adapter with the [`setupFixtures`](/docs/testing-fixtures-exports-setupfixtures--page) function.
@@ -1,22 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Fixtures / Exports / setupFixtures()"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # setupFixtures()
13
-
14
- ```ts
15
- setupFixtures<TAdapterOptions: {...}, TAdapterExports: {...}>(
16
- configuration: $ReadOnly<
17
- FixturesConfiguration<TAdapterOptions, TAdapterExports>,
18
- >,
19
- );
20
- ```
21
-
22
- This method configures the fixtures framework so that it can adapt defined fixtures to the framework that is to be supported. The configuration is of type [`FixturesConfiguration`](/docs/testing-fixtures-types-fixturesconfiguration--page).