@khanacademy/wonder-blocks-testing 7.0.4 → 7.1.1
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 +160 -62
- package/dist/index.js +326 -167
- package/package.json +2 -2
- package/src/__docs__/exports.respond-with.stories.mdx +17 -6
- package/src/__docs__/exports.settle-controller.stories.mdx +32 -0
- package/src/__docs__/types.mock-response.stories.mdx +6 -2
- package/src/__tests__/mock-requester.test.js +1 -1
- package/src/__tests__/respond-with.test.js +525 -0
- package/src/__tests__/settle-controller.test.js +29 -0
- package/src/__tests__/settle-signal.test.js +105 -0
- package/src/fetch/__tests__/mock-fetch.test.js +1 -1
- package/src/fetch/types.js +1 -1
- package/src/gql/__tests__/mock-gql-fetch.test.js +1 -1
- package/src/gql/__tests__/wb-data-integration.test.js +1 -1
- package/src/gql/types.js +1 -1
- package/src/index.js +3 -2
- package/src/mock-requester.js +2 -3
- package/src/respond-with.js +236 -0
- package/src/settle-controller.js +35 -0
- package/src/settle-signal.js +41 -0
- package/src/types.js +1 -1
- package/src/__tests__/make-mock-response.test.js +0 -460
- package/src/make-mock-response.js +0 -150
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 = 25);
|
|
86
86
|
/******/ })
|
|
87
87
|
/************************************************************************/
|
|
88
88
|
/******/ ([
|
|
@@ -148,7 +148,7 @@ module.exports = require("react-router-dom");
|
|
|
148
148
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return makeTestHarness; });
|
|
149
149
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
150
150
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
151
|
-
/* harmony import */ var _render_adapters_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
|
|
151
|
+
/* harmony import */ var _render_adapters_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(24);
|
|
152
152
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
153
153
|
|
|
154
154
|
|
|
@@ -202,126 +202,6 @@ const makeTestHarness = (adapters, defaultConfigs) => {
|
|
|
202
202
|
/* 4 */
|
|
203
203
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
204
204
|
|
|
205
|
-
"use strict";
|
|
206
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return RespondWith; });
|
|
207
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return makeMockResponse; });
|
|
208
|
-
/* harmony import */ var _response_impl_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(19);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Helper for creating a text-based mock response.
|
|
213
|
-
*/
|
|
214
|
-
const textResponse = (text, statusCode = 200) => ({
|
|
215
|
-
type: "text",
|
|
216
|
-
text,
|
|
217
|
-
statusCode
|
|
218
|
-
});
|
|
219
|
-
/**
|
|
220
|
-
* Helper for creating a rejected mock response.
|
|
221
|
-
*/
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const rejectResponse = error => ({
|
|
225
|
-
type: "reject",
|
|
226
|
-
error
|
|
227
|
-
});
|
|
228
|
-
/**
|
|
229
|
-
* Helpers to define mock responses for mocked requests.
|
|
230
|
-
*/
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const RespondWith = Object.freeze({
|
|
234
|
-
/**
|
|
235
|
-
* Response with text body and status code.
|
|
236
|
-
* Status code defaults to 200.
|
|
237
|
-
*/
|
|
238
|
-
text: (text, statusCode = 200) => textResponse(text, statusCode),
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Response with JSON body and status code 200.
|
|
242
|
-
*/
|
|
243
|
-
json: json => textResponse(() => JSON.stringify(json)),
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Response with GraphQL data JSON body and status code 200.
|
|
247
|
-
*/
|
|
248
|
-
graphQLData: data => textResponse(() => JSON.stringify({
|
|
249
|
-
data
|
|
250
|
-
})),
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Response with body that will not parse as JSON and status code 200.
|
|
254
|
-
*/
|
|
255
|
-
unparseableBody: () => textResponse("INVALID JSON"),
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Rejects with an AbortError to simulate an aborted request.
|
|
259
|
-
*/
|
|
260
|
-
abortedRequest: () => rejectResponse(() => {
|
|
261
|
-
const abortError = new Error("Mock request aborted");
|
|
262
|
-
abortError.name = "AbortError";
|
|
263
|
-
return abortError;
|
|
264
|
-
}),
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Rejects with the given error.
|
|
268
|
-
*/
|
|
269
|
-
reject: error => rejectResponse(error),
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* A non-200 status code with empty text body.
|
|
273
|
-
* Equivalent to calling `ResponseWith.text("", statusCode)`.
|
|
274
|
-
*/
|
|
275
|
-
errorStatusCode: statusCode => {
|
|
276
|
-
if (statusCode < 300) {
|
|
277
|
-
throw new Error(`${statusCode} is not a valid error status code`);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return textResponse("{}", statusCode);
|
|
281
|
-
},
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Response body that is valid JSON but not a valid GraphQL response.
|
|
285
|
-
*/
|
|
286
|
-
nonGraphQLBody: () => textResponse(() => JSON.stringify({
|
|
287
|
-
valid: "json",
|
|
288
|
-
that: "is not a valid graphql response"
|
|
289
|
-
})),
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Response that is a GraphQL errors response with status code 200.
|
|
293
|
-
*/
|
|
294
|
-
graphQLErrors: errorMessages => textResponse(() => JSON.stringify({
|
|
295
|
-
errors: errorMessages.map(e => ({
|
|
296
|
-
message: e
|
|
297
|
-
}))
|
|
298
|
-
}))
|
|
299
|
-
});
|
|
300
|
-
/**
|
|
301
|
-
* Turns a MockResponse value to an actual Response that represents the mock.
|
|
302
|
-
*/
|
|
303
|
-
|
|
304
|
-
const makeMockResponse = response => {
|
|
305
|
-
switch (response.type) {
|
|
306
|
-
case "text":
|
|
307
|
-
const text = typeof response.text === "function" ? response.text() : response.text;
|
|
308
|
-
return Promise.resolve(new _response_impl_js__WEBPACK_IMPORTED_MODULE_0__[/* ResponseImpl */ "a"](text, {
|
|
309
|
-
status: response.statusCode
|
|
310
|
-
}));
|
|
311
|
-
|
|
312
|
-
case "reject":
|
|
313
|
-
const error = response.error instanceof Error ? response.error : response.error();
|
|
314
|
-
return Promise.reject(error);
|
|
315
|
-
|
|
316
|
-
default:
|
|
317
|
-
throw new Error(`Unknown response type: ${response.type}`);
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
/***/ }),
|
|
322
|
-
/* 5 */
|
|
323
|
-
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
324
|
-
|
|
325
205
|
"use strict";
|
|
326
206
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return makeHookHarness; });
|
|
327
207
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
@@ -362,14 +242,11 @@ const makeHookHarness = (adapters, defaultConfigs) => {
|
|
|
362
242
|
};
|
|
363
243
|
|
|
364
244
|
/***/ }),
|
|
365
|
-
/*
|
|
245
|
+
/* 5 */
|
|
366
246
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
367
247
|
|
|
368
248
|
"use strict";
|
|
369
249
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return mockRequester; });
|
|
370
|
-
/* harmony import */ var _make_mock_response_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4);
|
|
371
|
-
|
|
372
|
-
|
|
373
250
|
/**
|
|
374
251
|
* A generic mock request function for using when mocking fetch or gqlFetch.
|
|
375
252
|
*/
|
|
@@ -401,7 +278,7 @@ const mockRequester = (operationMatcher, operationToString) => {
|
|
|
401
278
|
};
|
|
402
279
|
|
|
403
280
|
const addMockedOperation = (operation, response, onceOnly) => {
|
|
404
|
-
const mockResponse = () =>
|
|
281
|
+
const mockResponse = () => response.toPromise();
|
|
405
282
|
|
|
406
283
|
mocks.push({
|
|
407
284
|
operation,
|
|
@@ -419,6 +296,66 @@ const mockRequester = (operationMatcher, operationToString) => {
|
|
|
419
296
|
return mockFn;
|
|
420
297
|
};
|
|
421
298
|
|
|
299
|
+
/***/ }),
|
|
300
|
+
/* 6 */
|
|
301
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
302
|
+
|
|
303
|
+
"use strict";
|
|
304
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return SettleSignal; });
|
|
305
|
+
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
306
|
+
|
|
307
|
+
var id = 0;
|
|
308
|
+
|
|
309
|
+
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
310
|
+
|
|
311
|
+
var _settled = /*#__PURE__*/_classPrivateFieldLooseKey("settled");
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* A signal for controlling the `RespondWith` API responses.
|
|
315
|
+
*
|
|
316
|
+
* This provide finely-grained control over the promise lifecycle to support
|
|
317
|
+
* complex test scenarios.
|
|
318
|
+
*/
|
|
319
|
+
class SettleSignal extends EventTarget {
|
|
320
|
+
constructor(setSettleFn = null) {
|
|
321
|
+
super(); // If we were given a function, we call it with a method that will
|
|
322
|
+
// settle ourselves. This allows the appropriate SettleController
|
|
323
|
+
// to be in charge of settling this instance.
|
|
324
|
+
|
|
325
|
+
Object.defineProperty(this, _settled, {
|
|
326
|
+
writable: true,
|
|
327
|
+
value: false
|
|
328
|
+
});
|
|
329
|
+
setSettleFn == null ? void 0 : setSettleFn(() => {
|
|
330
|
+
if (_classPrivateFieldLooseBase(this, _settled)[_settled]) {
|
|
331
|
+
throw new Error("SettleSignal already settled");
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
_classPrivateFieldLooseBase(this, _settled)[_settled] = true;
|
|
335
|
+
this.dispatchEvent(new Event("settled"));
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* An already settled signal.
|
|
340
|
+
*/
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
static settle() {
|
|
344
|
+
const signal = new SettleSignal();
|
|
345
|
+
_classPrivateFieldLooseBase(signal, _settled)[_settled] = true;
|
|
346
|
+
return signal;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Has this signal been settled yet?
|
|
350
|
+
*/
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
get settled() {
|
|
354
|
+
return _classPrivateFieldLooseBase(this, _settled)[_settled];
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
}
|
|
358
|
+
|
|
422
359
|
/***/ }),
|
|
423
360
|
/* 7 */
|
|
424
361
|
/***/ (function(module, exports) {
|
|
@@ -498,7 +435,7 @@ const adapter = (children, config) => {
|
|
|
498
435
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return adapter; });
|
|
499
436
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
500
437
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
501
|
-
/* harmony import */ var _khanacademy_wonder_blocks_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
|
|
438
|
+
/* harmony import */ var _khanacademy_wonder_blocks_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(23);
|
|
502
439
|
/* harmony import */ var _khanacademy_wonder_blocks_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_data__WEBPACK_IMPORTED_MODULE_1__);
|
|
503
440
|
|
|
504
441
|
|
|
@@ -757,8 +694,8 @@ const fixtures = Component => {
|
|
|
757
694
|
|
|
758
695
|
"use strict";
|
|
759
696
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return mockFetch; });
|
|
760
|
-
/* harmony import */ var _fetch_request_matches_mock_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
|
|
761
|
-
/* harmony import */ var _mock_requester_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
|
|
697
|
+
/* harmony import */ var _fetch_request_matches_mock_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(20);
|
|
698
|
+
/* harmony import */ var _mock_requester_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
|
|
762
699
|
|
|
763
700
|
|
|
764
701
|
|
|
@@ -774,8 +711,8 @@ const mockFetch = () => Object(_mock_requester_js__WEBPACK_IMPORTED_MODULE_1__[/
|
|
|
774
711
|
|
|
775
712
|
"use strict";
|
|
776
713
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return mockGqlFetch; });
|
|
777
|
-
/* harmony import */ var _gql_request_matches_mock_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
|
|
778
|
-
/* harmony import */ var _mock_requester_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
|
|
714
|
+
/* harmony import */ var _gql_request_matches_mock_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(21);
|
|
715
|
+
/* harmony import */ var _mock_requester_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
|
|
779
716
|
|
|
780
717
|
|
|
781
718
|
|
|
@@ -790,6 +727,224 @@ const mockGqlFetch = () => Object(_mock_requester_js__WEBPACK_IMPORTED_MODULE_1_
|
|
|
790
727
|
/* 15 */
|
|
791
728
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
792
729
|
|
|
730
|
+
"use strict";
|
|
731
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return RespondWith; });
|
|
732
|
+
/* harmony import */ var _settle_signal_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6);
|
|
733
|
+
/* harmony import */ var _response_impl_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(22);
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* Helper for creating a text-based mock response.
|
|
739
|
+
*/
|
|
740
|
+
const textResponse = (text, statusCode, signal) => ({
|
|
741
|
+
toPromise: () => makeMockResponse({
|
|
742
|
+
type: "text",
|
|
743
|
+
text,
|
|
744
|
+
statusCode,
|
|
745
|
+
signal
|
|
746
|
+
})
|
|
747
|
+
});
|
|
748
|
+
/**
|
|
749
|
+
* Helper for creating a rejected mock response.
|
|
750
|
+
*/
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
const rejectResponse = (error, signal) => ({
|
|
754
|
+
toPromise: () => makeMockResponse({
|
|
755
|
+
type: "reject",
|
|
756
|
+
error,
|
|
757
|
+
signal
|
|
758
|
+
})
|
|
759
|
+
});
|
|
760
|
+
/**
|
|
761
|
+
* Helpers to define mock responses for mocked requests.
|
|
762
|
+
*/
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
const RespondWith = Object.freeze({
|
|
766
|
+
/**
|
|
767
|
+
* Response with text body and status code.
|
|
768
|
+
* Status code defaults to 200.
|
|
769
|
+
*/
|
|
770
|
+
text: (text, statusCode = 200, signal = null) => textResponse(text, statusCode, signal),
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Response with JSON body and status code 200.
|
|
774
|
+
*/
|
|
775
|
+
json: (json, signal = null) => textResponse(() => JSON.stringify(json), 200, signal),
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Response with GraphQL data JSON body and status code 200.
|
|
779
|
+
*/
|
|
780
|
+
graphQLData: (data, signal = null) => textResponse(() => JSON.stringify({
|
|
781
|
+
data
|
|
782
|
+
}), 200, signal),
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* Response with body that will not parse as JSON and status code 200.
|
|
786
|
+
*/
|
|
787
|
+
unparseableBody: (signal = null) => textResponse("INVALID JSON", 200, signal),
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* Rejects with an AbortError to simulate an aborted request.
|
|
791
|
+
*/
|
|
792
|
+
abortedRequest: (signal = null) => rejectResponse(() => {
|
|
793
|
+
const abortError = new Error("Mock request aborted");
|
|
794
|
+
abortError.name = "AbortError";
|
|
795
|
+
return abortError;
|
|
796
|
+
}, signal),
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Rejects with the given error.
|
|
800
|
+
*/
|
|
801
|
+
reject: (error, signal = null) => rejectResponse(error, signal),
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* A non-200 status code with empty text body.
|
|
805
|
+
* Equivalent to calling `ResponseWith.text("", statusCode)`.
|
|
806
|
+
*/
|
|
807
|
+
errorStatusCode: (statusCode, signal = null) => {
|
|
808
|
+
if (statusCode < 300) {
|
|
809
|
+
throw new Error(`${statusCode} is not a valid error status code`);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
return textResponse("{}", statusCode, signal);
|
|
813
|
+
},
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* Response body that is valid JSON but not a valid GraphQL response.
|
|
817
|
+
*/
|
|
818
|
+
nonGraphQLBody: (signal = null) => textResponse(() => JSON.stringify({
|
|
819
|
+
valid: "json",
|
|
820
|
+
that: "is not a valid graphql response"
|
|
821
|
+
}), 200, signal),
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Response that is a GraphQL errors response with status code 200.
|
|
825
|
+
*/
|
|
826
|
+
graphQLErrors: (errorMessages, signal = null) => textResponse(() => JSON.stringify({
|
|
827
|
+
errors: errorMessages.map(e => ({
|
|
828
|
+
message: e
|
|
829
|
+
}))
|
|
830
|
+
}), 200, signal)
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
const callOnSettled = (signal, fn) => {
|
|
834
|
+
if (signal == null || signal.settled) {
|
|
835
|
+
fn();
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
const onSettled = () => {
|
|
840
|
+
signal.removeEventListener("settled", onSettled);
|
|
841
|
+
fn();
|
|
842
|
+
};
|
|
843
|
+
|
|
844
|
+
signal.addEventListener("settled", onSettled);
|
|
845
|
+
};
|
|
846
|
+
/**
|
|
847
|
+
* Turns a MockResponse value to an actual Response that represents the mock.
|
|
848
|
+
*/
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
const makeMockResponse = response => {
|
|
852
|
+
const {
|
|
853
|
+
signal
|
|
854
|
+
} = response;
|
|
855
|
+
|
|
856
|
+
switch (response.type) {
|
|
857
|
+
case "text":
|
|
858
|
+
return new Promise((resolve, reject) => {
|
|
859
|
+
callOnSettled(signal, () => {
|
|
860
|
+
const text = typeof response.text === "function" ? response.text() : response.text;
|
|
861
|
+
resolve(new _response_impl_js__WEBPACK_IMPORTED_MODULE_1__[/* ResponseImpl */ "a"](text, {
|
|
862
|
+
status: response.statusCode
|
|
863
|
+
}));
|
|
864
|
+
});
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
case "reject":
|
|
868
|
+
return new Promise((resolve, reject) => {
|
|
869
|
+
callOnSettled(signal, () => reject(response.error instanceof Error ? response.error : response.error()));
|
|
870
|
+
});
|
|
871
|
+
|
|
872
|
+
/* istanbul ignore next */
|
|
873
|
+
|
|
874
|
+
default:
|
|
875
|
+
if (false) {} // Production; assume a rejection.
|
|
876
|
+
|
|
877
|
+
|
|
878
|
+
return makeMockResponse({
|
|
879
|
+
type: "reject",
|
|
880
|
+
error: new Error("Unknown response type"),
|
|
881
|
+
signal
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
|
|
886
|
+
/***/ }),
|
|
887
|
+
/* 16 */
|
|
888
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
889
|
+
|
|
890
|
+
"use strict";
|
|
891
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return SettleController; });
|
|
892
|
+
/* harmony import */ var _settle_signal_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6);
|
|
893
|
+
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
894
|
+
|
|
895
|
+
var id = 0;
|
|
896
|
+
|
|
897
|
+
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* A controller for the `RespondWith` API to control response settlement.
|
|
902
|
+
*/
|
|
903
|
+
|
|
904
|
+
var _settleFn = /*#__PURE__*/_classPrivateFieldLooseKey("settleFn");
|
|
905
|
+
|
|
906
|
+
var _signal = /*#__PURE__*/_classPrivateFieldLooseKey("signal");
|
|
907
|
+
|
|
908
|
+
class SettleController {
|
|
909
|
+
constructor() {
|
|
910
|
+
Object.defineProperty(this, _settleFn, {
|
|
911
|
+
writable: true,
|
|
912
|
+
value: void 0
|
|
913
|
+
});
|
|
914
|
+
Object.defineProperty(this, _signal, {
|
|
915
|
+
writable: true,
|
|
916
|
+
value: void 0
|
|
917
|
+
});
|
|
918
|
+
// Create our signal.
|
|
919
|
+
// We pass in a method to capture it's settle function so that
|
|
920
|
+
// only we can call it.
|
|
921
|
+
_classPrivateFieldLooseBase(this, _signal)[_signal] = new _settle_signal_js__WEBPACK_IMPORTED_MODULE_0__[/* SettleSignal */ "a"](settleFn => _classPrivateFieldLooseBase(this, _settleFn)[_settleFn] = settleFn);
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* The signal to pass to the `RespondWith` API.
|
|
925
|
+
*/
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
get signal() {
|
|
929
|
+
return _classPrivateFieldLooseBase(this, _signal)[_signal];
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Settle the signal and therefore any associated responses.
|
|
933
|
+
*
|
|
934
|
+
* @throws {Error} if the signal has already been settled.
|
|
935
|
+
*/
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
settle() {
|
|
939
|
+
_classPrivateFieldLooseBase(this, _settleFn)[_settleFn]();
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/***/ }),
|
|
945
|
+
/* 17 */
|
|
946
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
947
|
+
|
|
793
948
|
"use strict";
|
|
794
949
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
795
950
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
@@ -799,14 +954,14 @@ const mockGqlFetch = () => Object(_mock_requester_js__WEBPACK_IMPORTED_MODULE_1_
|
|
|
799
954
|
*/
|
|
800
955
|
|
|
801
956
|
/***/ }),
|
|
802
|
-
/*
|
|
957
|
+
/* 18 */
|
|
803
958
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
804
959
|
|
|
805
960
|
"use strict";
|
|
806
961
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return hookHarness; });
|
|
807
962
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
808
963
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
809
|
-
/* harmony import */ var _make_hook_harness_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
|
|
964
|
+
/* harmony import */ var _make_hook_harness_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4);
|
|
810
965
|
/* harmony import */ var _adapters_adapters_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(1);
|
|
811
966
|
|
|
812
967
|
|
|
@@ -824,7 +979,7 @@ const mockGqlFetch = () => Object(_mock_requester_js__WEBPACK_IMPORTED_MODULE_1_
|
|
|
824
979
|
const hookHarness = Object(_make_hook_harness_js__WEBPACK_IMPORTED_MODULE_1__[/* makeHookHarness */ "a"])(_adapters_adapters_js__WEBPACK_IMPORTED_MODULE_2__["DefaultAdapters"], _adapters_adapters_js__WEBPACK_IMPORTED_MODULE_2__["DefaultConfigs"]);
|
|
825
980
|
|
|
826
981
|
/***/ }),
|
|
827
|
-
/*
|
|
982
|
+
/* 19 */
|
|
828
983
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
829
984
|
|
|
830
985
|
"use strict";
|
|
@@ -849,7 +1004,7 @@ const hookHarness = Object(_make_hook_harness_js__WEBPACK_IMPORTED_MODULE_1__[/*
|
|
|
849
1004
|
const testHarness = Object(_make_test_harness_js__WEBPACK_IMPORTED_MODULE_1__[/* makeTestHarness */ "a"])(_adapters_adapters_js__WEBPACK_IMPORTED_MODULE_2__["DefaultAdapters"], _adapters_adapters_js__WEBPACK_IMPORTED_MODULE_2__["DefaultConfigs"]);
|
|
850
1005
|
|
|
851
1006
|
/***/ }),
|
|
852
|
-
/*
|
|
1007
|
+
/* 20 */
|
|
853
1008
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
854
1009
|
|
|
855
1010
|
"use strict";
|
|
@@ -892,20 +1047,7 @@ const fetchRequestMatchesMock = (mock, input, init) => {
|
|
|
892
1047
|
};
|
|
893
1048
|
|
|
894
1049
|
/***/ }),
|
|
895
|
-
/*
|
|
896
|
-
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
897
|
-
|
|
898
|
-
"use strict";
|
|
899
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ResponseImpl; });
|
|
900
|
-
// We need a version of Response. When we're in Jest JSDOM environment or a
|
|
901
|
-
// version of Node that supports the fetch API (17 and up, possibly with
|
|
902
|
-
// --experimental-fetch flag), then we're good, but otherwise we need an
|
|
903
|
-
// implementation, so this uses node-fetch as a peer dependency and uses that
|
|
904
|
-
// to provide the implementation if we don't already have one.
|
|
905
|
-
const ResponseImpl = typeof Response === "undefined" ? __webpack_require__(24).Response : Response;
|
|
906
|
-
|
|
907
|
-
/***/ }),
|
|
908
|
-
/* 20 */
|
|
1050
|
+
/* 21 */
|
|
909
1051
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
910
1052
|
|
|
911
1053
|
"use strict";
|
|
@@ -980,13 +1122,26 @@ const gqlRequestMatchesMock = (mock, operation, variables, context) => {
|
|
|
980
1122
|
};
|
|
981
1123
|
|
|
982
1124
|
/***/ }),
|
|
983
|
-
/*
|
|
1125
|
+
/* 22 */
|
|
1126
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1127
|
+
|
|
1128
|
+
"use strict";
|
|
1129
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ResponseImpl; });
|
|
1130
|
+
// We need a version of Response. When we're in Jest JSDOM environment or a
|
|
1131
|
+
// version of Node that supports the fetch API (17 and up, possibly with
|
|
1132
|
+
// --experimental-fetch flag), then we're good, but otherwise we need an
|
|
1133
|
+
// implementation, so this uses node-fetch as a peer dependency and uses that
|
|
1134
|
+
// to provide the implementation if we don't already have one.
|
|
1135
|
+
const ResponseImpl = typeof Response === "undefined" ? __webpack_require__(26).Response : Response;
|
|
1136
|
+
|
|
1137
|
+
/***/ }),
|
|
1138
|
+
/* 23 */
|
|
984
1139
|
/***/ (function(module, exports) {
|
|
985
1140
|
|
|
986
1141
|
module.exports = require("@khanacademy/wonder-blocks-data");
|
|
987
1142
|
|
|
988
1143
|
/***/ }),
|
|
989
|
-
/*
|
|
1144
|
+
/* 24 */
|
|
990
1145
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
991
1146
|
|
|
992
1147
|
"use strict";
|
|
@@ -1018,7 +1173,7 @@ const renderAdapters = (adapters, configs, children) => {
|
|
|
1018
1173
|
};
|
|
1019
1174
|
|
|
1020
1175
|
/***/ }),
|
|
1021
|
-
/*
|
|
1176
|
+
/* 25 */
|
|
1022
1177
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1023
1178
|
|
|
1024
1179
|
"use strict";
|
|
@@ -1032,23 +1187,26 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1032
1187
|
/* harmony import */ var _gql_mock_gql_fetch_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(14);
|
|
1033
1188
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "mockGqlFetch", function() { return _gql_mock_gql_fetch_js__WEBPACK_IMPORTED_MODULE_2__["a"]; });
|
|
1034
1189
|
|
|
1035
|
-
/* harmony import */ var
|
|
1036
|
-
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RespondWith", function() { return
|
|
1190
|
+
/* harmony import */ var _respond_with_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(15);
|
|
1191
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RespondWith", function() { return _respond_with_js__WEBPACK_IMPORTED_MODULE_3__["a"]; });
|
|
1192
|
+
|
|
1193
|
+
/* harmony import */ var _settle_controller_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(16);
|
|
1194
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "SettleController", function() { return _settle_controller_js__WEBPACK_IMPORTED_MODULE_4__["a"]; });
|
|
1037
1195
|
|
|
1038
|
-
/* harmony import */ var
|
|
1039
|
-
/* harmony import */ var
|
|
1040
|
-
/* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "harnessAdapters", function() { return
|
|
1041
|
-
/* harmony import */ var
|
|
1042
|
-
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeHookHarness", function() { return
|
|
1196
|
+
/* harmony import */ var _harness_types_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(17);
|
|
1197
|
+
/* harmony import */ var _harness_adapters_adapters_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(1);
|
|
1198
|
+
/* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "harnessAdapters", function() { return _harness_adapters_adapters_js__WEBPACK_IMPORTED_MODULE_6__; });
|
|
1199
|
+
/* harmony import */ var _harness_make_hook_harness_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(4);
|
|
1200
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeHookHarness", function() { return _harness_make_hook_harness_js__WEBPACK_IMPORTED_MODULE_7__["a"]; });
|
|
1043
1201
|
|
|
1044
|
-
/* harmony import */ var
|
|
1045
|
-
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeTestHarness", function() { return
|
|
1202
|
+
/* harmony import */ var _harness_make_test_harness_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(3);
|
|
1203
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeTestHarness", function() { return _harness_make_test_harness_js__WEBPACK_IMPORTED_MODULE_8__["a"]; });
|
|
1046
1204
|
|
|
1047
|
-
/* harmony import */ var
|
|
1048
|
-
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "hookHarness", function() { return
|
|
1205
|
+
/* harmony import */ var _harness_hook_harness_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(18);
|
|
1206
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "hookHarness", function() { return _harness_hook_harness_js__WEBPACK_IMPORTED_MODULE_9__["a"]; });
|
|
1049
1207
|
|
|
1050
|
-
/* harmony import */ var
|
|
1051
|
-
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "testHarness", function() { return
|
|
1208
|
+
/* harmony import */ var _harness_test_harness_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(19);
|
|
1209
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "testHarness", function() { return _harness_test_harness_js__WEBPACK_IMPORTED_MODULE_10__["a"]; });
|
|
1052
1210
|
|
|
1053
1211
|
// Fixtures framework
|
|
1054
1212
|
|
|
@@ -1056,6 +1214,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1056
1214
|
|
|
1057
1215
|
|
|
1058
1216
|
|
|
1217
|
+
|
|
1059
1218
|
// Test harness framework
|
|
1060
1219
|
|
|
1061
1220
|
|
|
@@ -1066,7 +1225,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1066
1225
|
|
|
1067
1226
|
|
|
1068
1227
|
/***/ }),
|
|
1069
|
-
/*
|
|
1228
|
+
/* 26 */
|
|
1070
1229
|
/***/ (function(module, exports) {
|
|
1071
1230
|
|
|
1072
1231
|
module.exports = require("node-fetch");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-testing",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.1",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/runtime": "^7.18.6",
|
|
17
|
-
"@khanacademy/wonder-blocks-data": "^
|
|
17
|
+
"@khanacademy/wonder-blocks-data": "^9.1.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@khanacademy/wonder-stuff-core": "^0.1.2",
|