Skip to content

Commit

Permalink
ref(fetch) replace request in chromedriver/releases.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Neeraj652 authored and coolaj86 committed Oct 14, 2024
1 parent ea0762c commit 93e6c64
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions chromedriver/releases.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

// See <https://googlechromelabs.github.io/chrome-for-testing/>
var releaseApiUrl =
const releaseApiUrl =
'https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json';

// {
Expand Down Expand Up @@ -40,14 +40,19 @@ var releaseApiUrl =
// ]
// }

module.exports = async function (request) {
let resp = await request({
url: releaseApiUrl,
json: true,
});
module.exports = async function () {
let resp = await fetch(releaseApiUrl);

if (!resp.ok) {
let text = await resp.text();
let msg = `failed to fetch releases from '${releaseApiUrl}': ${resp.status} ${text}`;
throw new Error(msg);
}

let body = await resp.json();

let builds = [];
for (let release of resp.body.versions) {
for (let release of body.versions) {
if (!release.downloads.chromedriver) {
continue;
}
Expand All @@ -58,7 +63,7 @@ module.exports = async function (request) {
version: version,
download: asset.url,
// I' not sure that this is actually statically built but it
// seems to be and at worst we'll just get bug reports for Apline
// seems to be and at worst we'll just get bug reports for Alpine
libc: 'none',
};

Expand All @@ -75,10 +80,15 @@ module.exports = async function (request) {
};

if (module === require.main) {
module.exports(require('@root/request')).then(function (all) {
all = require('../_webi/normalize.js')(all);
// just select the latest 5 for demonstration
all.releases = all.releases.slice(-20);
console.info(JSON.stringify(all, null, 2));
});
module
.exports()
.then(function (all) {
all = require('../_webi/normalize.js')(all);
// just select the latest 20 for demonstration
all.releases = all.releases.slice(-20);
console.info(JSON.stringify(all, null, 2));
})
.catch(function (err) {
console.error('Error:', err);
});
}

0 comments on commit 93e6c64

Please sign in to comment.