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