@ama-sdk/client-fetch 12.3.0-prerelease.8 → 12.3.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/api-fetch-client.js +18 -22
- package/cjs/plugins/abort/abort.spec.js +83 -81
- package/cjs/plugins/concurrent/concurrent.fetch.js +12 -20
- package/cjs/plugins/concurrent/concurrent.spec.js +99 -99
- package/cjs/plugins/keepalive/keepalive.request.js +7 -12
- package/cjs/plugins/keepalive/keepalive.spec.js +32 -34
- package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
- package/cjs/plugins/mock-intercept/mock-intercept.spec.js +247 -239
- package/cjs/plugins/perf-metric/perf-metric.fetch.js +11 -18
- package/cjs/plugins/retry/retry.fetch.js +18 -27
- package/cjs/plugins/retry/retry.spec.js +233 -225
- package/cjs/plugins/timeout/timeout.fetch.js +13 -19
- package/cjs/plugins/timeout/timeout.spec.js +211 -205
- package/cjs/plugins/wait-for/wait-for.fetch.js +19 -29
- package/cjs/plugins/wait-for/wait-for.spec.js +211 -203
- package/esm2015/api-fetch-client.js +18 -22
- package/esm2015/plugins/abort/abort.spec.js +83 -81
- package/esm2015/plugins/concurrent/concurrent.fetch.js +12 -20
- package/esm2015/plugins/concurrent/concurrent.spec.js +99 -99
- package/esm2015/plugins/keepalive/keepalive.request.js +7 -12
- package/esm2015/plugins/keepalive/keepalive.spec.js +32 -34
- package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
- package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +247 -239
- package/esm2015/plugins/perf-metric/perf-metric.fetch.js +11 -18
- package/esm2015/plugins/retry/retry.fetch.js +18 -27
- package/esm2015/plugins/retry/retry.spec.js +233 -225
- package/esm2015/plugins/timeout/timeout.fetch.js +13 -19
- package/esm2015/plugins/timeout/timeout.spec.js +211 -205
- package/esm2015/plugins/wait-for/wait-for.fetch.js +19 -29
- package/esm2015/plugins/wait-for/wait-for.spec.js +211 -203
- package/package.json +15 -15
- package/schematics/ng-add/index.d.ts.map +1 -1
- package/schematics/ng-add/index.js +11 -21
- package/schematics/ng-add/index.js.map +1 -0
- package/schematics/ng-add/migration/import-map.js.map +1 -0
- package/schematics/ng-add/schema.js.map +1 -0
- package/src/api-fetch-client.d.ts +1 -1
- package/src/api-fetch-client.d.ts.map +1 -1
- package/src/api-fetch-client.js +2 -1
- package/src/api-fetch-client.js.map +1 -1
|
@@ -67,7 +67,7 @@ function _instanceof(left, right) {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
function _ts_generator(thisArg, body) {
|
|
70
|
-
var f, y, t,
|
|
70
|
+
var f, y, t, _ = {
|
|
71
71
|
label: 0,
|
|
72
72
|
sent: function() {
|
|
73
73
|
if (t[0] & 1) throw t[1];
|
|
@@ -75,12 +75,8 @@ function _ts_generator(thisArg, body) {
|
|
|
75
75
|
},
|
|
76
76
|
trys: [],
|
|
77
77
|
ops: []
|
|
78
|
-
};
|
|
79
|
-
return g = {
|
|
80
|
-
next: verb(0),
|
|
81
|
-
"throw": verb(1),
|
|
82
|
-
"return": verb(2)
|
|
83
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
78
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
79
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
84
80
|
return this;
|
|
85
81
|
}), g;
|
|
86
82
|
function verb(n) {
|
|
@@ -93,7 +89,7 @@ function _ts_generator(thisArg, body) {
|
|
|
93
89
|
}
|
|
94
90
|
function step(op) {
|
|
95
91
|
if (f) throw new TypeError("Generator is already executing.");
|
|
96
|
-
while(_)try {
|
|
92
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
97
93
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
98
94
|
if (y = 0, t) op = [
|
|
99
95
|
op[0] & 2,
|
|
@@ -214,7 +210,6 @@ import { CanceledCallError } from '@ama-sdk/core';
|
|
|
214
210
|
{
|
|
215
211
|
key: "delay",
|
|
216
212
|
value: function delay(countDown) {
|
|
217
|
-
var _this = this;
|
|
218
213
|
return _async_to_generator(function() {
|
|
219
214
|
var time;
|
|
220
215
|
return _ts_generator(this, function(_state) {
|
|
@@ -222,7 +217,7 @@ import { CanceledCallError } from '@ama-sdk/core';
|
|
|
222
217
|
case 0:
|
|
223
218
|
return [
|
|
224
219
|
4,
|
|
225
|
-
|
|
220
|
+
this.sleepBetweenRetry(countDown)
|
|
226
221
|
];
|
|
227
222
|
case 1:
|
|
228
223
|
time = _state.sent();
|
|
@@ -234,40 +229,39 @@ import { CanceledCallError } from '@ama-sdk/core';
|
|
|
234
229
|
];
|
|
235
230
|
}
|
|
236
231
|
});
|
|
237
|
-
})();
|
|
232
|
+
}).call(this);
|
|
238
233
|
}
|
|
239
234
|
},
|
|
240
235
|
{
|
|
241
236
|
key: "waitAndRetry",
|
|
242
237
|
value: function waitAndRetry(context, countDown) {
|
|
243
|
-
var _this = this;
|
|
244
238
|
return _async_to_generator(function() {
|
|
245
239
|
return _ts_generator(this, function(_state) {
|
|
246
240
|
switch(_state.label){
|
|
247
241
|
case 0:
|
|
248
242
|
return [
|
|
249
243
|
4,
|
|
250
|
-
|
|
244
|
+
this.delay(countDown)
|
|
251
245
|
];
|
|
252
246
|
case 1:
|
|
253
247
|
_state.sent();
|
|
254
248
|
return [
|
|
255
249
|
2,
|
|
256
|
-
|
|
250
|
+
this.retry(context)
|
|
257
251
|
];
|
|
258
252
|
}
|
|
259
253
|
});
|
|
260
|
-
})();
|
|
254
|
+
}).call(this);
|
|
261
255
|
}
|
|
262
256
|
},
|
|
263
257
|
{
|
|
264
258
|
key: "load",
|
|
265
259
|
value: /** @inheritDoc */ function load(context) {
|
|
266
|
-
var countDown = this.numberOfRetry;
|
|
267
260
|
var _this = this;
|
|
261
|
+
var countDown = this.numberOfRetry;
|
|
268
262
|
return {
|
|
269
|
-
transform:
|
|
270
|
-
|
|
263
|
+
transform: function(fetchCall) {
|
|
264
|
+
return _async_to_generator(function() {
|
|
271
265
|
var result, conditionResult, e, conditionResult1;
|
|
272
266
|
return _ts_generator(this, function(_state) {
|
|
273
267
|
switch(_state.label){
|
|
@@ -290,7 +284,7 @@ import { CanceledCallError } from '@ama-sdk/core';
|
|
|
290
284
|
];
|
|
291
285
|
return [
|
|
292
286
|
4,
|
|
293
|
-
|
|
287
|
+
this.condition(context, result.clone())
|
|
294
288
|
];
|
|
295
289
|
case 2:
|
|
296
290
|
conditionResult = _state.sent();
|
|
@@ -298,7 +292,7 @@ import { CanceledCallError } from '@ama-sdk/core';
|
|
|
298
292
|
countDown--;
|
|
299
293
|
return [
|
|
300
294
|
2,
|
|
301
|
-
|
|
295
|
+
this.waitAndRetry(context, countDown)
|
|
302
296
|
];
|
|
303
297
|
}
|
|
304
298
|
_state.label = 3;
|
|
@@ -315,7 +309,7 @@ import { CanceledCallError } from '@ama-sdk/core';
|
|
|
315
309
|
];
|
|
316
310
|
return [
|
|
317
311
|
4,
|
|
318
|
-
|
|
312
|
+
this.condition(context, undefined, e)
|
|
319
313
|
];
|
|
320
314
|
case 5:
|
|
321
315
|
conditionResult1 = _state.sent();
|
|
@@ -323,7 +317,7 @@ import { CanceledCallError } from '@ama-sdk/core';
|
|
|
323
317
|
countDown--;
|
|
324
318
|
return [
|
|
325
319
|
2,
|
|
326
|
-
|
|
320
|
+
this.waitAndRetry(context, countDown)
|
|
327
321
|
];
|
|
328
322
|
}
|
|
329
323
|
_state.label = 6;
|
|
@@ -335,11 +329,8 @@ import { CanceledCallError } from '@ama-sdk/core';
|
|
|
335
329
|
];
|
|
336
330
|
}
|
|
337
331
|
});
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
return _ref.apply(this, arguments);
|
|
341
|
-
};
|
|
342
|
-
}()
|
|
332
|
+
}).call(_this);
|
|
333
|
+
}
|
|
343
334
|
};
|
|
344
335
|
}
|
|
345
336
|
}
|
|
@@ -28,7 +28,7 @@ function _async_to_generator(fn) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
function _ts_generator(thisArg, body) {
|
|
31
|
-
var f, y, t,
|
|
31
|
+
var f, y, t, _ = {
|
|
32
32
|
label: 0,
|
|
33
33
|
sent: function() {
|
|
34
34
|
if (t[0] & 1) throw t[1];
|
|
@@ -36,12 +36,8 @@ function _ts_generator(thisArg, body) {
|
|
|
36
36
|
},
|
|
37
37
|
trys: [],
|
|
38
38
|
ops: []
|
|
39
|
-
};
|
|
40
|
-
return g = {
|
|
41
|
-
next: verb(0),
|
|
42
|
-
"throw": verb(1),
|
|
43
|
-
"return": verb(2)
|
|
44
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
39
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
40
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
45
41
|
return this;
|
|
46
42
|
}), g;
|
|
47
43
|
function verb(n) {
|
|
@@ -54,7 +50,7 @@ function _ts_generator(thisArg, body) {
|
|
|
54
50
|
}
|
|
55
51
|
function step(op) {
|
|
56
52
|
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
-
while(_)try {
|
|
53
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
58
54
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
59
55
|
if (y = 0, t) op = [
|
|
60
56
|
op[0] & 2,
|
|
@@ -124,221 +120,233 @@ function _ts_generator(thisArg, body) {
|
|
|
124
120
|
}
|
|
125
121
|
import { RetryFetch } from './retry.fetch';
|
|
126
122
|
describe('Retry Fetch Plugin', function() {
|
|
127
|
-
it('should not retry on success',
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
res
|
|
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
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
jest.
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
123
|
+
it('should not retry on success', function() {
|
|
124
|
+
return _async_to_generator(function() {
|
|
125
|
+
var condition, plugin, runner, call, res, ret;
|
|
126
|
+
return _ts_generator(this, function(_state) {
|
|
127
|
+
switch(_state.label){
|
|
128
|
+
case 0:
|
|
129
|
+
condition = jest.fn().mockReturnValue(true);
|
|
130
|
+
plugin = new RetryFetch(1, condition);
|
|
131
|
+
runner = plugin.load({
|
|
132
|
+
url: 'http://www.test.com',
|
|
133
|
+
fetchPlugins: []
|
|
134
|
+
});
|
|
135
|
+
call = Promise.resolve({
|
|
136
|
+
text: 'test',
|
|
137
|
+
ok: true
|
|
138
|
+
});
|
|
139
|
+
res = runner.transform(call);
|
|
140
|
+
expect(condition).not.toHaveBeenCalled();
|
|
141
|
+
return [
|
|
142
|
+
4,
|
|
143
|
+
res
|
|
144
|
+
];
|
|
145
|
+
case 1:
|
|
146
|
+
ret = _state.sent();
|
|
147
|
+
expect(ret).toEqual({
|
|
148
|
+
text: 'test',
|
|
149
|
+
ok: true
|
|
150
|
+
});
|
|
151
|
+
return [
|
|
152
|
+
2
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
})();
|
|
157
|
+
});
|
|
158
|
+
it('should not retry if refused by the condition', function() {
|
|
159
|
+
return _async_to_generator(function() {
|
|
160
|
+
var conditionFalsy, plugin, runner, call, res;
|
|
161
|
+
return _ts_generator(this, function(_state) {
|
|
162
|
+
switch(_state.label){
|
|
163
|
+
case 0:
|
|
164
|
+
conditionFalsy = jest.fn().mockReturnValue(false);
|
|
165
|
+
plugin = new RetryFetch(3, conditionFalsy);
|
|
166
|
+
runner = plugin.load({
|
|
167
|
+
url: 'http://www.test.com',
|
|
168
|
+
fetchPlugins: []
|
|
169
|
+
});
|
|
170
|
+
call = Promise.resolve({
|
|
171
|
+
text: 'test',
|
|
172
|
+
ok: false,
|
|
173
|
+
clone: function() {
|
|
174
|
+
return {};
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
res = runner.transform(call);
|
|
178
|
+
return [
|
|
179
|
+
4,
|
|
180
|
+
res
|
|
181
|
+
];
|
|
182
|
+
case 1:
|
|
183
|
+
_state.sent();
|
|
184
|
+
expect(conditionFalsy).toHaveBeenCalledTimes(1);
|
|
185
|
+
return [
|
|
186
|
+
2
|
|
187
|
+
];
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
})();
|
|
191
|
+
});
|
|
192
|
+
it('should retry on fetch rejection', function() {
|
|
193
|
+
return _async_to_generator(function() {
|
|
194
|
+
var condition, plugin, runners, runner, call, callback;
|
|
195
|
+
return _ts_generator(this, function(_state) {
|
|
196
|
+
switch(_state.label){
|
|
197
|
+
case 0:
|
|
198
|
+
condition = jest.fn().mockReturnValue(true);
|
|
199
|
+
plugin = new RetryFetch(2, condition);
|
|
200
|
+
runners = [];
|
|
201
|
+
runner = plugin.load({
|
|
202
|
+
url: 'not an url',
|
|
203
|
+
fetchPlugins: runners
|
|
204
|
+
});
|
|
205
|
+
runners.push(runner);
|
|
206
|
+
call = Promise.reject(new Error(JSON.stringify({
|
|
207
|
+
text: 'test',
|
|
208
|
+
ok: true
|
|
209
|
+
})));
|
|
210
|
+
callback = jest.fn();
|
|
211
|
+
runner.transform(call).catch(callback);
|
|
212
|
+
return [
|
|
213
|
+
4,
|
|
214
|
+
jest.runAllTimersAsync()
|
|
215
|
+
];
|
|
216
|
+
case 1:
|
|
217
|
+
_state.sent();
|
|
218
|
+
expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
|
|
219
|
+
expect(condition).toHaveBeenCalledTimes(2);
|
|
220
|
+
return [
|
|
221
|
+
2
|
|
222
|
+
];
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
})();
|
|
226
|
+
});
|
|
227
|
+
it('should retry on fetch rejection with wait', function() {
|
|
228
|
+
return _async_to_generator(function() {
|
|
229
|
+
var condition, delay, plugin, runners, runner, call, callback;
|
|
230
|
+
return _ts_generator(this, function(_state) {
|
|
231
|
+
switch(_state.label){
|
|
232
|
+
case 0:
|
|
233
|
+
condition = jest.fn().mockReturnValue(true);
|
|
234
|
+
delay = 500;
|
|
235
|
+
plugin = new RetryFetch(2, condition, function() {
|
|
236
|
+
return delay;
|
|
237
|
+
});
|
|
238
|
+
runners = [];
|
|
239
|
+
runner = plugin.load({
|
|
240
|
+
url: 'not an url',
|
|
241
|
+
fetchPlugins: runners
|
|
242
|
+
});
|
|
243
|
+
runners.push(runner);
|
|
244
|
+
call = Promise.reject(new Error(JSON.stringify({
|
|
245
|
+
text: 'test',
|
|
246
|
+
ok: true
|
|
247
|
+
})));
|
|
248
|
+
callback = jest.fn();
|
|
249
|
+
runner.transform(call).catch(callback);
|
|
250
|
+
return [
|
|
251
|
+
4,
|
|
252
|
+
jest.advanceTimersByTimeAsync(delay)
|
|
253
|
+
];
|
|
254
|
+
case 1:
|
|
255
|
+
_state.sent();
|
|
256
|
+
expect(callback).not.toHaveBeenCalled();
|
|
257
|
+
return [
|
|
258
|
+
4,
|
|
259
|
+
jest.advanceTimersByTimeAsync(delay)
|
|
260
|
+
];
|
|
261
|
+
case 2:
|
|
262
|
+
_state.sent();
|
|
263
|
+
expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
|
|
264
|
+
expect(condition).toHaveBeenCalledTimes(2);
|
|
265
|
+
return [
|
|
266
|
+
2
|
|
267
|
+
];
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
})();
|
|
271
|
+
});
|
|
272
|
+
it('should retry on not ok call', function() {
|
|
273
|
+
return _async_to_generator(function() {
|
|
274
|
+
var condition, plugin, runners, runner, call, callback;
|
|
275
|
+
return _ts_generator(this, function(_state) {
|
|
276
|
+
switch(_state.label){
|
|
277
|
+
case 0:
|
|
278
|
+
condition = jest.fn().mockReturnValue(true);
|
|
279
|
+
plugin = new RetryFetch(3, condition);
|
|
280
|
+
runners = [];
|
|
281
|
+
runner = plugin.load({
|
|
282
|
+
url: 'not an url',
|
|
283
|
+
fetchPlugins: runners
|
|
284
|
+
});
|
|
285
|
+
runners.push(runner);
|
|
286
|
+
call = Promise.resolve({
|
|
287
|
+
text: 'test',
|
|
288
|
+
ok: false
|
|
289
|
+
});
|
|
290
|
+
callback = jest.fn();
|
|
291
|
+
runner.transform(call).catch(callback);
|
|
292
|
+
return [
|
|
293
|
+
4,
|
|
294
|
+
jest.runAllTimersAsync()
|
|
295
|
+
];
|
|
296
|
+
case 1:
|
|
297
|
+
_state.sent();
|
|
298
|
+
expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
|
|
299
|
+
expect(condition).toHaveBeenCalledTimes(3);
|
|
300
|
+
return [
|
|
301
|
+
2
|
|
302
|
+
];
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
})();
|
|
306
|
+
});
|
|
307
|
+
it('should retry on not ok call with wait', function() {
|
|
308
|
+
return _async_to_generator(function() {
|
|
309
|
+
var condition, delay, plugin, runners, runner, call, callback;
|
|
310
|
+
return _ts_generator(this, function(_state) {
|
|
311
|
+
switch(_state.label){
|
|
312
|
+
case 0:
|
|
313
|
+
condition = jest.fn().mockReturnValue(true);
|
|
314
|
+
delay = 500;
|
|
315
|
+
plugin = new RetryFetch(3, condition, function() {
|
|
316
|
+
return delay;
|
|
317
|
+
});
|
|
318
|
+
runners = [];
|
|
319
|
+
runner = plugin.load({
|
|
320
|
+
url: 'not an url',
|
|
321
|
+
fetchPlugins: runners
|
|
322
|
+
});
|
|
323
|
+
runners.push(runner);
|
|
324
|
+
call = Promise.resolve({
|
|
325
|
+
text: 'test',
|
|
326
|
+
ok: false
|
|
327
|
+
});
|
|
328
|
+
callback = jest.fn();
|
|
329
|
+
runner.transform(call).catch(callback);
|
|
330
|
+
return [
|
|
331
|
+
4,
|
|
332
|
+
jest.advanceTimersByTimeAsync(2 * delay)
|
|
333
|
+
];
|
|
334
|
+
case 1:
|
|
335
|
+
_state.sent();
|
|
336
|
+
expect(callback).not.toHaveBeenCalled();
|
|
337
|
+
return [
|
|
338
|
+
4,
|
|
339
|
+
jest.advanceTimersByTimeAsync(delay)
|
|
340
|
+
];
|
|
341
|
+
case 2:
|
|
342
|
+
_state.sent();
|
|
343
|
+
expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
|
|
344
|
+
expect(condition).toHaveBeenCalledTimes(3);
|
|
345
|
+
return [
|
|
346
|
+
2
|
|
347
|
+
];
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
})();
|
|
351
|
+
});
|
|
344
352
|
});
|