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