@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.
- package/CHANGELOG.md +18 -0
- package/dist/es/index.js +17 -187
- package/dist/index.js +90 -463
- package/package.json +2 -2
- package/src/__docs__/_overview_fixtures.stories.mdx +2 -6
- package/src/__docs__/exports.fixtures.stories.mdx +9 -31
- package/src/__docs__/types.fixture-fn.stories.mdx +46 -0
- package/src/__docs__/types.fixture-props.stories.mdx +20 -0
- package/src/fixtures/__tests__/fixtures.test.js +89 -466
- package/src/fixtures/fixtures.basic.stories.js +30 -50
- package/src/fixtures/fixtures.defaultwrapper.stories.js +26 -40
- package/src/fixtures/fixtures.js +50 -103
- package/src/fixtures/types.js +15 -181
- package/src/index.js +2 -11
- 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 -369
- 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 -128
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-testing
|
|
2
2
|
|
|
3
|
+
## 7.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- aa7993a8: Make sure wrapper component is used when provided
|
|
8
|
+
|
|
9
|
+
## 7.0.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 79a3bc8e: Export more types for the fixtures framework
|
|
14
|
+
|
|
15
|
+
## 7.0.0
|
|
16
|
+
|
|
17
|
+
### Major Changes
|
|
18
|
+
|
|
19
|
+
- d078f526: Simplify fixtures API to target only CSF/storybook
|
|
20
|
+
|
|
3
21
|
## 6.1.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
package/dist/es/index.js
CHANGED
|
@@ -1,208 +1,38 @@
|
|
|
1
|
-
import _extends from '@babel/runtime/helpers/extends';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { action } from '@storybook/addon-actions';
|
|
4
|
-
import { clone } from '@khanacademy/wonder-stuff-core';
|
|
5
3
|
import { InterceptRequests } from '@khanacademy/wonder-blocks-data';
|
|
6
4
|
import { StaticRouter, MemoryRouter, Switch, Route } from 'react-router-dom';
|
|
5
|
+
import _extends from '@babel/runtime/helpers/extends';
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
constructor(closeGroupFn, _options) {
|
|
10
|
-
this.closeGroup = (adapterOptions = null) => {
|
|
11
|
-
if (this._closeGroupFn == null) {
|
|
12
|
-
throw new Error("Group already closed");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
return this._closeGroupFn(this._options, adapterOptions, this._fixtures);
|
|
17
|
-
} finally {
|
|
18
|
-
this._closeGroupFn = null;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
this.declareFixture = options => {
|
|
23
|
-
if (typeof options !== "object" || options === null) {
|
|
24
|
-
throw new TypeError("options must be an object");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (this._closeGroupFn == null) {
|
|
28
|
-
throw new Error("Cannot declare fixtures after closing the group");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
this._fixtures.push(options);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
if (typeof closeGroupFn !== "function") {
|
|
35
|
-
throw new TypeError("closeGroupFn must be a function");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (typeof _options !== "object" || _options === null) {
|
|
39
|
-
throw new TypeError("options must be an object");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
this._closeGroupFn = closeGroupFn;
|
|
43
|
-
this._options = _options;
|
|
44
|
-
this._fixtures = [];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
class Adapter {
|
|
50
|
-
constructor(name, closeGroupFn) {
|
|
51
|
-
if (typeof name !== "string") {
|
|
52
|
-
throw new TypeError("name must be a string");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (name.trim() === "") {
|
|
56
|
-
throw new Error("name must be a non-empty string");
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (typeof closeGroupFn !== "function") {
|
|
60
|
-
throw new TypeError("closeGroupFn must be a function");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
this._name = name;
|
|
64
|
-
this._closeGroupFn = closeGroupFn;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
get name() {
|
|
68
|
-
return this._name;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
declareGroup(options) {
|
|
72
|
-
return new AdapterGroup(this._closeGroupFn, options);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const getAdapter = (MountingComponent = null) => new Adapter("storybook", ({
|
|
78
|
-
title,
|
|
79
|
-
description: groupDescription,
|
|
80
|
-
getDefaultTitle: _
|
|
81
|
-
}, adapterOptions, declaredFixtures) => {
|
|
7
|
+
const fixtures = Component => {
|
|
82
8
|
const templateMap = new WeakMap();
|
|
9
|
+
let storyNumber = 1;
|
|
83
10
|
const getPropsOptions = {
|
|
84
11
|
log: (message, ...args) => action(message).apply(void 0, args),
|
|
85
12
|
logHandler: action
|
|
86
13
|
};
|
|
87
|
-
const exports = declaredFixtures.reduce((acc, {
|
|
88
|
-
description,
|
|
89
|
-
getProps,
|
|
90
|
-
component: Component
|
|
91
|
-
}, i) => {
|
|
92
|
-
const storyName = `${i + 1} ${description}`;
|
|
93
|
-
const exportName = storyName.replace(/\b\w/g, c => c.toUpperCase()).replace(/[^\w]+/g, "").replace(/[_]+/g, "");
|
|
94
|
-
let Template = templateMap.get(Component);
|
|
95
|
-
|
|
96
|
-
if (Template == null) {
|
|
97
|
-
Template = MountingComponent ? args => React.createElement(MountingComponent, {
|
|
98
|
-
component: Component,
|
|
99
|
-
props: args,
|
|
100
|
-
log: getPropsOptions.log
|
|
101
|
-
}) : args => React.createElement(Component, args);
|
|
102
|
-
templateMap.set(Component, Template);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
acc[exportName] = Template.bind({});
|
|
106
|
-
acc[exportName].args = getProps(getPropsOptions);
|
|
107
|
-
acc[exportName].storyName = storyName;
|
|
108
|
-
return acc;
|
|
109
|
-
}, {
|
|
110
|
-
default: _extends({
|
|
111
|
-
title
|
|
112
|
-
}, adapterOptions)
|
|
113
|
-
});
|
|
114
|
-
return Object.freeze(exports);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
var adapters$1 = /*#__PURE__*/Object.freeze({
|
|
118
|
-
__proto__: null,
|
|
119
|
-
storybook: getAdapter
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
let _configuration = null;
|
|
123
|
-
const setup = configuration => {
|
|
124
|
-
_configuration = configuration;
|
|
125
|
-
};
|
|
126
|
-
const getConfiguration = () => {
|
|
127
|
-
if (_configuration == null) {
|
|
128
|
-
throw new Error("Not configured");
|
|
129
|
-
}
|
|
130
14
|
|
|
131
|
-
|
|
132
|
-
}
|
|
15
|
+
const makeStory = (description, props, wrapper = null) => {
|
|
16
|
+
const storyName = `${storyNumber++} ${description}`;
|
|
133
17
|
|
|
134
|
-
const
|
|
135
|
-
const obj2Clone = clone(val2);
|
|
18
|
+
const getProps = options => typeof props === "function" ? props(options) : props;
|
|
136
19
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const val2IsArray = Array.isArray(val2);
|
|
20
|
+
const RealComponent = wrapper || Component;
|
|
21
|
+
let Template = templateMap.get(RealComponent);
|
|
140
22
|
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
} else if (!val1IsArray && !val2IsArray) {
|
|
144
|
-
return _extends({}, val1, obj2Clone);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return obj2Clone;
|
|
149
|
-
};
|
|
23
|
+
if (Template == null) {
|
|
24
|
+
Template = args => React.createElement(RealComponent, args);
|
|
150
25
|
|
|
151
|
-
|
|
152
|
-
const combined = toBeCombined.filter(Boolean).reduce((acc, cur) => {
|
|
153
|
-
for (const key of Object.keys(cur)) {
|
|
154
|
-
acc[key] = combineTopLevel(acc[key], cur[key]);
|
|
26
|
+
templateMap.set(RealComponent, Template);
|
|
155
27
|
}
|
|
156
28
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const normalizeOptions = componentOrOptions => {
|
|
163
|
-
if (typeof componentOrOptions === "function" || typeof componentOrOptions.render === "function") {
|
|
164
|
-
return {
|
|
165
|
-
component: componentOrOptions
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return componentOrOptions;
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const fixtures = (componentOrOptions, fn) => {
|
|
173
|
-
var _additionalAdapterOpt;
|
|
174
|
-
|
|
175
|
-
const {
|
|
176
|
-
adapter,
|
|
177
|
-
defaultAdapterOptions
|
|
178
|
-
} = getConfiguration();
|
|
179
|
-
const {
|
|
180
|
-
title,
|
|
181
|
-
component,
|
|
182
|
-
description: groupDescription,
|
|
183
|
-
defaultWrapper,
|
|
184
|
-
additionalAdapterOptions
|
|
185
|
-
} = normalizeOptions(componentOrOptions);
|
|
186
|
-
const group = adapter.declareGroup({
|
|
187
|
-
title,
|
|
188
|
-
description: groupDescription,
|
|
189
|
-
getDefaultTitle: () => component.displayName || component.name || "Component"
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
const addFixture = (description, props, wrapper = null) => {
|
|
193
|
-
var _ref;
|
|
194
|
-
|
|
195
|
-
group.declareFixture({
|
|
196
|
-
description,
|
|
197
|
-
getProps: options => typeof props === "function" ? props(options) : props,
|
|
198
|
-
component: (_ref = wrapper != null ? wrapper : defaultWrapper) != null ? _ref : component
|
|
199
|
-
});
|
|
29
|
+
const story = Template.bind({});
|
|
30
|
+
story.args = getProps(getPropsOptions);
|
|
31
|
+
story.storyName = storyName;
|
|
32
|
+
return story;
|
|
200
33
|
};
|
|
201
34
|
|
|
202
|
-
|
|
203
|
-
const groupAdapterOverrides = (_additionalAdapterOpt = additionalAdapterOptions == null ? void 0 : additionalAdapterOptions[adapter.name]) != null ? _additionalAdapterOpt : {};
|
|
204
|
-
const combinedAdapterOptions = combineOptions(defaultAdapterOptions, groupAdapterOverrides);
|
|
205
|
-
return group.closeGroup(combinedAdapterOptions);
|
|
35
|
+
return makeStory;
|
|
206
36
|
};
|
|
207
37
|
|
|
208
38
|
const getHref = input => {
|
|
@@ -571,4 +401,4 @@ const hookHarness = makeHookHarness(DefaultAdapters, DefaultConfigs);
|
|
|
571
401
|
|
|
572
402
|
const testHarness = makeTestHarness(DefaultAdapters, DefaultConfigs);
|
|
573
403
|
|
|
574
|
-
export { RespondWith,
|
|
404
|
+
export { RespondWith, fixtures, adapters as harnessAdapters, hookHarness, makeHookHarness, makeTestHarness, mockFetch, mockGqlFetch, testHarness };
|