refactor: implement ajax() in tests using native fetch instead of jQuery (#32579)

This commit is contained in:
Milan Burda 2022-01-24 10:34:23 +01:00 committed by GitHub
parent 7032be660d
commit 9d054755d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 116 additions and 160 deletions

View file

@ -1,22 +1,21 @@
<html>
<body>
<script src="../../static/jquery-2.0.3.min.js"></script>
<script type="text/javascript" charset="utf-8">
var ipcRenderer = require('electron').ipcRenderer;
var port = location.search.substr("?port=".length);
$.ajax({
type: "GET",
url: "http://127.0.0.1:" + port,
headers: {
"Authorization": "Basic " + btoa("test:test")
},
success: function(result) {
ipcRenderer.sendToHost(result);
},
error: function(xhr, status, error) {
const { ipcRenderer } = require('electron');
const url = new URL(location.href);
const port = url.searchParams.get('port');
(async () => {
try {
const response = await fetch(`http://127.0.0.1:${port}`, {
headers: {
'Authorization': `Basic ${btoa('test:test')}`
}
});
ipcRenderer.sendToHost(await response.text());
} catch (error) {
ipcRenderer.sendToHost(error);
},
});
}
})();
</script>
</body>
</html>