@ama-sdk/client-fetch 12.3.0-prerelease.9 → 12.4.0-prerelease.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/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
|
@@ -78,7 +78,7 @@ function _instanceof(left, right) {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
function _ts_generator(thisArg, body) {
|
|
81
|
-
var f, y, t,
|
|
81
|
+
var f, y, t, _ = {
|
|
82
82
|
label: 0,
|
|
83
83
|
sent: function() {
|
|
84
84
|
if (t[0] & 1) throw t[1];
|
|
@@ -86,12 +86,8 @@ function _ts_generator(thisArg, body) {
|
|
|
86
86
|
},
|
|
87
87
|
trys: [],
|
|
88
88
|
ops: []
|
|
89
|
-
};
|
|
90
|
-
return g = {
|
|
91
|
-
next: verb(0),
|
|
92
|
-
"throw": verb(1),
|
|
93
|
-
"return": verb(2)
|
|
94
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
89
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
90
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
95
91
|
return this;
|
|
96
92
|
}), g;
|
|
97
93
|
function verb(n) {
|
|
@@ -104,7 +100,7 @@ function _ts_generator(thisArg, body) {
|
|
|
104
100
|
}
|
|
105
101
|
function step(op) {
|
|
106
102
|
if (f) throw new TypeError("Generator is already executing.");
|
|
107
|
-
while(_)try {
|
|
103
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
108
104
|
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;
|
|
109
105
|
if (y = 0, t) op = [
|
|
110
106
|
op[0] & 2,
|
|
@@ -222,7 +218,6 @@ var RetryFetch = /*#__PURE__*/ function() {
|
|
|
222
218
|
{
|
|
223
219
|
key: "delay",
|
|
224
220
|
value: function delay(countDown) {
|
|
225
|
-
var _this = this;
|
|
226
221
|
return _async_to_generator(function() {
|
|
227
222
|
var time;
|
|
228
223
|
return _ts_generator(this, function(_state) {
|
|
@@ -230,7 +225,7 @@ var RetryFetch = /*#__PURE__*/ function() {
|
|
|
230
225
|
case 0:
|
|
231
226
|
return [
|
|
232
227
|
4,
|
|
233
|
-
|
|
228
|
+
this.sleepBetweenRetry(countDown)
|
|
234
229
|
];
|
|
235
230
|
case 1:
|
|
236
231
|
time = _state.sent();
|
|
@@ -242,40 +237,39 @@ var RetryFetch = /*#__PURE__*/ function() {
|
|
|
242
237
|
];
|
|
243
238
|
}
|
|
244
239
|
});
|
|
245
|
-
})();
|
|
240
|
+
}).call(this);
|
|
246
241
|
}
|
|
247
242
|
},
|
|
248
243
|
{
|
|
249
244
|
key: "waitAndRetry",
|
|
250
245
|
value: function waitAndRetry(context, countDown) {
|
|
251
|
-
var _this = this;
|
|
252
246
|
return _async_to_generator(function() {
|
|
253
247
|
return _ts_generator(this, function(_state) {
|
|
254
248
|
switch(_state.label){
|
|
255
249
|
case 0:
|
|
256
250
|
return [
|
|
257
251
|
4,
|
|
258
|
-
|
|
252
|
+
this.delay(countDown)
|
|
259
253
|
];
|
|
260
254
|
case 1:
|
|
261
255
|
_state.sent();
|
|
262
256
|
return [
|
|
263
257
|
2,
|
|
264
|
-
|
|
258
|
+
this.retry(context)
|
|
265
259
|
];
|
|
266
260
|
}
|
|
267
261
|
});
|
|
268
|
-
})();
|
|
262
|
+
}).call(this);
|
|
269
263
|
}
|
|
270
264
|
},
|
|
271
265
|
{
|
|
272
266
|
key: "load",
|
|
273
267
|
value: /** @inheritDoc */ function load(context) {
|
|
274
|
-
var countDown = this.numberOfRetry;
|
|
275
268
|
var _this = this;
|
|
269
|
+
var countDown = this.numberOfRetry;
|
|
276
270
|
return {
|
|
277
|
-
transform:
|
|
278
|
-
|
|
271
|
+
transform: function(fetchCall) {
|
|
272
|
+
return _async_to_generator(function() {
|
|
279
273
|
var result, conditionResult, e, conditionResult1;
|
|
280
274
|
return _ts_generator(this, function(_state) {
|
|
281
275
|
switch(_state.label){
|
|
@@ -298,7 +292,7 @@ var RetryFetch = /*#__PURE__*/ function() {
|
|
|
298
292
|
];
|
|
299
293
|
return [
|
|
300
294
|
4,
|
|
301
|
-
|
|
295
|
+
this.condition(context, result.clone())
|
|
302
296
|
];
|
|
303
297
|
case 2:
|
|
304
298
|
conditionResult = _state.sent();
|
|
@@ -306,7 +300,7 @@ var RetryFetch = /*#__PURE__*/ function() {
|
|
|
306
300
|
countDown--;
|
|
307
301
|
return [
|
|
308
302
|
2,
|
|
309
|
-
|
|
303
|
+
this.waitAndRetry(context, countDown)
|
|
310
304
|
];
|
|
311
305
|
}
|
|
312
306
|
_state.label = 3;
|
|
@@ -323,7 +317,7 @@ var RetryFetch = /*#__PURE__*/ function() {
|
|
|
323
317
|
];
|
|
324
318
|
return [
|
|
325
319
|
4,
|
|
326
|
-
|
|
320
|
+
this.condition(context, undefined, e)
|
|
327
321
|
];
|
|
328
322
|
case 5:
|
|
329
323
|
conditionResult1 = _state.sent();
|
|
@@ -331,7 +325,7 @@ var RetryFetch = /*#__PURE__*/ function() {
|
|
|
331
325
|
countDown--;
|
|
332
326
|
return [
|
|
333
327
|
2,
|
|
334
|
-
|
|
328
|
+
this.waitAndRetry(context, countDown)
|
|
335
329
|
];
|
|
336
330
|
}
|
|
337
331
|
_state.label = 6;
|
|
@@ -343,11 +337,8 @@ var RetryFetch = /*#__PURE__*/ function() {
|
|
|
343
337
|
];
|
|
344
338
|
}
|
|
345
339
|
});
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
return _ref.apply(this, arguments);
|
|
349
|
-
};
|
|
350
|
-
}()
|
|
340
|
+
}).call(_this);
|
|
341
|
+
}
|
|
351
342
|
};
|
|
352
343
|
}
|
|
353
344
|
}
|
|
@@ -33,7 +33,7 @@ function _async_to_generator(fn) {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
function _ts_generator(thisArg, body) {
|
|
36
|
-
var f, y, t,
|
|
36
|
+
var f, y, t, _ = {
|
|
37
37
|
label: 0,
|
|
38
38
|
sent: function() {
|
|
39
39
|
if (t[0] & 1) throw t[1];
|
|
@@ -41,12 +41,8 @@ function _ts_generator(thisArg, body) {
|
|
|
41
41
|
},
|
|
42
42
|
trys: [],
|
|
43
43
|
ops: []
|
|
44
|
-
};
|
|
45
|
-
return g = {
|
|
46
|
-
next: verb(0),
|
|
47
|
-
"throw": verb(1),
|
|
48
|
-
"return": verb(2)
|
|
49
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
44
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
45
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
50
46
|
return this;
|
|
51
47
|
}), g;
|
|
52
48
|
function verb(n) {
|
|
@@ -59,7 +55,7 @@ function _ts_generator(thisArg, body) {
|
|
|
59
55
|
}
|
|
60
56
|
function step(op) {
|
|
61
57
|
if (f) throw new TypeError("Generator is already executing.");
|
|
62
|
-
while(_)try {
|
|
58
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
63
59
|
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;
|
|
64
60
|
if (y = 0, t) op = [
|
|
65
61
|
op[0] & 2,
|
|
@@ -128,221 +124,233 @@ function _ts_generator(thisArg, body) {
|
|
|
128
124
|
}
|
|
129
125
|
}
|
|
130
126
|
describe('Retry Fetch Plugin', function() {
|
|
131
|
-
it('should not retry on success',
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
res
|
|
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
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
jest.
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
127
|
+
it('should not retry on success', function() {
|
|
128
|
+
return _async_to_generator(function() {
|
|
129
|
+
var condition, plugin, runner, call, res, ret;
|
|
130
|
+
return _ts_generator(this, function(_state) {
|
|
131
|
+
switch(_state.label){
|
|
132
|
+
case 0:
|
|
133
|
+
condition = jest.fn().mockReturnValue(true);
|
|
134
|
+
plugin = new _retryfetch.RetryFetch(1, condition);
|
|
135
|
+
runner = plugin.load({
|
|
136
|
+
url: 'http://www.test.com',
|
|
137
|
+
fetchPlugins: []
|
|
138
|
+
});
|
|
139
|
+
call = Promise.resolve({
|
|
140
|
+
text: 'test',
|
|
141
|
+
ok: true
|
|
142
|
+
});
|
|
143
|
+
res = runner.transform(call);
|
|
144
|
+
expect(condition).not.toHaveBeenCalled();
|
|
145
|
+
return [
|
|
146
|
+
4,
|
|
147
|
+
res
|
|
148
|
+
];
|
|
149
|
+
case 1:
|
|
150
|
+
ret = _state.sent();
|
|
151
|
+
expect(ret).toEqual({
|
|
152
|
+
text: 'test',
|
|
153
|
+
ok: true
|
|
154
|
+
});
|
|
155
|
+
return [
|
|
156
|
+
2
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
})();
|
|
161
|
+
});
|
|
162
|
+
it('should not retry if refused by the condition', function() {
|
|
163
|
+
return _async_to_generator(function() {
|
|
164
|
+
var conditionFalsy, plugin, runner, call, res;
|
|
165
|
+
return _ts_generator(this, function(_state) {
|
|
166
|
+
switch(_state.label){
|
|
167
|
+
case 0:
|
|
168
|
+
conditionFalsy = jest.fn().mockReturnValue(false);
|
|
169
|
+
plugin = new _retryfetch.RetryFetch(3, conditionFalsy);
|
|
170
|
+
runner = plugin.load({
|
|
171
|
+
url: 'http://www.test.com',
|
|
172
|
+
fetchPlugins: []
|
|
173
|
+
});
|
|
174
|
+
call = Promise.resolve({
|
|
175
|
+
text: 'test',
|
|
176
|
+
ok: false,
|
|
177
|
+
clone: function() {
|
|
178
|
+
return {};
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
res = runner.transform(call);
|
|
182
|
+
return [
|
|
183
|
+
4,
|
|
184
|
+
res
|
|
185
|
+
];
|
|
186
|
+
case 1:
|
|
187
|
+
_state.sent();
|
|
188
|
+
expect(conditionFalsy).toHaveBeenCalledTimes(1);
|
|
189
|
+
return [
|
|
190
|
+
2
|
|
191
|
+
];
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
})();
|
|
195
|
+
});
|
|
196
|
+
it('should retry on fetch rejection', function() {
|
|
197
|
+
return _async_to_generator(function() {
|
|
198
|
+
var condition, plugin, runners, runner, call, callback;
|
|
199
|
+
return _ts_generator(this, function(_state) {
|
|
200
|
+
switch(_state.label){
|
|
201
|
+
case 0:
|
|
202
|
+
condition = jest.fn().mockReturnValue(true);
|
|
203
|
+
plugin = new _retryfetch.RetryFetch(2, condition);
|
|
204
|
+
runners = [];
|
|
205
|
+
runner = plugin.load({
|
|
206
|
+
url: 'not an url',
|
|
207
|
+
fetchPlugins: runners
|
|
208
|
+
});
|
|
209
|
+
runners.push(runner);
|
|
210
|
+
call = Promise.reject(new Error(JSON.stringify({
|
|
211
|
+
text: 'test',
|
|
212
|
+
ok: true
|
|
213
|
+
})));
|
|
214
|
+
callback = jest.fn();
|
|
215
|
+
runner.transform(call).catch(callback);
|
|
216
|
+
return [
|
|
217
|
+
4,
|
|
218
|
+
jest.runAllTimersAsync()
|
|
219
|
+
];
|
|
220
|
+
case 1:
|
|
221
|
+
_state.sent();
|
|
222
|
+
expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
|
|
223
|
+
expect(condition).toHaveBeenCalledTimes(2);
|
|
224
|
+
return [
|
|
225
|
+
2
|
|
226
|
+
];
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
})();
|
|
230
|
+
});
|
|
231
|
+
it('should retry on fetch rejection with wait', function() {
|
|
232
|
+
return _async_to_generator(function() {
|
|
233
|
+
var condition, delay, plugin, runners, runner, call, callback;
|
|
234
|
+
return _ts_generator(this, function(_state) {
|
|
235
|
+
switch(_state.label){
|
|
236
|
+
case 0:
|
|
237
|
+
condition = jest.fn().mockReturnValue(true);
|
|
238
|
+
delay = 500;
|
|
239
|
+
plugin = new _retryfetch.RetryFetch(2, condition, function() {
|
|
240
|
+
return delay;
|
|
241
|
+
});
|
|
242
|
+
runners = [];
|
|
243
|
+
runner = plugin.load({
|
|
244
|
+
url: 'not an url',
|
|
245
|
+
fetchPlugins: runners
|
|
246
|
+
});
|
|
247
|
+
runners.push(runner);
|
|
248
|
+
call = Promise.reject(new Error(JSON.stringify({
|
|
249
|
+
text: 'test',
|
|
250
|
+
ok: true
|
|
251
|
+
})));
|
|
252
|
+
callback = jest.fn();
|
|
253
|
+
runner.transform(call).catch(callback);
|
|
254
|
+
return [
|
|
255
|
+
4,
|
|
256
|
+
jest.advanceTimersByTimeAsync(delay)
|
|
257
|
+
];
|
|
258
|
+
case 1:
|
|
259
|
+
_state.sent();
|
|
260
|
+
expect(callback).not.toHaveBeenCalled();
|
|
261
|
+
return [
|
|
262
|
+
4,
|
|
263
|
+
jest.advanceTimersByTimeAsync(delay)
|
|
264
|
+
];
|
|
265
|
+
case 2:
|
|
266
|
+
_state.sent();
|
|
267
|
+
expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
|
|
268
|
+
expect(condition).toHaveBeenCalledTimes(2);
|
|
269
|
+
return [
|
|
270
|
+
2
|
|
271
|
+
];
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
})();
|
|
275
|
+
});
|
|
276
|
+
it('should retry on not ok call', function() {
|
|
277
|
+
return _async_to_generator(function() {
|
|
278
|
+
var condition, plugin, runners, runner, call, callback;
|
|
279
|
+
return _ts_generator(this, function(_state) {
|
|
280
|
+
switch(_state.label){
|
|
281
|
+
case 0:
|
|
282
|
+
condition = jest.fn().mockReturnValue(true);
|
|
283
|
+
plugin = new _retryfetch.RetryFetch(3, condition);
|
|
284
|
+
runners = [];
|
|
285
|
+
runner = plugin.load({
|
|
286
|
+
url: 'not an url',
|
|
287
|
+
fetchPlugins: runners
|
|
288
|
+
});
|
|
289
|
+
runners.push(runner);
|
|
290
|
+
call = Promise.resolve({
|
|
291
|
+
text: 'test',
|
|
292
|
+
ok: false
|
|
293
|
+
});
|
|
294
|
+
callback = jest.fn();
|
|
295
|
+
runner.transform(call).catch(callback);
|
|
296
|
+
return [
|
|
297
|
+
4,
|
|
298
|
+
jest.runAllTimersAsync()
|
|
299
|
+
];
|
|
300
|
+
case 1:
|
|
301
|
+
_state.sent();
|
|
302
|
+
expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
|
|
303
|
+
expect(condition).toHaveBeenCalledTimes(3);
|
|
304
|
+
return [
|
|
305
|
+
2
|
|
306
|
+
];
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
})();
|
|
310
|
+
});
|
|
311
|
+
it('should retry on not ok call with wait', function() {
|
|
312
|
+
return _async_to_generator(function() {
|
|
313
|
+
var condition, delay, plugin, runners, runner, call, callback;
|
|
314
|
+
return _ts_generator(this, function(_state) {
|
|
315
|
+
switch(_state.label){
|
|
316
|
+
case 0:
|
|
317
|
+
condition = jest.fn().mockReturnValue(true);
|
|
318
|
+
delay = 500;
|
|
319
|
+
plugin = new _retryfetch.RetryFetch(3, condition, function() {
|
|
320
|
+
return delay;
|
|
321
|
+
});
|
|
322
|
+
runners = [];
|
|
323
|
+
runner = plugin.load({
|
|
324
|
+
url: 'not an url',
|
|
325
|
+
fetchPlugins: runners
|
|
326
|
+
});
|
|
327
|
+
runners.push(runner);
|
|
328
|
+
call = Promise.resolve({
|
|
329
|
+
text: 'test',
|
|
330
|
+
ok: false
|
|
331
|
+
});
|
|
332
|
+
callback = jest.fn();
|
|
333
|
+
runner.transform(call).catch(callback);
|
|
334
|
+
return [
|
|
335
|
+
4,
|
|
336
|
+
jest.advanceTimersByTimeAsync(2 * delay)
|
|
337
|
+
];
|
|
338
|
+
case 1:
|
|
339
|
+
_state.sent();
|
|
340
|
+
expect(callback).not.toHaveBeenCalled();
|
|
341
|
+
return [
|
|
342
|
+
4,
|
|
343
|
+
jest.advanceTimersByTimeAsync(delay)
|
|
344
|
+
];
|
|
345
|
+
case 2:
|
|
346
|
+
_state.sent();
|
|
347
|
+
expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
|
|
348
|
+
expect(condition).toHaveBeenCalledTimes(3);
|
|
349
|
+
return [
|
|
350
|
+
2
|
|
351
|
+
];
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
})();
|
|
355
|
+
});
|
|
348
356
|
});
|