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