@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-testing",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@babel/runtime": "^7.
|
|
16
|
+
"@babel/runtime": "^7.18.6",
|
|
17
17
|
"@khanacademy/wonder-blocks-data": "^8.0.3"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
@@ -11,12 +11,8 @@ import {Meta} from "@storybook/addon-docs";
|
|
|
11
11
|
|
|
12
12
|
# Fixtures
|
|
13
13
|
|
|
14
|
-
The fixtures framework provides
|
|
14
|
+
The fixtures framework provides a way to declare CSF/Storybook-compatible stories with props type checking (something that is easy to forget when using the standard story API).
|
|
15
15
|
|
|
16
|
-
To use the framework for defining fixtures, import the [`fixtures()`](/docs/testing-fixtures-exports-fixtures--page) method.
|
|
17
|
-
|
|
18
|
-
An adapter to output fixtures for [Storybook](/docs/testing-fixtures-exports-fixtureadapters--page) is included.
|
|
16
|
+
To use the framework for defining fixtures, import the [`fixtures()`](/docs/testing-fixtures-exports-fixtures--page) method.
|
|
19
17
|
|
|
20
18
|
Some examples of this framework in use with Storybook can be seen [here](/docs/testing-fixtures-basic--f-1).
|
|
21
|
-
|
|
22
|
-
Types are also exported to enable the creation of adapters for other environments as you may need.
|
|
@@ -16,37 +16,23 @@ type FixtureProps<TProps: {...}> =
|
|
|
16
16
|
| $ReadOnly<TProps>
|
|
17
17
|
| ((options: $ReadOnly<GetPropsOptions>) => $ReadOnly<TProps>);
|
|
18
18
|
|
|
19
|
-
fixtures<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
fixtures<TProps: {...}>(
|
|
32
|
-
options: $ReadOnly<FixturesOptions<TProps>>,
|
|
33
|
-
fn: (
|
|
34
|
-
fixture: (
|
|
35
|
-
description: string,
|
|
36
|
-
props: FixtureProps<TProps>,
|
|
37
|
-
wrapper?: React.ComponentType<TProps>,
|
|
38
|
-
) => void,
|
|
39
|
-
) => void,
|
|
40
|
-
): ?$ReadOnly<mixed>;
|
|
19
|
+
fixtures<
|
|
20
|
+
TComponent: React.ComponentType<any>,
|
|
21
|
+
TProps: React.ElementConfig<TComponent>,
|
|
22
|
+
>(
|
|
23
|
+
Component: TComponent,
|
|
24
|
+
): (
|
|
25
|
+
description: string,
|
|
26
|
+
props: FixtureProps<TProps>,
|
|
27
|
+
wrapper?: React.ComponentType<TProps>,
|
|
28
|
+
) => void;
|
|
41
29
|
```
|
|
42
30
|
|
|
43
|
-
The `fixtures()` method is used to define a set of fixtures for a component.
|
|
31
|
+
The `fixtures()` method is used to define a set of fixtures for a component. Each fixture is a story compatible with the CSF format used by Storybook.
|
|
44
32
|
|
|
45
|
-
The
|
|
33
|
+
The method returned by `fixtures(Component)` is a strongly-typed call for generating a named story with the given args, and using the given wrapper component, if provided. See [our Fixtures Framework example stories](/docs/testing-fixtures-basic--f-1) for examples.
|
|
46
34
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
The second argument is a callback in which you should define your fixture susing the passed `fixture` function (the first and only argument of the callback). The `fixture` function takes two or three arguments:
|
|
35
|
+
The `fixture` function takes two or three arguments:
|
|
50
36
|
|
|
51
37
|
- `description: string`: A string describing the fixture. This should be used to explain what the fixture is expected to show.
|
|
52
38
|
- `props: FixtureProps<TProps>`: The props that the fixture should be rendered with. This can be either a plain object, or a function that returns a plain object. The function will be called with an API to assist in generating the props (see [`GetPropsOptions`](/docs/testing-fixtures-types-getpropsoptions--page)).
|
|
@@ -17,9 +17,36 @@ type GetPropsOptions = {|
|
|
|
17
17
|
* A function to call that will log output.
|
|
18
18
|
*/
|
|
19
19
|
log: (message: string, ...args: Array<any>) => void,
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A function to make a handler that will log all arguments with the given
|
|
23
|
+
* name or message. Useful for logging events as it avoids the boilerplate
|
|
24
|
+
* of the `log` function.
|
|
25
|
+
*/
|
|
26
|
+
logHandler: (name: string) => (...args: Array<any>) => void,
|
|
20
27
|
|};
|
|
21
28
|
```
|
|
22
29
|
|
|
23
30
|
A fixture can provide a callback that the framework invokes to obtain the props for the fixture component. This callback takes a single argument of type `GetPropsOptions`.
|
|
24
31
|
|
|
25
|
-
This has
|
|
32
|
+
This has two calls available.
|
|
33
|
+
|
|
34
|
+
The `log` callback is for logging output in the context of the fixture. This can be useful for logging information during your fixture. However, in many situations, it is easier to use the `logHandler` callback. The `logHandler` callback takes a single argument of type `string` and returns a function that logs all arguments with the given name or message, allowing easy creation of event handlers that will log that event and its arguments.
|
|
35
|
+
|
|
36
|
+
For example:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
fixture("My fixture that does logging", ({logHandler}) => ({
|
|
40
|
+
onClick: logHandler("onClick"),
|
|
41
|
+
}));
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
is equivalent to:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
fixture("My fixture that does logging", ({log}) => ({
|
|
48
|
+
onClick: (...args) => log("onClick", ...args),
|
|
49
|
+
}));
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
|