@khanacademy/wonder-blocks-testing 3.0.0 → 4.0.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 +18 -0
- package/dist/es/index.js +144 -316
- package/dist/index.js +271 -143
- package/package.json +4 -3
- 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/fixtures/__tests__/fixtures.test.js +32 -1
- package/src/fixtures/fixtures.js +15 -5
- 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,17 +404,15 @@ 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
|
|
|
328
411
|
|
|
329
412
|
const normalizeOptions = componentOrOptions => {
|
|
330
413
|
// To differentiate between a React component and a FixturesOptions object,
|
|
331
|
-
// we have to do some type checking.
|
|
332
|
-
//
|
|
333
|
-
// this should do the trick without relying on internal React details like
|
|
334
|
-
// protoype.isReactComponent. This should be sufficient for our purposes.
|
|
414
|
+
// we have to do some type checking.
|
|
415
|
+
//
|
|
335
416
|
// Alternatives I considered were:
|
|
336
417
|
// - Use an additional parameter for the options and then do an arg number
|
|
337
418
|
// check, but that always makes typing a function harder and often breaks
|
|
@@ -340,8 +421,17 @@ const normalizeOptions = componentOrOptions => {
|
|
|
340
421
|
// being the component and the second being the options. However that
|
|
341
422
|
// feels like an obscure API even though it's really easy to do the
|
|
342
423
|
// typing.
|
|
343
|
-
if (
|
|
424
|
+
if ( // Most React components, whether functional or class-based, are
|
|
425
|
+
// inherently functions in JavaScript, so a check for functions is
|
|
426
|
+
// usually sufficient.
|
|
427
|
+
typeof componentOrOptions === "function" || // However, the return of React.forwardRef is not a function,
|
|
428
|
+
// so we also have to cope with that.
|
|
429
|
+
// A forwardRef has $$typeof = Symbol(react.forward_ref) and a
|
|
430
|
+
// render function.
|
|
431
|
+
// $FlowIgnore[prop-missing]
|
|
432
|
+
typeof componentOrOptions.render === "function") {
|
|
344
433
|
return {
|
|
434
|
+
// $FlowIgnore[incompatible-return]
|
|
345
435
|
component: componentOrOptions
|
|
346
436
|
};
|
|
347
437
|
} // We can't test for React.ComponentType at runtime.
|
|
@@ -412,80 +502,53 @@ const fixtures = (componentOrOptions, fn) => {
|
|
|
412
502
|
};
|
|
413
503
|
|
|
414
504
|
/***/ }),
|
|
415
|
-
/*
|
|
505
|
+
/* 7 */
|
|
416
506
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
417
507
|
|
|
418
508
|
"use strict";
|
|
419
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return
|
|
420
|
-
/* harmony import */ var
|
|
421
|
-
/* 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);
|
|
422
512
|
|
|
423
513
|
|
|
424
514
|
|
|
425
515
|
/**
|
|
426
516
|
* A mock for the fetch function passed to GqlRouter.
|
|
427
517
|
*/
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
// This is the array of mocked operations that we will traverse and
|
|
431
|
-
// manipulate.
|
|
432
|
-
const mocks = []; // What we return has to be a drop in for the fetch function that is
|
|
433
|
-
// 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)}`);
|
|
434
520
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
if (mock.onceOnly && mock.used) {
|
|
439
|
-
// This is a once-only mock and it has been used, so skip it.
|
|
440
|
-
continue;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
if (Object(_gql_request_matches_mock_js__WEBPACK_IMPORTED_MODULE_0__[/* gqlRequestMatchesMock */ "a"])(mock.operation, operation, variables, context)) {
|
|
444
|
-
mock.used = true;
|
|
445
|
-
return mock.response();
|
|
446
|
-
}
|
|
447
|
-
} // Default is to reject with some helpful info on what request
|
|
448
|
-
// we rejected.
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
return Promise.reject(new Error(`No matching GraphQL mock response found for request:
|
|
452
|
-
Operation: ${operation.type} ${operation.id}
|
|
453
|
-
Variables: ${variables == null ? "None" : JSON.stringify(variables, null, 2)}
|
|
454
|
-
Context: ${JSON.stringify(context, null, 2)}`));
|
|
455
|
-
};
|
|
456
|
-
|
|
457
|
-
const addMockedOperation = (operation, response, onceOnly) => {
|
|
458
|
-
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__) {
|
|
459
524
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
used: false
|
|
465
|
-
});
|
|
466
|
-
return gqlFetchMock;
|
|
467
|
-
};
|
|
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);
|
|
468
529
|
|
|
469
|
-
gqlFetchMock.mockOperation = (operation, response) => addMockedOperation(operation, response, false);
|
|
470
530
|
|
|
471
|
-
gqlFetchMock.mockOperationOnce = (operation, response) => addMockedOperation(operation, response, true);
|
|
472
531
|
|
|
473
|
-
|
|
474
|
-
|
|
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)}`);
|
|
475
538
|
|
|
476
539
|
/***/ }),
|
|
477
|
-
/*
|
|
540
|
+
/* 9 */
|
|
478
541
|
/***/ (function(module, exports) {
|
|
479
542
|
|
|
480
543
|
module.exports = require("@storybook/addon-actions");
|
|
481
544
|
|
|
482
545
|
/***/ }),
|
|
483
|
-
/*
|
|
546
|
+
/* 10 */
|
|
484
547
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
485
548
|
|
|
486
549
|
"use strict";
|
|
487
550
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Adapter; });
|
|
488
|
-
/* 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);
|
|
489
552
|
|
|
490
553
|
|
|
491
554
|
/**
|
|
@@ -540,7 +603,7 @@ class Adapter {
|
|
|
540
603
|
}
|
|
541
604
|
|
|
542
605
|
/***/ }),
|
|
543
|
-
/*
|
|
606
|
+
/* 11 */
|
|
544
607
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
545
608
|
|
|
546
609
|
"use strict";
|
|
@@ -605,12 +668,12 @@ class AdapterGroup {
|
|
|
605
668
|
}
|
|
606
669
|
|
|
607
670
|
/***/ }),
|
|
608
|
-
/*
|
|
671
|
+
/* 12 */
|
|
609
672
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
610
673
|
|
|
611
674
|
"use strict";
|
|
612
675
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return combineOptions; });
|
|
613
|
-
/* 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);
|
|
614
677
|
|
|
615
678
|
/**
|
|
616
679
|
* Combine one or more objects into a single object.
|
|
@@ -635,12 +698,12 @@ const combineOptions = (...toBeCombined) => {
|
|
|
635
698
|
};
|
|
636
699
|
|
|
637
700
|
/***/ }),
|
|
638
|
-
/*
|
|
701
|
+
/* 13 */
|
|
639
702
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
640
703
|
|
|
641
704
|
"use strict";
|
|
642
705
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return combineTopLevel; });
|
|
643
|
-
/* 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);
|
|
644
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__);
|
|
645
708
|
|
|
646
709
|
/**
|
|
@@ -681,13 +744,69 @@ const combineTopLevel = (val1, val2) => {
|
|
|
681
744
|
};
|
|
682
745
|
|
|
683
746
|
/***/ }),
|
|
684
|
-
/*
|
|
747
|
+
/* 14 */
|
|
685
748
|
/***/ (function(module, exports) {
|
|
686
749
|
|
|
687
750
|
module.exports = require("@khanacademy/wonder-stuff-core");
|
|
688
751
|
|
|
689
752
|
/***/ }),
|
|
690
|
-
/*
|
|
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 */
|
|
691
810
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
692
811
|
|
|
693
812
|
"use strict";
|
|
@@ -762,33 +881,42 @@ const gqlRequestMatchesMock = (mock, operation, variables, context) => {
|
|
|
762
881
|
};
|
|
763
882
|
|
|
764
883
|
/***/ }),
|
|
765
|
-
/*
|
|
884
|
+
/* 18 */
|
|
766
885
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
767
886
|
|
|
768
887
|
"use strict";
|
|
769
888
|
__webpack_require__.r(__webpack_exports__);
|
|
770
|
-
/* 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);
|
|
771
890
|
/* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "adapters", function() { return _fixtures_adapters_adapters_js__WEBPACK_IMPORTED_MODULE_0__; });
|
|
772
|
-
/* 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);
|
|
773
892
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fixtures", function() { return _fixtures_fixtures_js__WEBPACK_IMPORTED_MODULE_1__["a"]; });
|
|
774
893
|
|
|
775
894
|
/* harmony import */ var _fixtures_setup_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(0);
|
|
776
895
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setupFixtures", function() { return _fixtures_setup_js__WEBPACK_IMPORTED_MODULE_2__["b"]; });
|
|
777
896
|
|
|
778
|
-
/* harmony import */ var
|
|
779
|
-
/* 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"]; });
|
|
780
902
|
|
|
781
|
-
/* harmony import */ var
|
|
782
|
-
/* 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"]; });
|
|
783
905
|
|
|
784
906
|
// Fixtures framework
|
|
785
907
|
|
|
786
908
|
|
|
787
909
|
|
|
788
910
|
|
|
789
|
-
// GraphQL framework
|
|
790
911
|
|
|
791
912
|
|
|
792
913
|
|
|
914
|
+
|
|
915
|
+
/***/ }),
|
|
916
|
+
/* 19 */
|
|
917
|
+
/***/ (function(module, exports) {
|
|
918
|
+
|
|
919
|
+
module.exports = require("node-fetch");
|
|
920
|
+
|
|
793
921
|
/***/ })
|
|
794
922
|
/******/ ]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-testing",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -14,16 +14,17 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/runtime": "^7.16.3",
|
|
17
|
-
"@khanacademy/wonder-blocks-data": "^7.0.
|
|
17
|
+
"@khanacademy/wonder-blocks-data": "^7.0.1"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
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": {
|
|
26
|
-
"wb-dev-build-settings": "^0.
|
|
27
|
+
"wb-dev-build-settings": "^0.4.0"
|
|
27
28
|
},
|
|
28
29
|
"author": "",
|
|
29
30
|
"license": "MIT"
|