Merge pull request #14654 from Snuffleupagus/TestReporter-send-fetch
Replace XMLHttpRequest usage with the Fetch API in `send` (in `test/unit/testreporter.js`)
This commit is contained in:
commit
0d265a30ed
@ -1,23 +1,29 @@
|
|||||||
const TestReporter = function (browser) {
|
const TestReporter = function (browser) {
|
||||||
function send(action, json, cb) {
|
function send(action, json) {
|
||||||
const r = new XMLHttpRequest();
|
return new Promise(resolve => {
|
||||||
// (The POST URI is ignored atm.)
|
json.browser = browser;
|
||||||
r.open("POST", action, true);
|
|
||||||
r.setRequestHeader("Content-Type", "application/json");
|
fetch(action, {
|
||||||
r.onreadystatechange = function sendTaskResultOnreadystatechange(e) {
|
method: "POST",
|
||||||
if (r.readyState === 4) {
|
headers: {
|
||||||
// Retry until successful
|
"Content-Type": "application/json",
|
||||||
if (r.status !== 200) {
|
},
|
||||||
send(action, json, cb);
|
body: JSON.stringify(json),
|
||||||
} else {
|
})
|
||||||
if (cb) {
|
.then(response => {
|
||||||
cb();
|
// Retry until successful.
|
||||||
|
if (!response.ok || response.status !== 200) {
|
||||||
|
throw new Error(response.statusText);
|
||||||
}
|
}
|
||||||
}
|
resolve();
|
||||||
}
|
})
|
||||||
};
|
.catch(reason => {
|
||||||
json.browser = browser;
|
console.warn(`TestReporter - send failed (${action}): ${reason}`);
|
||||||
r.send(JSON.stringify(json));
|
resolve();
|
||||||
|
|
||||||
|
send(action, json);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendInfo(message) {
|
function sendInfo(message) {
|
||||||
|
Loading…
Reference in New Issue
Block a user