-
-
Notifications
You must be signed in to change notification settings - Fork 11k
/
Copy path__helpers.js
41 lines (33 loc) · 1000 Bytes
/
__helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import _axios from '../../index.js';
window.axios = _axios;
// Jasmine config
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
jasmine.getEnv().defaultTimeoutInterval = 60000;
// Get Ajax request using an increasing timeout to retry
window.getAjaxRequest = (function () {
let attempts = 0;
const MAX_ATTEMPTS = 5;
const ATTEMPT_DELAY_FACTOR = 5;
function getAjaxRequest() {
return new Promise(function (resolve, reject) {
attempts = 0;
attemptGettingAjaxRequest(resolve, reject);
});
}
function attemptGettingAjaxRequest(resolve, reject) {
const delay = attempts * attempts * ATTEMPT_DELAY_FACTOR;
if (attempts++ > MAX_ATTEMPTS) {
reject(new Error('No request was found'));
return;
}
setTimeout(function () {
const request = jasmine.Ajax.requests.mostRecent();
if (request) {
resolve(request);
} else {
attemptGettingAjaxRequest(resolve, reject);
}
}, delay);
}
return getAjaxRequest;
})();