|
1 | 1 | const TestReporter = function (browser) {
|
2 |
| - function send(action, json, cb) { |
3 |
| - const r = new XMLHttpRequest(); |
4 |
| - // (The POST URI is ignored atm.) |
5 |
| - r.open("POST", action, true); |
6 |
| - r.setRequestHeader("Content-Type", "application/json"); |
7 |
| - r.onreadystatechange = function sendTaskResultOnreadystatechange(e) { |
8 |
| - if (r.readyState === 4) { |
9 |
| - // Retry until successful |
10 |
| - if (r.status !== 200) { |
11 |
| - send(action, json, cb); |
12 |
| - } else { |
13 |
| - if (cb) { |
14 |
| - cb(); |
| 2 | + function send(action, json) { |
| 3 | + return new Promise(resolve => { |
| 4 | + json.browser = browser; |
| 5 | + |
| 6 | + fetch(action, { |
| 7 | + method: "POST", |
| 8 | + headers: { |
| 9 | + "Content-Type": "application/json", |
| 10 | + }, |
| 11 | + body: JSON.stringify(json), |
| 12 | + }) |
| 13 | + .then(response => { |
| 14 | + // Retry until successful. |
| 15 | + if (!response.ok || response.status !== 200) { |
| 16 | + throw new Error(response.statusText); |
15 | 17 | }
|
16 |
| - } |
17 |
| - } |
18 |
| - }; |
19 |
| - json.browser = browser; |
20 |
| - r.send(JSON.stringify(json)); |
| 18 | + resolve(); |
| 19 | + }) |
| 20 | + .catch(reason => { |
| 21 | + console.warn(`TestReporter - send failed (${action}): ${reason}`); |
| 22 | + resolve(); |
| 23 | + |
| 24 | + send(action, json); |
| 25 | + }); |
| 26 | + }); |
21 | 27 | }
|
22 | 28 |
|
23 | 29 | function sendInfo(message) {
|
|
0 commit comments