@khanacademy/wonder-blocks-testing 3.0.1 → 4.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.
- package/CHANGELOG.md +6 -0
- package/dist/es/index.js +212 -135
- package/dist/index.js +259 -138
- package/package.json +2 -1
- package/src/{gql/__tests__/make-gql-mock-response.test.js → __tests__/make-mock-response.test.js} +196 -34
- package/src/__tests__/mock-requester.test.js +213 -0
- package/src/__tests__/response-impl.test.js +47 -0
- package/src/fetch/__tests__/__snapshots__/mock-fetch.test.js.snap +29 -0
- package/src/fetch/__tests__/fetch-request-matches-mock.test.js +99 -0
- package/src/fetch/__tests__/mock-fetch.test.js +84 -0
- package/src/fetch/fetch-request-matches-mock.js +43 -0
- package/src/fetch/mock-fetch.js +19 -0
- package/src/fetch/types.js +18 -0
- package/src/gql/__tests__/mock-gql-fetch.test.js +24 -15
- package/src/gql/__tests__/wb-data-integration.test.js +7 -4
- package/src/gql/mock-gql-fetch.js +9 -80
- package/src/gql/types.js +11 -10
- package/src/index.js +9 -3
- package/src/make-mock-response.js +150 -0
- package/src/mock-requester.js +75 -0
- package/src/response-impl.js +9 -0
- package/src/types.js +39 -0
- package/src/gql/make-gql-mock-response.js +0 -124
package/dist/index.js
CHANGED
|
@@ -82,7 +82,7 @@ module.exports =
|
|
|
82
82
|
/******/
|
|
83
83
|
/******/
|
|
84
84
|
/******/ // Load entry module and return exports
|
|
85
|
-
/******/ return __webpack_require__(__webpack_require__.s =
|
|
85
|
+
/******/ return __webpack_require__(__webpack_require__.s = 18);
|
|
86
86
|
/******/ })
|
|
87
87
|
/************************************************************************/
|
|
88
88
|
/******/ ([
|
|
@@ -121,89 +121,114 @@ const getConfiguration = () => {
|
|
|
121
121
|
|
|
122
122
|
"use strict";
|
|
123
123
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return RespondWith; });
|
|
124
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return
|
|
124
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return makeMockResponse; });
|
|
125
|
+
/* harmony import */ var _response_impl_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(15);
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Helper for creating a text-based mock response.
|
|
130
|
+
*/
|
|
131
|
+
const textResponse = (text, statusCode = 200) => ({
|
|
132
|
+
type: "text",
|
|
133
|
+
text,
|
|
134
|
+
statusCode
|
|
135
|
+
});
|
|
136
|
+
/**
|
|
137
|
+
* Helper for creating a rejected mock response.
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
const rejectResponse = error => ({
|
|
142
|
+
type: "reject",
|
|
143
|
+
error
|
|
144
|
+
});
|
|
125
145
|
/**
|
|
126
|
-
* Helpers to define
|
|
146
|
+
* Helpers to define mock responses for mocked requests.
|
|
127
147
|
*/
|
|
148
|
+
|
|
149
|
+
|
|
128
150
|
const RespondWith = Object.freeze({
|
|
129
|
-
|
|
130
|
-
|
|
151
|
+
/**
|
|
152
|
+
* Response with text body and status code.
|
|
153
|
+
* Status code defaults to 200.
|
|
154
|
+
*/
|
|
155
|
+
text: (text, statusCode = 200) => textResponse(text, statusCode),
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Response with JSON body and status code 200.
|
|
159
|
+
*/
|
|
160
|
+
json: json => textResponse(() => JSON.stringify(json)),
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Response with GraphQL data JSON body and status code 200.
|
|
164
|
+
*/
|
|
165
|
+
graphQLData: data => textResponse(() => JSON.stringify({
|
|
131
166
|
data
|
|
167
|
+
})),
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Response with body that will not parse as JSON and status code 200.
|
|
171
|
+
*/
|
|
172
|
+
unparseableBody: () => textResponse("INVALID JSON"),
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Rejects with an AbortError to simulate an aborted request.
|
|
176
|
+
*/
|
|
177
|
+
abortedRequest: () => rejectResponse(() => {
|
|
178
|
+
const abortError = new Error("Mock request aborted");
|
|
179
|
+
abortError.name = "AbortError";
|
|
180
|
+
return abortError;
|
|
132
181
|
}),
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Rejects with the given error.
|
|
185
|
+
*/
|
|
186
|
+
reject: error => rejectResponse(error),
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* A non-200 status code with empty text body.
|
|
190
|
+
* Equivalent to calling `ResponseWith.text("", statusCode)`.
|
|
191
|
+
*/
|
|
139
192
|
errorStatusCode: statusCode => {
|
|
140
193
|
if (statusCode < 300) {
|
|
141
194
|
throw new Error(`${statusCode} is not a valid error status code`);
|
|
142
195
|
}
|
|
143
196
|
|
|
144
|
-
return {
|
|
145
|
-
type: "status",
|
|
146
|
-
statusCode
|
|
147
|
-
};
|
|
197
|
+
return textResponse("{}", statusCode);
|
|
148
198
|
},
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Response body that is valid JSON but not a valid GraphQL response.
|
|
202
|
+
*/
|
|
203
|
+
nonGraphQLBody: () => textResponse(() => JSON.stringify({
|
|
204
|
+
valid: "json",
|
|
205
|
+
that: "is not a valid graphql response"
|
|
206
|
+
})),
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Response that is a GraphQL errors response with status code 200.
|
|
210
|
+
*/
|
|
211
|
+
graphQLErrors: errorMessages => textResponse(() => JSON.stringify({
|
|
212
|
+
errors: errorMessages.map(e => ({
|
|
213
|
+
message: e
|
|
214
|
+
}))
|
|
215
|
+
}))
|
|
156
216
|
});
|
|
157
217
|
/**
|
|
158
|
-
* Turns
|
|
159
|
-
* that error.
|
|
218
|
+
* Turns a MockResponse value to an actual Response that represents the mock.
|
|
160
219
|
*/
|
|
161
220
|
|
|
162
|
-
const
|
|
221
|
+
const makeMockResponse = response => {
|
|
163
222
|
switch (response.type) {
|
|
164
|
-
case "
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return Promise.resolve({
|
|
174
|
-
status: 200,
|
|
175
|
-
text: () => Promise.resolve("INVALID JSON")
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
case "abort":
|
|
179
|
-
const abortError = new Error("Mock request aborted");
|
|
180
|
-
abortError.name = "AbortError";
|
|
181
|
-
return Promise.reject(abortError);
|
|
182
|
-
|
|
183
|
-
case "status":
|
|
184
|
-
return Promise.resolve({
|
|
185
|
-
status: response.statusCode,
|
|
186
|
-
text: () => Promise.resolve(JSON.stringify({}))
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
case "invalid":
|
|
190
|
-
return Promise.resolve({
|
|
191
|
-
status: 200,
|
|
192
|
-
text: () => Promise.resolve(JSON.stringify({
|
|
193
|
-
valid: "json",
|
|
194
|
-
that: "is not a valid graphql response"
|
|
195
|
-
}))
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
case "graphql":
|
|
199
|
-
return Promise.resolve({
|
|
200
|
-
status: 200,
|
|
201
|
-
text: () => Promise.resolve(JSON.stringify({
|
|
202
|
-
errors: response.errors.map(e => ({
|
|
203
|
-
message: e
|
|
204
|
-
}))
|
|
205
|
-
}))
|
|
206
|
-
});
|
|
223
|
+
case "text":
|
|
224
|
+
const text = typeof response.text === "function" ? response.text() : response.text;
|
|
225
|
+
return Promise.resolve(new _response_impl_js__WEBPACK_IMPORTED_MODULE_0__[/* ResponseImpl */ "a"](text, {
|
|
226
|
+
status: response.statusCode
|
|
227
|
+
}));
|
|
228
|
+
|
|
229
|
+
case "reject":
|
|
230
|
+
const error = response.error instanceof Error ? response.error : response.error();
|
|
231
|
+
return Promise.reject(error);
|
|
207
232
|
|
|
208
233
|
default:
|
|
209
234
|
throw new Error(`Unknown response type: ${response.type}`);
|
|
@@ -220,24 +245,82 @@ module.exports = require("react");
|
|
|
220
245
|
/* 3 */
|
|
221
246
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
222
247
|
|
|
248
|
+
"use strict";
|
|
249
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return mockRequester; });
|
|
250
|
+
/* harmony import */ var _make_mock_response_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* A generic mock request function for using when mocking fetch or gqlFetch.
|
|
255
|
+
*/
|
|
256
|
+
const mockRequester = (operationMatcher, operationToString) => {
|
|
257
|
+
// We want this to work in jest and in fixtures to make life easy for folks.
|
|
258
|
+
// This is the array of mocked operations that we will traverse and
|
|
259
|
+
// manipulate.
|
|
260
|
+
const mocks = []; // What we return has to be a drop in for the fetch function that is
|
|
261
|
+
// provided to `GqlRouter` which is how folks will then use this mock.
|
|
262
|
+
|
|
263
|
+
const mockFn = (...args) => {
|
|
264
|
+
// Iterate our mocked operations and find the first one that matches.
|
|
265
|
+
for (const mock of mocks) {
|
|
266
|
+
if (mock.onceOnly && mock.used) {
|
|
267
|
+
// This is a once-only mock and it has been used, so skip it.
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (operationMatcher.apply(void 0, [mock.operation].concat(args))) {
|
|
272
|
+
mock.used = true;
|
|
273
|
+
return mock.response();
|
|
274
|
+
}
|
|
275
|
+
} // Default is to reject with some helpful info on what request
|
|
276
|
+
// we rejected.
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
return Promise.reject(new Error(`No matching mock response found for request:
|
|
280
|
+
${operationToString.apply(void 0, args)}`));
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const addMockedOperation = (operation, response, onceOnly) => {
|
|
284
|
+
const mockResponse = () => Object(_make_mock_response_js__WEBPACK_IMPORTED_MODULE_0__[/* makeMockResponse */ "b"])(response);
|
|
285
|
+
|
|
286
|
+
mocks.push({
|
|
287
|
+
operation,
|
|
288
|
+
response: mockResponse,
|
|
289
|
+
onceOnly,
|
|
290
|
+
used: false
|
|
291
|
+
});
|
|
292
|
+
return mockFn;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
mockFn.mockOperation = (operation, response) => addMockedOperation(operation, response, false);
|
|
296
|
+
|
|
297
|
+
mockFn.mockOperationOnce = (operation, response) => addMockedOperation(operation, response, true);
|
|
298
|
+
|
|
299
|
+
return mockFn;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
/***/ }),
|
|
303
|
+
/* 4 */
|
|
304
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
305
|
+
|
|
223
306
|
"use strict";
|
|
224
307
|
__webpack_require__.r(__webpack_exports__);
|
|
225
|
-
/* harmony import */ var _storybook_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
|
|
308
|
+
/* harmony import */ var _storybook_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
|
|
226
309
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "storybook", function() { return _storybook_js__WEBPACK_IMPORTED_MODULE_0__["a"]; });
|
|
227
310
|
|
|
228
311
|
|
|
229
312
|
|
|
230
313
|
/***/ }),
|
|
231
|
-
/*
|
|
314
|
+
/* 5 */
|
|
232
315
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
233
316
|
|
|
234
317
|
"use strict";
|
|
235
318
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return getAdapter; });
|
|
236
319
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
|
|
237
320
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
238
|
-
/* harmony import */ var _storybook_addon_actions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
|
|
321
|
+
/* harmony import */ var _storybook_addon_actions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9);
|
|
239
322
|
/* harmony import */ var _storybook_addon_actions__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_storybook_addon_actions__WEBPACK_IMPORTED_MODULE_1__);
|
|
240
|
-
/* harmony import */ var _adapter_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(
|
|
323
|
+
/* harmony import */ var _adapter_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(10);
|
|
241
324
|
|
|
242
325
|
|
|
243
326
|
|
|
@@ -313,7 +396,7 @@ const getAdapter = (MountingComponent = null) => new _adapter_js__WEBPACK_IMPORT
|
|
|
313
396
|
});
|
|
314
397
|
|
|
315
398
|
/***/ }),
|
|
316
|
-
/*
|
|
399
|
+
/* 6 */
|
|
317
400
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
318
401
|
|
|
319
402
|
"use strict";
|
|
@@ -321,7 +404,7 @@ const getAdapter = (MountingComponent = null) => new _adapter_js__WEBPACK_IMPORT
|
|
|
321
404
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
|
|
322
405
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
323
406
|
/* harmony import */ var _setup_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
|
|
324
|
-
/* harmony import */ var _combine_options_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(
|
|
407
|
+
/* harmony import */ var _combine_options_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(12);
|
|
325
408
|
|
|
326
409
|
|
|
327
410
|
|
|
@@ -419,80 +502,53 @@ const fixtures = (componentOrOptions, fn) => {
|
|
|
419
502
|
};
|
|
420
503
|
|
|
421
504
|
/***/ }),
|
|
422
|
-
/*
|
|
505
|
+
/* 7 */
|
|
423
506
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
424
507
|
|
|
425
508
|
"use strict";
|
|
426
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return
|
|
427
|
-
/* harmony import */ var
|
|
428
|
-
/* harmony import */ var
|
|
509
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return mockFetch; });
|
|
510
|
+
/* harmony import */ var _fetch_request_matches_mock_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(16);
|
|
511
|
+
/* harmony import */ var _mock_requester_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
|
|
429
512
|
|
|
430
513
|
|
|
431
514
|
|
|
432
515
|
/**
|
|
433
516
|
* A mock for the fetch function passed to GqlRouter.
|
|
434
517
|
*/
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
// This is the array of mocked operations that we will traverse and
|
|
438
|
-
// manipulate.
|
|
439
|
-
const mocks = []; // What we return has to be a drop in for the fetch function that is
|
|
440
|
-
// provided to `GqlRouter` which is how folks will then use this mock.
|
|
518
|
+
const mockFetch = () => Object(_mock_requester_js__WEBPACK_IMPORTED_MODULE_1__[/* mockRequester */ "a"])(_fetch_request_matches_mock_js__WEBPACK_IMPORTED_MODULE_0__[/* fetchRequestMatchesMock */ "a"], (input, init) => `Input: ${typeof input === "string" ? input : JSON.stringify(input, null, 2)}
|
|
519
|
+
Options: ${init == null ? "None" : JSON.stringify(init, null, 2)}`);
|
|
441
520
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
if (mock.onceOnly && mock.used) {
|
|
446
|
-
// This is a once-only mock and it has been used, so skip it.
|
|
447
|
-
continue;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
if (Object(_gql_request_matches_mock_js__WEBPACK_IMPORTED_MODULE_0__[/* gqlRequestMatchesMock */ "a"])(mock.operation, operation, variables, context)) {
|
|
451
|
-
mock.used = true;
|
|
452
|
-
return mock.response();
|
|
453
|
-
}
|
|
454
|
-
} // Default is to reject with some helpful info on what request
|
|
455
|
-
// we rejected.
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
return Promise.reject(new Error(`No matching GraphQL mock response found for request:
|
|
459
|
-
Operation: ${operation.type} ${operation.id}
|
|
460
|
-
Variables: ${variables == null ? "None" : JSON.stringify(variables, null, 2)}
|
|
461
|
-
Context: ${JSON.stringify(context, null, 2)}`));
|
|
462
|
-
};
|
|
463
|
-
|
|
464
|
-
const addMockedOperation = (operation, response, onceOnly) => {
|
|
465
|
-
const mockResponse = () => Object(_make_gql_mock_response_js__WEBPACK_IMPORTED_MODULE_1__[/* makeGqlMockResponse */ "b"])(response);
|
|
521
|
+
/***/ }),
|
|
522
|
+
/* 8 */
|
|
523
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
466
524
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
used: false
|
|
472
|
-
});
|
|
473
|
-
return gqlFetchMock;
|
|
474
|
-
};
|
|
525
|
+
"use strict";
|
|
526
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return mockGqlFetch; });
|
|
527
|
+
/* harmony import */ var _gql_request_matches_mock_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(17);
|
|
528
|
+
/* harmony import */ var _mock_requester_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
|
|
475
529
|
|
|
476
|
-
gqlFetchMock.mockOperation = (operation, response) => addMockedOperation(operation, response, false);
|
|
477
530
|
|
|
478
|
-
gqlFetchMock.mockOperationOnce = (operation, response) => addMockedOperation(operation, response, true);
|
|
479
531
|
|
|
480
|
-
|
|
481
|
-
|
|
532
|
+
/**
|
|
533
|
+
* A mock for the fetch function passed to GqlRouter.
|
|
534
|
+
*/
|
|
535
|
+
const mockGqlFetch = () => Object(_mock_requester_js__WEBPACK_IMPORTED_MODULE_1__[/* mockRequester */ "a"])(_gql_request_matches_mock_js__WEBPACK_IMPORTED_MODULE_0__[/* gqlRequestMatchesMock */ "a"], (operation, variables, context) => `Operation: ${operation.type} ${operation.id}
|
|
536
|
+
Variables: ${variables == null ? "None" : JSON.stringify(variables, null, 2)}
|
|
537
|
+
Context: ${JSON.stringify(context, null, 2)}`);
|
|
482
538
|
|
|
483
539
|
/***/ }),
|
|
484
|
-
/*
|
|
540
|
+
/* 9 */
|
|
485
541
|
/***/ (function(module, exports) {
|
|
486
542
|
|
|
487
543
|
module.exports = require("@storybook/addon-actions");
|
|
488
544
|
|
|
489
545
|
/***/ }),
|
|
490
|
-
/*
|
|
546
|
+
/* 10 */
|
|
491
547
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
492
548
|
|
|
493
549
|
"use strict";
|
|
494
550
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Adapter; });
|
|
495
|
-
/* harmony import */ var _adapter_group_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
|
|
551
|
+
/* harmony import */ var _adapter_group_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(11);
|
|
496
552
|
|
|
497
553
|
|
|
498
554
|
/**
|
|
@@ -547,7 +603,7 @@ class Adapter {
|
|
|
547
603
|
}
|
|
548
604
|
|
|
549
605
|
/***/ }),
|
|
550
|
-
/*
|
|
606
|
+
/* 11 */
|
|
551
607
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
552
608
|
|
|
553
609
|
"use strict";
|
|
@@ -612,12 +668,12 @@ class AdapterGroup {
|
|
|
612
668
|
}
|
|
613
669
|
|
|
614
670
|
/***/ }),
|
|
615
|
-
/*
|
|
671
|
+
/* 12 */
|
|
616
672
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
617
673
|
|
|
618
674
|
"use strict";
|
|
619
675
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return combineOptions; });
|
|
620
|
-
/* harmony import */ var _combine_top_level_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
|
|
676
|
+
/* harmony import */ var _combine_top_level_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(13);
|
|
621
677
|
|
|
622
678
|
/**
|
|
623
679
|
* Combine one or more objects into a single object.
|
|
@@ -642,12 +698,12 @@ const combineOptions = (...toBeCombined) => {
|
|
|
642
698
|
};
|
|
643
699
|
|
|
644
700
|
/***/ }),
|
|
645
|
-
/*
|
|
701
|
+
/* 13 */
|
|
646
702
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
647
703
|
|
|
648
704
|
"use strict";
|
|
649
705
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return combineTopLevel; });
|
|
650
|
-
/* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
|
|
706
|
+
/* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(14);
|
|
651
707
|
/* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__);
|
|
652
708
|
|
|
653
709
|
/**
|
|
@@ -688,13 +744,69 @@ const combineTopLevel = (val1, val2) => {
|
|
|
688
744
|
};
|
|
689
745
|
|
|
690
746
|
/***/ }),
|
|
691
|
-
/*
|
|
747
|
+
/* 14 */
|
|
692
748
|
/***/ (function(module, exports) {
|
|
693
749
|
|
|
694
750
|
module.exports = require("@khanacademy/wonder-stuff-core");
|
|
695
751
|
|
|
696
752
|
/***/ }),
|
|
697
|
-
/*
|
|
753
|
+
/* 15 */
|
|
754
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
755
|
+
|
|
756
|
+
"use strict";
|
|
757
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ResponseImpl; });
|
|
758
|
+
// We need a version of Response. When we're in Jest JSDOM environment or a
|
|
759
|
+
// version of Node that supports the fetch API (17 and up, possibly with
|
|
760
|
+
// --experimental-fetch flag), then we're good, but otherwise we need an
|
|
761
|
+
// implementation, so this uses node-fetch as a peer dependency and uses that
|
|
762
|
+
// to provide the implementation if we don't already have one.
|
|
763
|
+
const ResponseImpl = typeof Response === "undefined" ? __webpack_require__(19).Response : Response;
|
|
764
|
+
|
|
765
|
+
/***/ }),
|
|
766
|
+
/* 16 */
|
|
767
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
768
|
+
|
|
769
|
+
"use strict";
|
|
770
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return fetchRequestMatchesMock; });
|
|
771
|
+
/**
|
|
772
|
+
* Get the URL from the given RequestInfo.
|
|
773
|
+
*
|
|
774
|
+
* Since we could be running in Node or in JSDOM, we don't check instance
|
|
775
|
+
* types, but just use a heuristic so that this works without knowing what
|
|
776
|
+
* was polyfilling things.
|
|
777
|
+
*/
|
|
778
|
+
const getHref = input => {
|
|
779
|
+
if (typeof input === "string") {
|
|
780
|
+
return input;
|
|
781
|
+
} else if (typeof input.url === "string") {
|
|
782
|
+
return input.url;
|
|
783
|
+
} else if (typeof input.href === "string") {
|
|
784
|
+
return input.href;
|
|
785
|
+
} else {
|
|
786
|
+
throw new Error(`Unsupported input type`);
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
/**
|
|
790
|
+
* Determines if a given fetch invocation matches the given mock.
|
|
791
|
+
*/
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
const fetchRequestMatchesMock = (mock, input, init) => {
|
|
795
|
+
// Currently, we only match on the input portion.
|
|
796
|
+
// This can be a Request, a URL, or a string.
|
|
797
|
+
const href = getHref(input); // Our mock operation is either a string for an exact match, or a regex.
|
|
798
|
+
|
|
799
|
+
if (typeof mock === "string") {
|
|
800
|
+
return href === mock;
|
|
801
|
+
} else if (mock instanceof RegExp) {
|
|
802
|
+
return mock.test(href);
|
|
803
|
+
} else {
|
|
804
|
+
throw new Error(`Unsupported mock operation: ${JSON.stringify(mock)}`);
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
/***/ }),
|
|
809
|
+
/* 17 */
|
|
698
810
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
699
811
|
|
|
700
812
|
"use strict";
|
|
@@ -769,33 +881,42 @@ const gqlRequestMatchesMock = (mock, operation, variables, context) => {
|
|
|
769
881
|
};
|
|
770
882
|
|
|
771
883
|
/***/ }),
|
|
772
|
-
/*
|
|
884
|
+
/* 18 */
|
|
773
885
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
774
886
|
|
|
775
887
|
"use strict";
|
|
776
888
|
__webpack_require__.r(__webpack_exports__);
|
|
777
|
-
/* harmony import */ var _fixtures_adapters_adapters_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
|
|
889
|
+
/* harmony import */ var _fixtures_adapters_adapters_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4);
|
|
778
890
|
/* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "adapters", function() { return _fixtures_adapters_adapters_js__WEBPACK_IMPORTED_MODULE_0__; });
|
|
779
|
-
/* harmony import */ var _fixtures_fixtures_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
|
|
891
|
+
/* harmony import */ var _fixtures_fixtures_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6);
|
|
780
892
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fixtures", function() { return _fixtures_fixtures_js__WEBPACK_IMPORTED_MODULE_1__["a"]; });
|
|
781
893
|
|
|
782
894
|
/* harmony import */ var _fixtures_setup_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(0);
|
|
783
895
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setupFixtures", function() { return _fixtures_setup_js__WEBPACK_IMPORTED_MODULE_2__["b"]; });
|
|
784
896
|
|
|
785
|
-
/* harmony import */ var
|
|
786
|
-
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "
|
|
897
|
+
/* harmony import */ var _make_mock_response_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(1);
|
|
898
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RespondWith", function() { return _make_mock_response_js__WEBPACK_IMPORTED_MODULE_3__["a"]; });
|
|
899
|
+
|
|
900
|
+
/* harmony import */ var _fetch_mock_fetch_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(7);
|
|
901
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "mockFetch", function() { return _fetch_mock_fetch_js__WEBPACK_IMPORTED_MODULE_4__["a"]; });
|
|
787
902
|
|
|
788
|
-
/* harmony import */ var
|
|
789
|
-
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "
|
|
903
|
+
/* harmony import */ var _gql_mock_gql_fetch_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(8);
|
|
904
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "mockGqlFetch", function() { return _gql_mock_gql_fetch_js__WEBPACK_IMPORTED_MODULE_5__["a"]; });
|
|
790
905
|
|
|
791
906
|
// Fixtures framework
|
|
792
907
|
|
|
793
908
|
|
|
794
909
|
|
|
795
910
|
|
|
796
|
-
// GraphQL framework
|
|
797
911
|
|
|
798
912
|
|
|
799
913
|
|
|
914
|
+
|
|
915
|
+
/***/ }),
|
|
916
|
+
/* 19 */
|
|
917
|
+
/***/ (function(module, exports) {
|
|
918
|
+
|
|
919
|
+
module.exports = require("node-fetch");
|
|
920
|
+
|
|
800
921
|
/***/ })
|
|
801
922
|
/******/ ]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-testing",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"@khanacademy/wonder-stuff-core": "^0.1.2",
|
|
21
21
|
"@khanacademy/wonder-stuff-testing": "^0.0.2",
|
|
22
22
|
"@storybook/addon-actions": "^6.4.8",
|
|
23
|
+
"node-fetch": "^2.6.7",
|
|
23
24
|
"react": "16.14.0"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|