Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace XMLHttpRequest usage with the Fetch API in send (in test/unit/testreporter.js) #14654

Merged
merged 1 commit into from
Mar 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions test/unit/testreporter.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
const TestReporter = function (browser) {
function send(action, json, cb) {
const r = new XMLHttpRequest();
// (The POST URI is ignored atm.)
r.open("POST", action, true);
r.setRequestHeader("Content-Type", "application/json");
r.onreadystatechange = function sendTaskResultOnreadystatechange(e) {
if (r.readyState === 4) {
// Retry until successful
if (r.status !== 200) {
send(action, json, cb);
} else {
if (cb) {
cb();
function send(action, json) {
return new Promise(resolve => {
json.browser = browser;

fetch(action, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})
.then(response => {
// Retry until successful.
if (!response.ok || response.status !== 200) {
throw new Error(response.statusText);
}
}
}
};
json.browser = browser;
r.send(JSON.stringify(json));
resolve();
})
.catch(reason => {
console.warn(`TestReporter - send failed (${action}): ${reason}`);
resolve();

send(action, json);
});
});
}

function sendInfo(message) {
Expand Down