@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-testing",
3
- "version": "6.1.0",
3
+ "version": "7.0.2",
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.3",
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 an agnostic way to declare component fixtures that can then be adapted via runtime configuration to the fixture rendering environment of choice.
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. You can configure the framework for your specific environment (such as Storybook) using the [`setupFixtures()`](/docs/testing-fixtures-exports-setupfixtures--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,38 +16,16 @@ type FixtureProps<TProps: {...}> =
16
16
  | $ReadOnly<TProps>
17
17
  | ((options: $ReadOnly<GetPropsOptions>) => $ReadOnly<TProps>);
18
18
 
19
- fixtures<TProps: {...}>(
20
- component: React.ComponentType<TProps>,
21
- fn: (
22
- fixture: (
23
- description: string,
24
- props: FixtureProps<TProps>,
25
- wrapper?: React.ComponentType<TProps>,
26
- ) => void,
27
- ) => void,
28
- ): ?$ReadOnly<mixed>;
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
+ ): FixtureFn<TProps>;
41
25
  ```
42
26
 
43
- The `fixtures()` method is used to define a set of fixtures for a component. It provides a way to describe fixtures as one might describe unit tests. Fixtures are like stories in Storybook (and, if the fixtures framework is configured for storybook, will be stories).
44
-
45
- The return value provides the module exports that your fixture file should export. If your build system supports CommonJS syntax, this can be exported using `module.exports = returnValue`; however, if you need to use ESM syntax, you may need to do something like we do in [our Fixtures Framework example stories](/docs/testing-fixtures-basic--f-1).
46
-
47
- There are two ways to call the `fixtures()` function; with a component and callback, or with a set of [options](/docs/testing-fixtures-types-fixtureoptions--page) and callback.
27
+ 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.
48
28
 
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:
29
+ 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.
50
30
 
51
- - `description: string`: A string describing the fixture. This should be used to explain what the fixture is expected to show.
52
- - `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)).
53
- - `wrapper?: React.ComponentType<TProps>`: An optional component that will be rendered around the fixture. This can be used to wrap the fixture in a component that adds additional functionality, such as a test harness (see [`makeTestHarness`](/docs/testing-test-harness-exports-maketestharness--page)).
31
+ The returned `fixture` function is of type [`FixtureFn<TProps>`](/docs/testing-fixtures-types-fixturefn--page).
@@ -0,0 +1,46 @@
1
+ import {Meta} from "@storybook/addon-docs";
2
+
3
+ <Meta
4
+ title="Testing / Fixtures / Types / FixtureFn"
5
+ parameters={{
6
+ chromatic: {
7
+ disableSnapshot: true,
8
+ },
9
+ }}
10
+ />
11
+
12
+ # FixtureFn
13
+
14
+ ```ts
15
+ /**
16
+ * A function for defining a fixture.
17
+ */
18
+ type FixtureFn<TProps: {...}> = (
19
+ /**
20
+ * The name of the fixture.
21
+ */
22
+ description: string,
23
+
24
+ /**
25
+ * The props for the fixture or a function that returns the props.
26
+ * The function is injected with an API to facilitate logging.
27
+ */
28
+ props: FixtureProps<TProps>,
29
+
30
+ /**
31
+ * An alternative component to render for the fixture.
32
+ * Useful if the fixture requires some additional setup for testing the
33
+ * component.
34
+ */
35
+ wrapper?: React.ComponentType<TProps>,
36
+ ) => mixed;
37
+
38
+ ```
39
+
40
+ The [`fixtures`](/docs/testing-fixtures-exports-fixtures--page) method returns a method of this type, specific to the component that was passed into `fixtures`.
41
+
42
+ This function takes two or three arguments:
43
+
44
+ - `description: string`: A string describing the fixture. This should be used to explain what the fixture is expected to show.
45
+ - `props: FixtureProps<TProps>`: The props that the fixture should be rendered with. See [`FixtureProps`](/docs/testing-fixtures-types-fixtureprops--page).
46
+ - `wrapper?: React.ComponentType<TProps>`: An optional component that will be rendered for the fixture. This can be used to wrap the fixture in a component that adds additional functionality, such as a test harness (see [`makeTestHarness`](/docs/testing-test-harness-exports-maketestharness--page)).
@@ -0,0 +1,20 @@
1
+ import {Meta} from "@storybook/addon-docs";
2
+
3
+ <Meta
4
+ title="Testing / Fixtures / Types / FixtureProps"
5
+ parameters={{
6
+ chromatic: {
7
+ disableSnapshot: true,
8
+ },
9
+ }}
10
+ />
11
+
12
+ # FixtureProps
13
+
14
+ ```ts
15
+ type FixtureProps<TProps: {...}> =
16
+ | $ReadOnly<TProps>
17
+ | ((options: $ReadOnly<GetPropsOptions>) => $ReadOnly<TProps>);
18
+ ```
19
+
20
+ This type describes how props can be provided to a fixture as 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)).