@ama-sdk/client-fetch 12.3.0-prerelease.70 → 12.3.0-prerelease.71
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/cjs/api-fetch-client.js +12 -13
- package/cjs/plugins/abort/abort.spec.js +79 -73
- package/cjs/plugins/concurrent/concurrent.fetch.js +8 -12
- package/cjs/plugins/concurrent/concurrent.spec.js +95 -91
- package/cjs/plugins/keepalive/keepalive.request.js +3 -4
- package/cjs/plugins/keepalive/keepalive.spec.js +28 -26
- package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +11 -14
- package/cjs/plugins/mock-intercept/mock-intercept.spec.js +243 -231
- package/cjs/plugins/perf-metric/perf-metric.fetch.js +7 -10
- package/cjs/plugins/retry/retry.fetch.js +14 -19
- package/cjs/plugins/retry/retry.spec.js +229 -217
- package/cjs/plugins/timeout/timeout.fetch.js +9 -11
- package/cjs/plugins/timeout/timeout.spec.js +207 -197
- package/cjs/plugins/wait-for/wait-for.fetch.js +15 -21
- package/cjs/plugins/wait-for/wait-for.spec.js +207 -195
- package/esm2015/api-fetch-client.js +12 -13
- package/esm2015/plugins/abort/abort.spec.js +79 -73
- package/esm2015/plugins/concurrent/concurrent.fetch.js +8 -12
- package/esm2015/plugins/concurrent/concurrent.spec.js +95 -91
- package/esm2015/plugins/keepalive/keepalive.request.js +3 -4
- package/esm2015/plugins/keepalive/keepalive.spec.js +28 -26
- package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +11 -14
- package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +243 -231
- package/esm2015/plugins/perf-metric/perf-metric.fetch.js +7 -10
- package/esm2015/plugins/retry/retry.fetch.js +14 -19
- package/esm2015/plugins/retry/retry.spec.js +229 -217
- package/esm2015/plugins/timeout/timeout.fetch.js +9 -11
- package/esm2015/plugins/timeout/timeout.spec.js +207 -197
- package/esm2015/plugins/wait-for/wait-for.fetch.js +15 -21
- package/esm2015/plugins/wait-for/wait-for.spec.js +207 -195
- package/package.json +8 -8
|
@@ -179,22 +179,22 @@ var MockInterceptFetch = /*#__PURE__*/ function() {
|
|
|
179
179
|
{
|
|
180
180
|
key: "load",
|
|
181
181
|
value: function load(context) {
|
|
182
|
+
var _this = this;
|
|
182
183
|
if (!context.apiClient.options.requestPlugins.some(function(plugin) {
|
|
183
184
|
return _instanceof(plugin, _core.MockInterceptRequest);
|
|
184
185
|
})) {
|
|
185
186
|
throw new Error('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin');
|
|
186
187
|
}
|
|
187
|
-
var _this = this;
|
|
188
188
|
return {
|
|
189
|
-
transform:
|
|
190
|
-
|
|
189
|
+
transform: function(fetchCall) {
|
|
190
|
+
return _async_to_generator(function() {
|
|
191
191
|
var responsePromise, delay, _tmp, resp, operationId, mock, response;
|
|
192
192
|
return _ts_generator(this, function(_state) {
|
|
193
193
|
switch(_state.label){
|
|
194
194
|
case 0:
|
|
195
195
|
return [
|
|
196
196
|
4,
|
|
197
|
-
|
|
197
|
+
this.options.adapter.initialize()
|
|
198
198
|
];
|
|
199
199
|
case 1:
|
|
200
200
|
_state.sent();
|
|
@@ -205,15 +205,15 @@ var MockInterceptFetch = /*#__PURE__*/ function() {
|
|
|
205
205
|
responsePromise
|
|
206
206
|
];
|
|
207
207
|
}
|
|
208
|
-
if (!(typeof
|
|
208
|
+
if (!(typeof this.options.delayTiming !== 'undefined')) return [
|
|
209
209
|
3,
|
|
210
210
|
6
|
|
211
211
|
];
|
|
212
|
-
if (!(typeof
|
|
212
|
+
if (!(typeof this.options.delayTiming === 'number')) return [
|
|
213
213
|
3,
|
|
214
214
|
2
|
|
215
215
|
];
|
|
216
|
-
_tmp =
|
|
216
|
+
_tmp = this.options.delayTiming;
|
|
217
217
|
return [
|
|
218
218
|
3,
|
|
219
219
|
4
|
|
@@ -221,7 +221,7 @@ var MockInterceptFetch = /*#__PURE__*/ function() {
|
|
|
221
221
|
case 2:
|
|
222
222
|
return [
|
|
223
223
|
4,
|
|
224
|
-
|
|
224
|
+
this.options.delayTiming(context)
|
|
225
225
|
];
|
|
226
226
|
case 3:
|
|
227
227
|
_tmp = _state.sent();
|
|
@@ -243,7 +243,7 @@ var MockInterceptFetch = /*#__PURE__*/ function() {
|
|
|
243
243
|
case 6:
|
|
244
244
|
operationId = context.options.headers.get(_core.CUSTOM_MOCK_OPERATION_ID_HEADER);
|
|
245
245
|
try {
|
|
246
|
-
mock =
|
|
246
|
+
mock = this.options.adapter.getLatestMock(operationId);
|
|
247
247
|
if (!mock.getResponse) {
|
|
248
248
|
return [
|
|
249
249
|
2,
|
|
@@ -269,11 +269,8 @@ var MockInterceptFetch = /*#__PURE__*/ function() {
|
|
|
269
269
|
];
|
|
270
270
|
}
|
|
271
271
|
});
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
return _ref.apply(this, arguments);
|
|
275
|
-
};
|
|
276
|
-
}()
|
|
272
|
+
}).call(_this);
|
|
273
|
+
}
|
|
277
274
|
};
|
|
278
275
|
}
|
|
279
276
|
}
|
|
@@ -167,113 +167,119 @@ describe('Mock intercept', function() {
|
|
|
167
167
|
return jest.clearAllMocks();
|
|
168
168
|
});
|
|
169
169
|
describe('request plugin', function() {
|
|
170
|
-
it('should do nothing if disabled is true',
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
170
|
+
it('should do nothing if disabled is true', function() {
|
|
171
|
+
return _async_to_generator(function() {
|
|
172
|
+
var plugin, originalRequest, loaded;
|
|
173
|
+
return _ts_generator(this, function(_state) {
|
|
174
|
+
switch(_state.label){
|
|
175
|
+
case 0:
|
|
176
|
+
plugin = new _core.MockInterceptRequest({
|
|
177
|
+
disabled: true,
|
|
178
|
+
adapter: testMockAdapter
|
|
179
|
+
});
|
|
180
|
+
originalRequest = {
|
|
181
|
+
method: 'get',
|
|
182
|
+
headers: new Headers({
|
|
183
|
+
test: 'true'
|
|
184
|
+
}),
|
|
185
|
+
basePath: 'myurl'
|
|
186
|
+
};
|
|
187
|
+
loaded = plugin.load();
|
|
188
|
+
return [
|
|
189
|
+
4,
|
|
190
|
+
loaded.transform(originalRequest)
|
|
191
|
+
];
|
|
192
|
+
case 1:
|
|
193
|
+
expect.apply(void 0, [
|
|
194
|
+
_state.sent()
|
|
195
|
+
]).toEqual(originalRequest);
|
|
196
|
+
expect(initializeSpy).toHaveBeenCalled();
|
|
197
|
+
return [
|
|
198
|
+
2
|
|
199
|
+
];
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
})();
|
|
203
|
+
});
|
|
204
|
+
it('should not stringify provided api', function() {
|
|
205
|
+
return _async_to_generator(function() {
|
|
206
|
+
var plugin, loaded, originalRequest;
|
|
207
|
+
return _ts_generator(this, function(_state) {
|
|
208
|
+
switch(_state.label){
|
|
209
|
+
case 0:
|
|
210
|
+
plugin = new _core.MockInterceptRequest({
|
|
211
|
+
disabled: false,
|
|
212
|
+
adapter: testMockAdapter
|
|
213
|
+
});
|
|
214
|
+
loaded = plugin.load();
|
|
215
|
+
originalRequest = {
|
|
216
|
+
method: 'get',
|
|
217
|
+
headers: new Headers({
|
|
218
|
+
test: 'true'
|
|
219
|
+
}),
|
|
220
|
+
basePath: 'myurl',
|
|
221
|
+
api: 'should not exist'
|
|
222
|
+
};
|
|
223
|
+
return [
|
|
224
|
+
4,
|
|
225
|
+
loaded.transform(originalRequest)
|
|
226
|
+
];
|
|
227
|
+
case 1:
|
|
228
|
+
_state.sent();
|
|
229
|
+
expect(originalRequest.headers.has(_core.CUSTOM_MOCK_REQUEST_HEADER)).toBe(true);
|
|
230
|
+
expect(Object.keys(JSON.parse(originalRequest.headers.get(_core.CUSTOM_MOCK_REQUEST_HEADER)))).not.toContainEqual('api');
|
|
231
|
+
return [
|
|
232
|
+
2
|
|
233
|
+
];
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
})();
|
|
237
|
+
});
|
|
238
|
+
it('should intercept the request', function() {
|
|
239
|
+
return _async_to_generator(function() {
|
|
240
|
+
var plugin, originalRequest, loaded, transformed, res;
|
|
241
|
+
return _ts_generator(this, function(_state) {
|
|
242
|
+
switch(_state.label){
|
|
243
|
+
case 0:
|
|
244
|
+
// Disabled because Blob URL is not supported on NodeJS
|
|
245
|
+
plugin = new _core.MockInterceptRequest({
|
|
246
|
+
adapter: testMockAdapter
|
|
247
|
+
});
|
|
248
|
+
originalRequest = {
|
|
249
|
+
headers: new Headers({
|
|
250
|
+
test: 'true'
|
|
251
|
+
}),
|
|
252
|
+
basePath: 'myurl',
|
|
253
|
+
method: 'PATCH'
|
|
254
|
+
};
|
|
255
|
+
loaded = plugin.load();
|
|
256
|
+
return [
|
|
257
|
+
4,
|
|
258
|
+
loaded.transform(originalRequest)
|
|
259
|
+
];
|
|
260
|
+
case 1:
|
|
261
|
+
transformed = _state.sent();
|
|
262
|
+
return [
|
|
263
|
+
4,
|
|
264
|
+
fetch(transformed.basePath, transformed)
|
|
265
|
+
];
|
|
266
|
+
case 2:
|
|
267
|
+
return [
|
|
268
|
+
4,
|
|
269
|
+
_state.sent().text()
|
|
270
|
+
];
|
|
271
|
+
case 3:
|
|
272
|
+
res = _state.sent();
|
|
273
|
+
expect(getMockSpy).toHaveBeenCalled();
|
|
274
|
+
expect(res).toBe(JSON.stringify(testMock.mockData));
|
|
275
|
+
expect(initializeSpy).toHaveBeenCalled();
|
|
276
|
+
return [
|
|
277
|
+
2
|
|
278
|
+
];
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
})();
|
|
282
|
+
});
|
|
277
283
|
});
|
|
278
284
|
describe('fetch plugin', function() {
|
|
279
285
|
describe('when using an initialization function', function() {
|
|
@@ -290,152 +296,158 @@ describe('Mock intercept', function() {
|
|
|
290
296
|
adapter: asyncMockAdapter
|
|
291
297
|
});
|
|
292
298
|
});
|
|
293
|
-
it('should call initialize fn',
|
|
294
|
-
|
|
299
|
+
it('should call initialize fn', function() {
|
|
300
|
+
return _async_to_generator(function() {
|
|
301
|
+
var loadedPlugin, testData;
|
|
302
|
+
return _ts_generator(this, function(_state) {
|
|
303
|
+
switch(_state.label){
|
|
304
|
+
case 0:
|
|
305
|
+
loadedPlugin = plugin.load({
|
|
306
|
+
controller: jest.fn(),
|
|
307
|
+
fetchPlugins: [],
|
|
308
|
+
url: 'myurl',
|
|
309
|
+
apiClient: apiClient,
|
|
310
|
+
options: {
|
|
311
|
+
headers: new Headers(_define_property({}, _core.CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
testData = {
|
|
315
|
+
test: true
|
|
316
|
+
};
|
|
317
|
+
return [
|
|
318
|
+
4,
|
|
319
|
+
loadedPlugin.transform(Promise.resolve(testData))
|
|
320
|
+
];
|
|
321
|
+
case 1:
|
|
322
|
+
_state.sent();
|
|
323
|
+
expect(initializeSpy).toHaveBeenCalled();
|
|
324
|
+
expect(getMockSpy).not.toHaveBeenCalled();
|
|
325
|
+
expect(getLatestMockSpy).toHaveBeenCalledWith('testOperation');
|
|
326
|
+
return [
|
|
327
|
+
2
|
|
328
|
+
];
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
})();
|
|
332
|
+
});
|
|
333
|
+
it('should throw if there is no request plugin', function() {
|
|
334
|
+
var config = {
|
|
335
|
+
controller: jest.fn(),
|
|
336
|
+
fetchPlugins: [],
|
|
337
|
+
url: 'myurl',
|
|
338
|
+
apiClient: {
|
|
339
|
+
options: {
|
|
340
|
+
requestPlugins: []
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
options: {
|
|
344
|
+
headers: new Headers(_define_property({}, _core.CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
expect(function() {
|
|
348
|
+
return plugin.load(config);
|
|
349
|
+
}).toThrow();
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
describe('with delay', function() {
|
|
354
|
+
it('should delay the response of the specific number', function() {
|
|
355
|
+
return _async_to_generator(function() {
|
|
356
|
+
var plugin, loadedPlugin, callback, run;
|
|
295
357
|
return _ts_generator(this, function(_state) {
|
|
296
358
|
switch(_state.label){
|
|
297
359
|
case 0:
|
|
360
|
+
plugin = new _mockinterceptfetch.MockInterceptFetch({
|
|
361
|
+
adapter: testMockAdapter,
|
|
362
|
+
delayTiming: 700
|
|
363
|
+
});
|
|
298
364
|
loadedPlugin = plugin.load({
|
|
299
365
|
controller: jest.fn(),
|
|
300
366
|
fetchPlugins: [],
|
|
301
|
-
url: '
|
|
367
|
+
url: '',
|
|
302
368
|
apiClient: apiClient,
|
|
303
369
|
options: {
|
|
304
370
|
headers: new Headers(_define_property({}, _core.CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
305
371
|
}
|
|
306
372
|
});
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
};
|
|
373
|
+
callback = jest.fn();
|
|
374
|
+
run = loadedPlugin.transform(Promise.resolve({})).then(callback);
|
|
310
375
|
return [
|
|
311
376
|
4,
|
|
312
|
-
|
|
377
|
+
jest.advanceTimersByTimeAsync(699)
|
|
313
378
|
];
|
|
314
379
|
case 1:
|
|
315
380
|
_state.sent();
|
|
316
|
-
expect(
|
|
317
|
-
|
|
318
|
-
|
|
381
|
+
expect(callback).not.toHaveBeenCalled();
|
|
382
|
+
return [
|
|
383
|
+
4,
|
|
384
|
+
jest.advanceTimersByTimeAsync(1)
|
|
385
|
+
];
|
|
386
|
+
case 2:
|
|
387
|
+
_state.sent();
|
|
388
|
+
expect(callback).toHaveBeenCalled();
|
|
389
|
+
return [
|
|
390
|
+
4,
|
|
391
|
+
run
|
|
392
|
+
];
|
|
393
|
+
case 3:
|
|
394
|
+
_state.sent();
|
|
319
395
|
return [
|
|
320
396
|
2
|
|
321
397
|
];
|
|
322
398
|
}
|
|
323
399
|
});
|
|
324
|
-
}));
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
400
|
+
})();
|
|
401
|
+
});
|
|
402
|
+
it('should delay the response based on callback', function() {
|
|
403
|
+
return _async_to_generator(function() {
|
|
404
|
+
var plugin, loadedPlugin, callback, run;
|
|
405
|
+
return _ts_generator(this, function(_state) {
|
|
406
|
+
switch(_state.label){
|
|
407
|
+
case 0:
|
|
408
|
+
plugin = new _mockinterceptfetch.MockInterceptFetch({
|
|
409
|
+
adapter: testMockAdapter,
|
|
410
|
+
delayTiming: function() {
|
|
411
|
+
return 800;
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
loadedPlugin = plugin.load({
|
|
415
|
+
controller: jest.fn(),
|
|
416
|
+
fetchPlugins: [],
|
|
417
|
+
url: '',
|
|
418
|
+
apiClient: apiClient,
|
|
419
|
+
options: {
|
|
420
|
+
headers: new Headers(_define_property({}, _core.CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
callback = jest.fn();
|
|
424
|
+
run = loadedPlugin.transform(Promise.resolve({})).then(callback);
|
|
425
|
+
return [
|
|
426
|
+
4,
|
|
427
|
+
jest.advanceTimersByTimeAsync(799)
|
|
428
|
+
];
|
|
429
|
+
case 1:
|
|
430
|
+
_state.sent();
|
|
431
|
+
expect(callback).not.toHaveBeenCalled();
|
|
432
|
+
return [
|
|
433
|
+
4,
|
|
434
|
+
jest.advanceTimersByTimeAsync(1)
|
|
435
|
+
];
|
|
436
|
+
case 2:
|
|
437
|
+
_state.sent();
|
|
438
|
+
expect(callback).toHaveBeenCalled();
|
|
439
|
+
return [
|
|
440
|
+
4,
|
|
441
|
+
run
|
|
442
|
+
];
|
|
443
|
+
case 3:
|
|
444
|
+
_state.sent();
|
|
445
|
+
return [
|
|
446
|
+
2
|
|
447
|
+
];
|
|
337
448
|
}
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
return plugin.load(config);
|
|
341
|
-
}).toThrow();
|
|
342
|
-
});
|
|
449
|
+
});
|
|
450
|
+
})();
|
|
343
451
|
});
|
|
344
452
|
});
|
|
345
|
-
describe('with delay', function() {
|
|
346
|
-
it('should delay the response of the specific number', /*#__PURE__*/ _async_to_generator(function() {
|
|
347
|
-
var plugin, loadedPlugin, callback, run;
|
|
348
|
-
return _ts_generator(this, function(_state) {
|
|
349
|
-
switch(_state.label){
|
|
350
|
-
case 0:
|
|
351
|
-
plugin = new _mockinterceptfetch.MockInterceptFetch({
|
|
352
|
-
adapter: testMockAdapter,
|
|
353
|
-
delayTiming: 700
|
|
354
|
-
});
|
|
355
|
-
loadedPlugin = plugin.load({
|
|
356
|
-
controller: jest.fn(),
|
|
357
|
-
fetchPlugins: [],
|
|
358
|
-
url: '',
|
|
359
|
-
apiClient: apiClient,
|
|
360
|
-
options: {
|
|
361
|
-
headers: new Headers(_define_property({}, _core.CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
362
|
-
}
|
|
363
|
-
});
|
|
364
|
-
callback = jest.fn();
|
|
365
|
-
run = loadedPlugin.transform(Promise.resolve({})).then(callback);
|
|
366
|
-
return [
|
|
367
|
-
4,
|
|
368
|
-
jest.advanceTimersByTimeAsync(699)
|
|
369
|
-
];
|
|
370
|
-
case 1:
|
|
371
|
-
_state.sent();
|
|
372
|
-
expect(callback).not.toHaveBeenCalled();
|
|
373
|
-
return [
|
|
374
|
-
4,
|
|
375
|
-
jest.advanceTimersByTimeAsync(1)
|
|
376
|
-
];
|
|
377
|
-
case 2:
|
|
378
|
-
_state.sent();
|
|
379
|
-
expect(callback).toHaveBeenCalled();
|
|
380
|
-
return [
|
|
381
|
-
4,
|
|
382
|
-
run
|
|
383
|
-
];
|
|
384
|
-
case 3:
|
|
385
|
-
_state.sent();
|
|
386
|
-
return [
|
|
387
|
-
2
|
|
388
|
-
];
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
}));
|
|
392
|
-
it('should delay the response based on callback', /*#__PURE__*/ _async_to_generator(function() {
|
|
393
|
-
var plugin, loadedPlugin, callback, run;
|
|
394
|
-
return _ts_generator(this, function(_state) {
|
|
395
|
-
switch(_state.label){
|
|
396
|
-
case 0:
|
|
397
|
-
plugin = new _mockinterceptfetch.MockInterceptFetch({
|
|
398
|
-
adapter: testMockAdapter,
|
|
399
|
-
delayTiming: function() {
|
|
400
|
-
return 800;
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
loadedPlugin = plugin.load({
|
|
404
|
-
controller: jest.fn(),
|
|
405
|
-
fetchPlugins: [],
|
|
406
|
-
url: '',
|
|
407
|
-
apiClient: apiClient,
|
|
408
|
-
options: {
|
|
409
|
-
headers: new Headers(_define_property({}, _core.CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
callback = jest.fn();
|
|
413
|
-
run = loadedPlugin.transform(Promise.resolve({})).then(callback);
|
|
414
|
-
return [
|
|
415
|
-
4,
|
|
416
|
-
jest.advanceTimersByTimeAsync(799)
|
|
417
|
-
];
|
|
418
|
-
case 1:
|
|
419
|
-
_state.sent();
|
|
420
|
-
expect(callback).not.toHaveBeenCalled();
|
|
421
|
-
return [
|
|
422
|
-
4,
|
|
423
|
-
jest.advanceTimersByTimeAsync(1)
|
|
424
|
-
];
|
|
425
|
-
case 2:
|
|
426
|
-
_state.sent();
|
|
427
|
-
expect(callback).toHaveBeenCalled();
|
|
428
|
-
return [
|
|
429
|
-
4,
|
|
430
|
-
run
|
|
431
|
-
];
|
|
432
|
-
case 3:
|
|
433
|
-
_state.sent();
|
|
434
|
-
return [
|
|
435
|
-
2
|
|
436
|
-
];
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
}));
|
|
440
|
-
});
|
|
441
453
|
});
|
|
@@ -318,13 +318,13 @@ var PerformanceMetricPlugin = /*#__PURE__*/ function() {
|
|
|
318
318
|
value: /** @inheritDoc */ function load(context) {
|
|
319
319
|
var _this = this;
|
|
320
320
|
return {
|
|
321
|
-
transform:
|
|
322
|
-
|
|
321
|
+
transform: function(fetchCall) {
|
|
322
|
+
return _async_to_generator(function() {
|
|
323
323
|
var markId, response, exception;
|
|
324
324
|
return _ts_generator(this, function(_state) {
|
|
325
325
|
switch(_state.label){
|
|
326
326
|
case 0:
|
|
327
|
-
markId =
|
|
327
|
+
markId = this.openMark(context.url, context.options);
|
|
328
328
|
_state.label = 1;
|
|
329
329
|
case 1:
|
|
330
330
|
_state.trys.push([
|
|
@@ -339,14 +339,14 @@ var PerformanceMetricPlugin = /*#__PURE__*/ function() {
|
|
|
339
339
|
];
|
|
340
340
|
case 2:
|
|
341
341
|
response = _state.sent();
|
|
342
|
-
|
|
342
|
+
this.closeMark(markId, response);
|
|
343
343
|
return [
|
|
344
344
|
2,
|
|
345
345
|
response
|
|
346
346
|
];
|
|
347
347
|
case 3:
|
|
348
348
|
exception = _state.sent();
|
|
349
|
-
|
|
349
|
+
this.closeMarkWithError(markId, exception);
|
|
350
350
|
throw exception;
|
|
351
351
|
case 4:
|
|
352
352
|
return [
|
|
@@ -354,11 +354,8 @@ var PerformanceMetricPlugin = /*#__PURE__*/ function() {
|
|
|
354
354
|
];
|
|
355
355
|
}
|
|
356
356
|
});
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
return _ref.apply(this, arguments);
|
|
360
|
-
};
|
|
361
|
-
}()
|
|
357
|
+
}).call(_this);
|
|
358
|
+
}
|
|
362
359
|
};
|
|
363
360
|
}
|
|
364
361
|
}
|