@khanacademy/wonder-blocks-testing 7.1.10 → 7.1.11
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 +25 -0
- package/dist/es/index.js +183 -120
- package/dist/fetch/fetch-request-matches-mock.d.ts +5 -0
- package/dist/fetch/fetch-request-matches-mock.js.flow +17 -0
- package/dist/fetch/mock-fetch.d.ts +5 -0
- package/dist/fetch/mock-fetch.js.flow +13 -0
- package/dist/fetch/types.d.ts +9 -0
- package/dist/fetch/types.js.flow +19 -0
- package/dist/fixtures/fixtures.basic.stories.d.ts +13 -0
- package/dist/fixtures/fixtures.basic.stories.js.flow +22 -0
- package/dist/fixtures/fixtures.d.ts +19 -0
- package/dist/fixtures/fixtures.defaultwrapper.stories.d.ts +9 -0
- package/dist/fixtures/fixtures.defaultwrapper.stories.js.flow +17 -0
- package/dist/fixtures/fixtures.js.flow +33 -0
- package/dist/fixtures/types.d.ts +36 -0
- package/dist/fixtures/types.js.flow +37 -0
- package/dist/gql/gql-request-matches-mock.d.ts +3 -0
- package/dist/gql/gql-request-matches-mock.js.flow +15 -0
- package/dist/gql/mock-gql-fetch.d.ts +5 -0
- package/dist/gql/mock-gql-fetch.js.flow +13 -0
- package/dist/gql/types.d.ts +15 -0
- package/dist/gql/types.js.flow +39 -0
- package/dist/harness/adapters/adapters.d.ts +35 -0
- package/dist/harness/adapters/adapters.js.flow +69 -0
- package/dist/harness/adapters/css.d.ts +12 -0
- package/dist/harness/adapters/css.js.flow +23 -0
- package/dist/harness/adapters/data.d.ts +18 -0
- package/dist/harness/adapters/data.js.flow +32 -0
- package/dist/harness/adapters/portal.d.ts +12 -0
- package/dist/harness/adapters/portal.js.flow +18 -0
- package/dist/harness/adapters/router.d.ts +94 -0
- package/dist/harness/adapters/router.js.flow +122 -0
- package/dist/harness/hook-harness.d.ts +13 -0
- package/dist/harness/hook-harness.js.flow +23 -0
- package/dist/harness/make-hook-harness.d.ts +17 -0
- package/dist/harness/make-hook-harness.js.flow +42 -0
- package/dist/harness/make-test-harness.d.ts +18 -0
- package/dist/harness/make-test-harness.js.flow +48 -0
- package/dist/harness/render-adapters.d.ts +6 -0
- package/dist/harness/render-adapters.js.flow +24 -0
- package/dist/harness/test-harness.d.ts +32 -0
- package/dist/harness/test-harness.js.flow +83 -0
- package/dist/harness/types.d.ts +46 -0
- package/dist/harness/types.js.flow +66 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +185 -127
- package/dist/index.js.flow +26 -2
- package/dist/mock-requester.d.ts +5 -0
- package/dist/mock-requester.js.flow +22 -0
- package/dist/respond-with.d.ts +57 -0
- package/dist/respond-with.js.flow +91 -0
- package/dist/response-impl.d.ts +1 -0
- package/dist/response-impl.js.flow +8 -0
- package/dist/settle-controller.d.ts +19 -0
- package/dist/settle-controller.js.flow +26 -0
- package/dist/settle-signal.d.ts +18 -0
- package/dist/settle-signal.js.flow +26 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.js.flow +46 -0
- package/package.json +6 -6
- package/src/__tests__/{mock-requester.test.js → mock-requester.test.ts} +1 -2
- package/src/__tests__/{respond-with.test.js → respond-with.test.ts} +0 -1
- package/src/__tests__/response-impl.test.js +1 -1
- package/src/__tests__/{settle-controller.test.js → settle-controller.test.ts} +0 -1
- package/src/__tests__/{settle-signal.test.js → settle-signal.test.ts} +0 -1
- package/src/fetch/__tests__/__snapshots__/{mock-fetch.test.js.snap → mock-fetch.test.ts.snap} +3 -3
- package/src/fetch/__tests__/{fetch-request-matches-mock.test.js → fetch-request-matches-mock.test.ts} +5 -6
- package/src/fetch/__tests__/{mock-fetch.test.js → mock-fetch.test.ts} +1 -2
- package/src/fetch/{fetch-request-matches-mock.js → fetch-request-matches-mock.ts} +3 -2
- package/src/fetch/{mock-fetch.js → mock-fetch.ts} +2 -3
- package/src/fetch/{types.js → types.ts} +5 -6
- package/src/fixtures/__tests__/{fixtures.test.js → fixtures.test.tsx} +6 -4
- package/src/fixtures/{fixtures.basic.stories.js → fixtures.basic.stories.tsx} +16 -13
- package/src/fixtures/{fixtures.defaultwrapper.stories.js → fixtures.defaultwrapper.stories.tsx} +8 -8
- package/src/fixtures/{fixtures.js → fixtures.tsx} +16 -11
- package/src/fixtures/{types.js → types.ts} +9 -13
- package/src/gql/__tests__/{gql-request-matches-mock.test.js → gql-request-matches-mock.test.ts} +17 -18
- package/src/gql/__tests__/{mock-gql-fetch.test.js → mock-gql-fetch.test.tsx} +44 -45
- package/src/gql/__tests__/{wb-data-integration.test.js → wb-data-integration.test.tsx} +21 -22
- package/src/gql/{gql-request-matches-mock.js → gql-request-matches-mock.ts} +1 -4
- package/src/gql/{mock-gql-fetch.js → mock-gql-fetch.ts} +3 -6
- package/src/gql/types.ts +33 -0
- package/src/harness/__tests__/{hook-harness.test.js → hook-harness.test.ts} +5 -6
- package/src/harness/__tests__/{make-hook-harness.test.js → make-hook-harness.test.tsx} +10 -11
- package/src/harness/__tests__/{make-test-harness.test.js → make-test-harness.test.tsx} +4 -5
- package/src/harness/__tests__/{render-adapters.test.js → render-adapters.test.tsx} +8 -9
- package/src/harness/__tests__/{test-harness.test.js → test-harness.test.ts} +5 -6
- package/src/harness/__tests__/{types.flowtest.js → types.flowtest.tsx} +24 -27
- package/src/harness/adapters/__tests__/{css.test.js → css.test.tsx} +2 -3
- package/src/harness/adapters/__tests__/{data.test.js → data.test.tsx} +4 -3
- package/src/harness/adapters/__tests__/{portal.test.js → portal.test.tsx} +0 -1
- package/src/harness/adapters/__tests__/{router.test.js → router.test.tsx} +75 -56
- package/src/harness/adapters/{adapters.js → adapters.ts} +1 -2
- package/src/harness/adapters/{css.js → css.tsx} +21 -18
- package/src/harness/adapters/{data.js → data.tsx} +7 -5
- package/src/harness/adapters/{portal.js → portal.tsx} +3 -4
- package/src/harness/adapters/router.tsx +218 -0
- package/src/harness/{hook-harness.js → hook-harness.ts} +2 -3
- package/src/harness/{make-hook-harness.js → make-hook-harness.ts} +6 -6
- package/src/harness/{make-test-harness.js → make-test-harness.tsx} +17 -20
- package/src/harness/{render-adapters.js → render-adapters.ts} +4 -4
- package/src/harness/{test-harness.js → test-harness.ts} +1 -12
- package/src/harness/{types.js → types.ts} +14 -12
- package/src/{index.js → index.ts} +0 -2
- package/src/{mock-requester.js → mock-requester.ts} +4 -3
- package/src/{respond-with.js → respond-with.ts} +42 -37
- package/src/{response-impl.js → response-impl.ts} +1 -2
- package/src/{settle-controller.js → settle-controller.ts} +9 -7
- package/src/{settle-signal.js → settle-signal.ts} +10 -7
- package/src/types.ts +40 -0
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/__docs__/_overview_.stories.mdx +0 -18
- package/src/__docs__/_overview_fixtures.stories.mdx +0 -18
- package/src/__docs__/_overview_mocking.stories.mdx +0 -14
- package/src/__docs__/_overview_test_harness.stories.mdx +0 -18
- package/src/__docs__/exports.fixtures.stories.mdx +0 -31
- package/src/__docs__/exports.harness-adapters.stories.mdx +0 -187
- package/src/__docs__/exports.hook-harness.stories.mdx +0 -22
- package/src/__docs__/exports.make-hook-harness.stories.mdx +0 -25
- package/src/__docs__/exports.make-test-harness.stories.mdx +0 -28
- package/src/__docs__/exports.mock-fetch.stories.mdx +0 -40
- package/src/__docs__/exports.mock-gql-fetch.stories.mdx +0 -64
- package/src/__docs__/exports.respond-with.stories.mdx +0 -84
- package/src/__docs__/exports.settle-controller.stories.mdx +0 -32
- package/src/__docs__/exports.test-harness.stories.mdx +0 -23
- package/src/__docs__/types.fetch-mock-fn.stories.mdx +0 -22
- package/src/__docs__/types.fetch-mock-operation.stories.mdx +0 -18
- package/src/__docs__/types.fixture-fn.stories.mdx +0 -46
- package/src/__docs__/types.fixture-props.stories.mdx +0 -20
- package/src/__docs__/types.get-props-options.stories.mdx +0 -52
- package/src/__docs__/types.gql-fetch-mock-fn.stories.mdx +0 -27
- package/src/__docs__/types.gql-mock-operation.stories.mdx +0 -26
- package/src/__docs__/types.mock-response.stories.mdx +0 -22
- package/src/__docs__/types.test-harness-adapter.stories.mdx +0 -21
- package/src/__docs__/types.test-harness-adapters.stories.mdx +0 -46
- package/src/__docs__/types.test-harness-config.stories.mdx +0 -18
- package/src/__docs__/types.test-harness-configs.stories.mdx +0 -59
- package/src/gql/types.js +0 -34
- package/src/harness/adapters/router.js +0 -206
- package/src/types.js +0 -39
- /package/src/harness/adapters/__tests__/__snapshots__/{router.test.js.snap → router.test.tsx.snap} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-testing
|
|
2
2
|
|
|
3
|
+
## 7.1.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 873f4a14: Update type narrowing logic to work better with TypeScript
|
|
8
|
+
- d816af08: Update build and test configs use TypeScript
|
|
9
|
+
- 3891f544: Update babel config to include plugins that Storybook needed
|
|
10
|
+
- 3813715d: Update wonder-stuff dependencies (non-functional changes)
|
|
11
|
+
- 0d28bb1c: Configured TypeScript
|
|
12
|
+
- 3d05f764: Fix HOCs and other type errors
|
|
13
|
+
- c2ec4902: Update eslint configuration, fix lint
|
|
14
|
+
- 2983c05b: Include 'types' field in package.json
|
|
15
|
+
- 77ff6a66: Generate Flow types from TypeScript types
|
|
16
|
+
- ec8d4b7f: Fix miscellaneous TypeScript errors
|
|
17
|
+
- Updated dependencies [d816af08]
|
|
18
|
+
- Updated dependencies [3891f544]
|
|
19
|
+
- Updated dependencies [3813715d]
|
|
20
|
+
- Updated dependencies [0d28bb1c]
|
|
21
|
+
- Updated dependencies [3d05f764]
|
|
22
|
+
- Updated dependencies [c2ec4902]
|
|
23
|
+
- Updated dependencies [2983c05b]
|
|
24
|
+
- Updated dependencies [77ff6a66]
|
|
25
|
+
- Updated dependencies [ec8d4b7f]
|
|
26
|
+
- @khanacademy/wonder-blocks-data@10.1.1
|
|
27
|
+
|
|
3
28
|
## 7.1.10
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
package/dist/es/index.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { action } from '@storybook/addon-actions';
|
|
3
|
-
import _classPrivateFieldLooseBase from '@babel/runtime/helpers/classPrivateFieldLooseBase';
|
|
4
|
-
import _classPrivateFieldLooseKey from '@babel/runtime/helpers/classPrivateFieldLooseKey';
|
|
5
3
|
import { InterceptRequests } from '@khanacademy/wonder-blocks-data';
|
|
6
4
|
import { StaticRouter, MemoryRouter, Switch, Route } from 'react-router-dom';
|
|
7
|
-
import _extends from '@babel/runtime/helpers/extends';
|
|
8
5
|
|
|
9
6
|
const fixtures = Component => {
|
|
10
7
|
const templateMap = new WeakMap();
|
|
@@ -13,27 +10,20 @@ const fixtures = Component => {
|
|
|
13
10
|
log: (message, ...args) => action(message).apply(void 0, args),
|
|
14
11
|
logHandler: action
|
|
15
12
|
};
|
|
16
|
-
|
|
17
13
|
const makeStory = (description, props, wrapper = null) => {
|
|
18
14
|
const storyName = `${storyNumber++} ${description}`;
|
|
19
|
-
|
|
20
15
|
const getProps = options => typeof props === "function" ? props(options) : props;
|
|
21
|
-
|
|
22
16
|
const RealComponent = wrapper || Component;
|
|
23
17
|
let Template = templateMap.get(RealComponent);
|
|
24
|
-
|
|
25
18
|
if (Template == null) {
|
|
26
19
|
Template = args => React.createElement(RealComponent, args);
|
|
27
|
-
|
|
28
20
|
templateMap.set(RealComponent, Template);
|
|
29
21
|
}
|
|
30
|
-
|
|
31
22
|
const story = Template.bind({});
|
|
32
23
|
story.args = getProps(getPropsOptions);
|
|
33
24
|
story.storyName = storyName;
|
|
34
25
|
return story;
|
|
35
26
|
};
|
|
36
|
-
|
|
37
27
|
return makeStory;
|
|
38
28
|
};
|
|
39
29
|
|
|
@@ -48,10 +38,8 @@ const getHref = input => {
|
|
|
48
38
|
throw new Error(`Unsupported input type`);
|
|
49
39
|
}
|
|
50
40
|
};
|
|
51
|
-
|
|
52
41
|
const fetchRequestMatchesMock = (mock, input, init) => {
|
|
53
42
|
const href = getHref(input);
|
|
54
|
-
|
|
55
43
|
if (typeof mock === "string") {
|
|
56
44
|
return href === mock;
|
|
57
45
|
} else if (mock instanceof RegExp) {
|
|
@@ -63,26 +51,22 @@ const fetchRequestMatchesMock = (mock, input, init) => {
|
|
|
63
51
|
|
|
64
52
|
const mockRequester = (operationMatcher, operationToString) => {
|
|
65
53
|
const mocks = [];
|
|
66
|
-
|
|
67
54
|
const mockFn = (...args) => {
|
|
68
55
|
for (const mock of mocks) {
|
|
69
56
|
if (mock.onceOnly && mock.used) {
|
|
70
57
|
continue;
|
|
71
58
|
}
|
|
72
|
-
|
|
73
59
|
if (operationMatcher.apply(void 0, [mock.operation].concat(args))) {
|
|
74
60
|
mock.used = true;
|
|
75
61
|
return mock.response();
|
|
76
62
|
}
|
|
77
63
|
}
|
|
78
|
-
|
|
64
|
+
const operation = operationToString.apply(void 0, args);
|
|
79
65
|
return Promise.reject(new Error(`No matching mock response found for request:
|
|
80
|
-
${
|
|
66
|
+
${operation}`));
|
|
81
67
|
};
|
|
82
|
-
|
|
83
68
|
const addMockedOperation = (operation, response, onceOnly) => {
|
|
84
69
|
const mockResponse = () => response.toPromise();
|
|
85
|
-
|
|
86
70
|
mocks.push({
|
|
87
71
|
operation,
|
|
88
72
|
response: mockResponse,
|
|
@@ -91,104 +75,58 @@ const mockRequester = (operationMatcher, operationToString) => {
|
|
|
91
75
|
});
|
|
92
76
|
return mockFn;
|
|
93
77
|
};
|
|
94
|
-
|
|
95
78
|
mockFn.mockOperation = (operation, response) => addMockedOperation(operation, response, false);
|
|
96
|
-
|
|
97
79
|
mockFn.mockOperationOnce = (operation, response) => addMockedOperation(operation, response, true);
|
|
98
|
-
|
|
99
80
|
return mockFn;
|
|
100
81
|
};
|
|
101
82
|
|
|
102
83
|
const mockFetch = () => mockRequester(fetchRequestMatchesMock, (input, init) => `Input: ${typeof input === "string" ? input : JSON.stringify(input, null, 2)}
|
|
103
|
-
|
|
84
|
+
Options: ${init == null ? "None" : JSON.stringify(init, null, 2)}`);
|
|
104
85
|
|
|
105
86
|
const safeHasOwnProperty = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
106
|
-
|
|
107
87
|
const areObjectsEqual = (a, b) => {
|
|
108
88
|
if (a === b) {
|
|
109
89
|
return true;
|
|
110
90
|
}
|
|
111
|
-
|
|
112
91
|
if (a == null || b == null) {
|
|
113
92
|
return false;
|
|
114
93
|
}
|
|
115
|
-
|
|
116
94
|
if (typeof a !== "object" || typeof b !== "object") {
|
|
117
95
|
return false;
|
|
118
96
|
}
|
|
119
|
-
|
|
120
97
|
const aKeys = Object.keys(a);
|
|
121
98
|
const bKeys = Object.keys(b);
|
|
122
|
-
|
|
123
99
|
if (aKeys.length !== bKeys.length) {
|
|
124
100
|
return false;
|
|
125
101
|
}
|
|
126
|
-
|
|
127
102
|
for (let i = 0; i < aKeys.length; i++) {
|
|
128
103
|
const key = aKeys[i];
|
|
129
|
-
|
|
130
104
|
if (!safeHasOwnProperty(b, key) || !areObjectsEqual(a[key], b[key])) {
|
|
131
105
|
return false;
|
|
132
106
|
}
|
|
133
107
|
}
|
|
134
|
-
|
|
135
108
|
return true;
|
|
136
109
|
};
|
|
137
|
-
|
|
138
110
|
const gqlRequestMatchesMock = (mock, operation, variables, context) => {
|
|
139
111
|
if (mock.operation.id !== operation.id || mock.operation.type !== operation.type) {
|
|
140
112
|
return false;
|
|
141
113
|
}
|
|
142
|
-
|
|
143
114
|
if (mock.variables != null) {
|
|
144
115
|
if (!areObjectsEqual(mock.variables, variables)) {
|
|
145
116
|
return false;
|
|
146
117
|
}
|
|
147
118
|
}
|
|
148
|
-
|
|
149
119
|
if (mock.context != null) {
|
|
150
120
|
if (!areObjectsEqual(mock.context, context)) {
|
|
151
121
|
return false;
|
|
152
122
|
}
|
|
153
123
|
}
|
|
154
|
-
|
|
155
124
|
return true;
|
|
156
125
|
};
|
|
157
126
|
|
|
158
127
|
const mockGqlFetch = () => mockRequester(gqlRequestMatchesMock, (operation, variables, context) => `Operation: ${operation.type} ${operation.id}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
var _settled = _classPrivateFieldLooseKey("settled");
|
|
163
|
-
|
|
164
|
-
class SettleSignal extends EventTarget {
|
|
165
|
-
constructor(setSettleFn = null) {
|
|
166
|
-
super();
|
|
167
|
-
Object.defineProperty(this, _settled, {
|
|
168
|
-
writable: true,
|
|
169
|
-
value: false
|
|
170
|
-
});
|
|
171
|
-
setSettleFn == null ? void 0 : setSettleFn(() => {
|
|
172
|
-
if (_classPrivateFieldLooseBase(this, _settled)[_settled]) {
|
|
173
|
-
throw new Error("SettleSignal already settled");
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
_classPrivateFieldLooseBase(this, _settled)[_settled] = true;
|
|
177
|
-
this.dispatchEvent(new Event("settled"));
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
static settle() {
|
|
182
|
-
const signal = new SettleSignal();
|
|
183
|
-
_classPrivateFieldLooseBase(signal, _settled)[_settled] = true;
|
|
184
|
-
return signal;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
get settled() {
|
|
188
|
-
return _classPrivateFieldLooseBase(this, _settled)[_settled];
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
}
|
|
128
|
+
Variables: ${variables == null ? "None" : JSON.stringify(variables, null, 2)}
|
|
129
|
+
Context: ${JSON.stringify(context, null, 2)}`);
|
|
192
130
|
|
|
193
131
|
const ResponseImpl = typeof Response === "undefined" ? require("node-fetch").Response : Response;
|
|
194
132
|
|
|
@@ -200,7 +138,6 @@ const textResponse = (text, statusCode, signal) => ({
|
|
|
200
138
|
signal
|
|
201
139
|
})
|
|
202
140
|
});
|
|
203
|
-
|
|
204
141
|
const rejectResponse = (error, signal) => ({
|
|
205
142
|
toPromise: () => makeMockResponse({
|
|
206
143
|
type: "reject",
|
|
@@ -208,7 +145,6 @@ const rejectResponse = (error, signal) => ({
|
|
|
208
145
|
signal
|
|
209
146
|
})
|
|
210
147
|
});
|
|
211
|
-
|
|
212
148
|
const RespondWith = Object.freeze({
|
|
213
149
|
text: (text, statusCode = 200, signal = null) => textResponse(text, statusCode, signal),
|
|
214
150
|
json: (json, signal = null) => textResponse(() => JSON.stringify(json), 200, signal),
|
|
@@ -226,7 +162,6 @@ const RespondWith = Object.freeze({
|
|
|
226
162
|
if (statusCode < 300) {
|
|
227
163
|
throw new Error(`${statusCode} is not a valid error status code`);
|
|
228
164
|
}
|
|
229
|
-
|
|
230
165
|
return textResponse("{}", statusCode, signal);
|
|
231
166
|
},
|
|
232
167
|
nonGraphQLBody: (signal = null) => textResponse(() => JSON.stringify({
|
|
@@ -239,26 +174,21 @@ const RespondWith = Object.freeze({
|
|
|
239
174
|
}))
|
|
240
175
|
}), 200, signal)
|
|
241
176
|
});
|
|
242
|
-
|
|
243
177
|
const callOnSettled = (signal, fn) => {
|
|
244
178
|
if (signal == null || signal.settled) {
|
|
245
179
|
fn();
|
|
246
180
|
return;
|
|
247
181
|
}
|
|
248
|
-
|
|
249
182
|
const onSettled = () => {
|
|
250
183
|
signal.removeEventListener("settled", onSettled);
|
|
251
184
|
fn();
|
|
252
185
|
};
|
|
253
|
-
|
|
254
186
|
signal.addEventListener("settled", onSettled);
|
|
255
187
|
};
|
|
256
|
-
|
|
257
188
|
const makeMockResponse = response => {
|
|
258
189
|
const {
|
|
259
190
|
signal
|
|
260
191
|
} = response;
|
|
261
|
-
|
|
262
192
|
switch (response.type) {
|
|
263
193
|
case "text":
|
|
264
194
|
return new Promise((resolve, reject) => {
|
|
@@ -269,17 +199,14 @@ const makeMockResponse = response => {
|
|
|
269
199
|
}));
|
|
270
200
|
});
|
|
271
201
|
});
|
|
272
|
-
|
|
273
202
|
case "reject":
|
|
274
203
|
return new Promise((resolve, reject) => {
|
|
275
204
|
callOnSettled(signal, () => reject(response.error instanceof Error ? response.error : response.error()));
|
|
276
205
|
});
|
|
277
|
-
|
|
278
206
|
default:
|
|
279
207
|
if (process.env.NODE_ENV !== "production") {
|
|
280
208
|
throw new Error(`Unknown response type: ${response.type}`);
|
|
281
209
|
}
|
|
282
|
-
|
|
283
210
|
return makeMockResponse({
|
|
284
211
|
type: "reject",
|
|
285
212
|
error: new Error("Unknown response type"),
|
|
@@ -288,35 +215,179 @@ const makeMockResponse = response => {
|
|
|
288
215
|
}
|
|
289
216
|
};
|
|
290
217
|
|
|
291
|
-
|
|
218
|
+
function _typeof(obj) {
|
|
219
|
+
"@babel/helpers - typeof";
|
|
292
220
|
|
|
293
|
-
|
|
221
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
222
|
+
return typeof obj;
|
|
223
|
+
} : function (obj) {
|
|
224
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
225
|
+
}, _typeof(obj);
|
|
226
|
+
}
|
|
294
227
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
writable: true,
|
|
303
|
-
value: void 0
|
|
304
|
-
});
|
|
305
|
-
_classPrivateFieldLooseBase(this, _signal)[_signal] = new SettleSignal(settleFn => _classPrivateFieldLooseBase(this, _settleFn)[_settleFn] = settleFn);
|
|
228
|
+
function _toPrimitive(input, hint) {
|
|
229
|
+
if (_typeof(input) !== "object" || input === null) return input;
|
|
230
|
+
var prim = input[Symbol.toPrimitive];
|
|
231
|
+
if (prim !== undefined) {
|
|
232
|
+
var res = prim.call(input, hint || "default");
|
|
233
|
+
if (_typeof(res) !== "object") return res;
|
|
234
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
306
235
|
}
|
|
236
|
+
return (hint === "string" ? String : Number)(input);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function _toPropertyKey(arg) {
|
|
240
|
+
var key = _toPrimitive(arg, "string");
|
|
241
|
+
return _typeof(key) === "symbol" ? key : String(key);
|
|
242
|
+
}
|
|
307
243
|
|
|
308
|
-
|
|
309
|
-
|
|
244
|
+
function _defineProperties(target, props) {
|
|
245
|
+
for (var i = 0; i < props.length; i++) {
|
|
246
|
+
var descriptor = props[i];
|
|
247
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
248
|
+
descriptor.configurable = true;
|
|
249
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
250
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
310
251
|
}
|
|
252
|
+
}
|
|
253
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
254
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
255
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
256
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
257
|
+
writable: false
|
|
258
|
+
});
|
|
259
|
+
return Constructor;
|
|
260
|
+
}
|
|
311
261
|
|
|
312
|
-
|
|
313
|
-
|
|
262
|
+
function _setPrototypeOf(o, p) {
|
|
263
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
264
|
+
o.__proto__ = p;
|
|
265
|
+
return o;
|
|
266
|
+
};
|
|
267
|
+
return _setPrototypeOf(o, p);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function _inheritsLoose(subClass, superClass) {
|
|
271
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
272
|
+
subClass.prototype.constructor = subClass;
|
|
273
|
+
_setPrototypeOf(subClass, superClass);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function _getPrototypeOf(o) {
|
|
277
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
|
278
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
279
|
+
};
|
|
280
|
+
return _getPrototypeOf(o);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function _isNativeFunction(fn) {
|
|
284
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function _isNativeReflectConstruct() {
|
|
288
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
289
|
+
if (Reflect.construct.sham) return false;
|
|
290
|
+
if (typeof Proxy === "function") return true;
|
|
291
|
+
try {
|
|
292
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
293
|
+
return true;
|
|
294
|
+
} catch (e) {
|
|
295
|
+
return false;
|
|
314
296
|
}
|
|
297
|
+
}
|
|
315
298
|
|
|
299
|
+
function _construct(Parent, args, Class) {
|
|
300
|
+
if (_isNativeReflectConstruct()) {
|
|
301
|
+
_construct = Reflect.construct.bind();
|
|
302
|
+
} else {
|
|
303
|
+
_construct = function _construct(Parent, args, Class) {
|
|
304
|
+
var a = [null];
|
|
305
|
+
a.push.apply(a, args);
|
|
306
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
307
|
+
var instance = new Constructor();
|
|
308
|
+
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
309
|
+
return instance;
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
return _construct.apply(null, arguments);
|
|
316
313
|
}
|
|
317
314
|
|
|
318
|
-
|
|
315
|
+
function _wrapNativeSuper(Class) {
|
|
316
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
317
|
+
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
318
|
+
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
319
|
+
if (typeof Class !== "function") {
|
|
320
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
321
|
+
}
|
|
322
|
+
if (typeof _cache !== "undefined") {
|
|
323
|
+
if (_cache.has(Class)) return _cache.get(Class);
|
|
324
|
+
_cache.set(Class, Wrapper);
|
|
325
|
+
}
|
|
326
|
+
function Wrapper() {
|
|
327
|
+
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
328
|
+
}
|
|
329
|
+
Wrapper.prototype = Object.create(Class.prototype, {
|
|
330
|
+
constructor: {
|
|
331
|
+
value: Wrapper,
|
|
332
|
+
enumerable: false,
|
|
333
|
+
writable: true,
|
|
334
|
+
configurable: true
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
return _setPrototypeOf(Wrapper, Class);
|
|
338
|
+
};
|
|
339
|
+
return _wrapNativeSuper(Class);
|
|
340
|
+
}
|
|
319
341
|
|
|
342
|
+
let SettleSignal = function (_EventTarget) {
|
|
343
|
+
_inheritsLoose(SettleSignal, _EventTarget);
|
|
344
|
+
function SettleSignal(setSettleFn = null) {
|
|
345
|
+
var _this;
|
|
346
|
+
_this = _EventTarget.call(this) || this;
|
|
347
|
+
_this._settled = false;
|
|
348
|
+
setSettleFn == null ? void 0 : setSettleFn(() => {
|
|
349
|
+
if (_this._settled) {
|
|
350
|
+
throw new Error("SettleSignal already settled");
|
|
351
|
+
}
|
|
352
|
+
_this._settled = true;
|
|
353
|
+
_this.dispatchEvent(new Event("settled"));
|
|
354
|
+
});
|
|
355
|
+
return _this;
|
|
356
|
+
}
|
|
357
|
+
SettleSignal.settle = function settle() {
|
|
358
|
+
const signal = new SettleSignal();
|
|
359
|
+
signal._settled = true;
|
|
360
|
+
return signal;
|
|
361
|
+
};
|
|
362
|
+
_createClass(SettleSignal, [{
|
|
363
|
+
key: "settled",
|
|
364
|
+
get: function () {
|
|
365
|
+
return this._settled;
|
|
366
|
+
}
|
|
367
|
+
}]);
|
|
368
|
+
return SettleSignal;
|
|
369
|
+
}(_wrapNativeSuper(EventTarget));
|
|
370
|
+
|
|
371
|
+
let SettleController = function () {
|
|
372
|
+
function SettleController() {
|
|
373
|
+
this._settleFn = void 0;
|
|
374
|
+
this._signal = void 0;
|
|
375
|
+
this._signal = new SettleSignal(settleFn => this._settleFn = settleFn);
|
|
376
|
+
}
|
|
377
|
+
var _proto = SettleController.prototype;
|
|
378
|
+
_proto.settle = function settle() {
|
|
379
|
+
this._settleFn();
|
|
380
|
+
};
|
|
381
|
+
_createClass(SettleController, [{
|
|
382
|
+
key: "signal",
|
|
383
|
+
get: function () {
|
|
384
|
+
return this._signal;
|
|
385
|
+
}
|
|
386
|
+
}]);
|
|
387
|
+
return SettleController;
|
|
388
|
+
}();
|
|
389
|
+
|
|
390
|
+
const defaultConfig$3 = null;
|
|
320
391
|
const normalizeConfig = config => {
|
|
321
392
|
if (typeof config === "string") {
|
|
322
393
|
return {
|
|
@@ -324,28 +395,23 @@ const normalizeConfig = config => {
|
|
|
324
395
|
style: {}
|
|
325
396
|
};
|
|
326
397
|
}
|
|
327
|
-
|
|
328
398
|
if (Array.isArray(config)) {
|
|
329
399
|
return {
|
|
330
400
|
classes: config,
|
|
331
401
|
style: {}
|
|
332
402
|
};
|
|
333
403
|
}
|
|
334
|
-
|
|
335
404
|
if (typeof config === "object") {
|
|
336
|
-
if (config.classes != null && config.style != null) {
|
|
405
|
+
if ("classes" in config && config.classes != null && "style" in config && config.style != null) {
|
|
337
406
|
return config;
|
|
338
407
|
}
|
|
339
|
-
|
|
340
408
|
return {
|
|
341
409
|
classes: [],
|
|
342
410
|
style: config
|
|
343
411
|
};
|
|
344
412
|
}
|
|
345
|
-
|
|
346
413
|
throw new Error(`Invalid config: ${config}`);
|
|
347
414
|
};
|
|
348
|
-
|
|
349
415
|
const adapter$3 = (children, config) => {
|
|
350
416
|
const {
|
|
351
417
|
classes,
|
|
@@ -362,13 +428,11 @@ const defaultConfig$2 = [];
|
|
|
362
428
|
const adapter$2 = (children, config) => {
|
|
363
429
|
let currentChildren = children;
|
|
364
430
|
const interceptors = Array.isArray(config) ? config : [config];
|
|
365
|
-
|
|
366
431
|
for (const interceptor of interceptors) {
|
|
367
432
|
currentChildren = React.createElement(InterceptRequests, {
|
|
368
433
|
interceptor: interceptor
|
|
369
434
|
}, currentChildren);
|
|
370
435
|
}
|
|
371
|
-
|
|
372
436
|
return React.createElement(React.Fragment, null, currentChildren);
|
|
373
437
|
};
|
|
374
438
|
|
|
@@ -381,12 +445,10 @@ const adapter$1 = (children, config) => React.createElement(React.Fragment, null
|
|
|
381
445
|
const defaultConfig = {
|
|
382
446
|
location: "/"
|
|
383
447
|
};
|
|
384
|
-
|
|
385
448
|
const maybeWithRoute = (children, path) => {
|
|
386
449
|
if (path == null) {
|
|
387
450
|
return children;
|
|
388
451
|
}
|
|
389
|
-
|
|
390
452
|
return React.createElement(Switch, null, React.createElement(Route, {
|
|
391
453
|
exact: true,
|
|
392
454
|
path: path
|
|
@@ -397,46 +459,37 @@ const maybeWithRoute = (children, path) => {
|
|
|
397
459
|
}
|
|
398
460
|
}));
|
|
399
461
|
};
|
|
400
|
-
|
|
401
462
|
const adapter = (children, config) => {
|
|
402
463
|
if (typeof config === "string") {
|
|
403
464
|
config = {
|
|
404
465
|
location: config
|
|
405
466
|
};
|
|
406
467
|
}
|
|
407
|
-
|
|
408
468
|
const wrappedWithRoute = maybeWithRoute(children, config.path);
|
|
409
|
-
|
|
410
469
|
if (config.forceStatic) {
|
|
411
470
|
return React.createElement(StaticRouter, {
|
|
412
471
|
location: config.location,
|
|
413
472
|
context: {}
|
|
414
473
|
}, wrappedWithRoute);
|
|
415
474
|
}
|
|
416
|
-
|
|
417
475
|
if (typeof config.location !== "undefined") {
|
|
418
476
|
return React.createElement(MemoryRouter, {
|
|
419
477
|
initialEntries: [config.location]
|
|
420
478
|
}, wrappedWithRoute);
|
|
421
479
|
}
|
|
422
|
-
|
|
423
480
|
if (typeof config.initialEntries === "undefined") {
|
|
424
481
|
throw new Error("A location or initial history entries must be provided.");
|
|
425
482
|
}
|
|
426
|
-
|
|
427
483
|
const entries = config.initialEntries.length === 0 ? [defaultConfig.location] : config.initialEntries;
|
|
428
484
|
const routerProps = {
|
|
429
485
|
initialEntries: entries
|
|
430
486
|
};
|
|
431
|
-
|
|
432
487
|
if (config.initialIndex != null) {
|
|
433
488
|
routerProps.initialIndex = config.initialIndex;
|
|
434
489
|
}
|
|
435
|
-
|
|
436
490
|
if (config.getUserConfirmation != null) {
|
|
437
491
|
routerProps.getUserConfirmation = config.getUserConfirmation;
|
|
438
492
|
}
|
|
439
|
-
|
|
440
493
|
return React.createElement(MemoryRouter, routerProps, wrappedWithRoute);
|
|
441
494
|
};
|
|
442
495
|
|
|
@@ -459,25 +512,36 @@ var adapters = /*#__PURE__*/Object.freeze({
|
|
|
459
512
|
DefaultConfigs: DefaultConfigs
|
|
460
513
|
});
|
|
461
514
|
|
|
515
|
+
function _extends() {
|
|
516
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
517
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
518
|
+
var source = arguments[i];
|
|
519
|
+
for (var key in source) {
|
|
520
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
521
|
+
target[key] = source[key];
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return target;
|
|
526
|
+
};
|
|
527
|
+
return _extends.apply(this, arguments);
|
|
528
|
+
}
|
|
529
|
+
|
|
462
530
|
const renderAdapters = (adapters, configs, children) => {
|
|
463
531
|
let currentChildren = children;
|
|
464
|
-
|
|
465
532
|
for (const adapterName of Object.keys(adapters)) {
|
|
466
533
|
const adapter = adapters[adapterName];
|
|
467
534
|
const config = configs[adapterName];
|
|
468
|
-
|
|
469
535
|
if (config != null) {
|
|
470
536
|
currentChildren = adapter(currentChildren, config);
|
|
471
537
|
}
|
|
472
538
|
}
|
|
473
|
-
|
|
474
539
|
return currentChildren;
|
|
475
540
|
};
|
|
476
541
|
|
|
477
542
|
const makeTestHarness = (adapters, defaultConfigs) => {
|
|
478
543
|
return (Component, configs) => {
|
|
479
544
|
const fullConfig = _extends({}, defaultConfigs, configs);
|
|
480
|
-
|
|
481
545
|
const harnessedComponent = React.forwardRef((props, ref) => renderAdapters(adapters, fullConfig, React.createElement(Component, _extends({}, props, {
|
|
482
546
|
ref: ref
|
|
483
547
|
}))));
|
|
@@ -489,7 +553,6 @@ const makeTestHarness = (adapters, defaultConfigs) => {
|
|
|
489
553
|
const HookHarness = ({
|
|
490
554
|
children
|
|
491
555
|
}) => children;
|
|
492
|
-
|
|
493
556
|
const makeHookHarness = (adapters, defaultConfigs) => {
|
|
494
557
|
const testHarness = makeTestHarness(adapters, defaultConfigs);
|
|
495
558
|
return configs => testHarness(HookHarness, configs);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for fetch-request-matches-mock
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { FetchMockOperation } from "./types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Determines if a given fetch invocation matches the given mock.
|
|
12
|
+
*/
|
|
13
|
+
declare export var fetchRequestMatchesMock: (
|
|
14
|
+
mock: FetchMockOperation,
|
|
15
|
+
input: RequestInfo,
|
|
16
|
+
init?: RequestInit | null
|
|
17
|
+
) => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for mock-fetch
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { FetchMockFn } from "./types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A mock for the fetch function passed to GqlRouter.
|
|
12
|
+
*/
|
|
13
|
+
declare export var mockFetch: () => FetchMockFn;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MockResponse } from "../respond-with";
|
|
2
|
+
export type FetchMockOperation = RegExp | string;
|
|
3
|
+
type FetchMockOperationFn = (operation: FetchMockOperation, response: MockResponse<any>) => FetchMockFn;
|
|
4
|
+
export type FetchMockFn = {
|
|
5
|
+
(input: RequestInfo, init?: RequestInit): Promise<Response>;
|
|
6
|
+
mockOperation: FetchMockOperationFn;
|
|
7
|
+
mockOperationOnce: FetchMockOperationFn;
|
|
8
|
+
};
|
|
9
|
+
export {};
|