@khanacademy/wonder-blocks-testing 6.1.0 → 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.
Files changed (38) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/es/index.js +16 -187
  3. package/dist/index.js +87 -461
  4. package/package.json +2 -2
  5. package/src/__docs__/_overview_fixtures.stories.mdx +2 -6
  6. package/src/__docs__/exports.fixtures.stories.mdx +13 -27
  7. package/src/fixtures/__tests__/fixtures.test.js +75 -470
  8. package/src/fixtures/fixtures.basic.stories.js +30 -50
  9. package/src/fixtures/fixtures.defaultwrapper.stories.js +26 -40
  10. package/src/fixtures/fixtures.js +53 -102
  11. package/src/fixtures/types.js +3 -194
  12. package/src/index.js +1 -14
  13. package/src/__docs__/exports.fixture-adapters.stories.mdx +0 -49
  14. package/src/__docs__/exports.setup-fixtures.stories.mdx +0 -22
  15. package/src/__docs__/types.custom-mount-props.stories.mdx +0 -35
  16. package/src/__docs__/types.fixtures-adapter-factory.stories.mdx +0 -23
  17. package/src/__docs__/types.fixtures-adapter-fixture-options.stories.mdx +0 -35
  18. package/src/__docs__/types.fixtures-adapter-group-options.stories.mdx +0 -37
  19. package/src/__docs__/types.fixtures-adapter-group.stories.mdx +0 -43
  20. package/src/__docs__/types.fixtures-adapter-options.stories.mdx +0 -21
  21. package/src/__docs__/types.fixtures-adapter.stories.mdx +0 -35
  22. package/src/__docs__/types.fixtures-configuration.stories.mdx +0 -35
  23. package/src/__docs__/types.fixtures-options.stories.mdx +0 -51
  24. package/src/fixtures/__tests__/combine-options.test.js +0 -65
  25. package/src/fixtures/__tests__/combine-top-level.test.js +0 -100
  26. package/src/fixtures/__tests__/setup.test.js +0 -71
  27. package/src/fixtures/adapters/__tests__/__snapshots__/adapter-group.test.js.snap +0 -9
  28. package/src/fixtures/adapters/__tests__/__snapshots__/adapter.test.js.snap +0 -13
  29. package/src/fixtures/adapters/__tests__/adapter-group.test.js +0 -223
  30. package/src/fixtures/adapters/__tests__/adapter.test.js +0 -97
  31. package/src/fixtures/adapters/__tests__/storybook.test.js +0 -369
  32. package/src/fixtures/adapters/adapter-group.js +0 -88
  33. package/src/fixtures/adapters/adapter.js +0 -63
  34. package/src/fixtures/adapters/adapters.js +0 -2
  35. package/src/fixtures/adapters/storybook.js +0 -128
  36. package/src/fixtures/combine-options.js +0 -25
  37. package/src/fixtures/combine-top-level.js +0 -44
  38. 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.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.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,37 +16,23 @@ 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
+ ): (
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. 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).
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 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).
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
- 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.
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)).