refactor: use helpers for JSON/text (#10154)
This commit is contained in:
parent
317fa732f9
commit
c815ba45a3
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {httpRequest} from '../httpUtil.js';
|
import {getText} from '../httpUtil.js';
|
||||||
|
|
||||||
import {BrowserPlatform} from './types.js';
|
import {BrowserPlatform} from './types.js';
|
||||||
|
|
||||||
@ -64,30 +64,7 @@ export function relativeExecutablePath(
|
|||||||
export async function resolveBuildId(
|
export async function resolveBuildId(
|
||||||
_channel: 'latest' = 'latest'
|
_channel: 'latest' = 'latest'
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return await getText(
|
||||||
const request = httpRequest(
|
new URL(`https://chromedriver.storage.googleapis.com/LATEST_RELEASE`)
|
||||||
new URL(`https://chromedriver.storage.googleapis.com/LATEST_RELEASE`),
|
|
||||||
'GET',
|
|
||||||
response => {
|
|
||||||
let data = '';
|
|
||||||
if (response.statusCode && response.statusCode >= 400) {
|
|
||||||
return reject(new Error(`Got status code ${response.statusCode}`));
|
|
||||||
}
|
|
||||||
response.on('data', chunk => {
|
|
||||||
data += chunk;
|
|
||||||
});
|
|
||||||
response.on('end', () => {
|
|
||||||
try {
|
|
||||||
return resolve(String(data));
|
|
||||||
} catch {
|
|
||||||
return reject(new Error('Chrome version not found'));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
);
|
||||||
request.on('error', err => {
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import {httpRequest} from '../httpUtil.js';
|
import {getJSON} from '../httpUtil.js';
|
||||||
|
|
||||||
import {BrowserPlatform, ProfileOptions} from './types.js';
|
import {BrowserPlatform, ProfileOptions} from './types.js';
|
||||||
|
|
||||||
@ -68,33 +68,16 @@ export function relativeExecutablePath(
|
|||||||
export async function resolveBuildId(
|
export async function resolveBuildId(
|
||||||
channel: 'FIREFOX_NIGHTLY' = 'FIREFOX_NIGHTLY'
|
channel: 'FIREFOX_NIGHTLY' = 'FIREFOX_NIGHTLY'
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
const versions = (await getJSON(
|
||||||
const request = httpRequest(
|
new URL('https://product-details.mozilla.org/1.0/firefox_versions.json')
|
||||||
new URL('https://product-details.mozilla.org/1.0/firefox_versions.json'),
|
)) as {
|
||||||
'GET',
|
[channel: string]: string;
|
||||||
response => {
|
};
|
||||||
let data = '';
|
const version = versions[channel];
|
||||||
if (response.statusCode && response.statusCode >= 400) {
|
if (!version) {
|
||||||
return reject(new Error(`Got status code ${response.statusCode}`));
|
throw new Error(`Channel ${channel} is not found.`);
|
||||||
}
|
}
|
||||||
response.on('data', chunk => {
|
return version;
|
||||||
data += chunk;
|
|
||||||
});
|
|
||||||
response.on('end', () => {
|
|
||||||
try {
|
|
||||||
const versions = JSON.parse(data);
|
|
||||||
return resolve(versions[channel]);
|
|
||||||
} catch {
|
|
||||||
return reject(new Error('Firefox version not found'));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
request.on('error', err => {
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createProfile(options: ProfileOptions): Promise<void> {
|
export async function createProfile(options: ProfileOptions): Promise<void> {
|
||||||
|
@ -18,5 +18,5 @@ export const testChromeBuildId = '113.0.5672.0';
|
|||||||
export const testChromiumBuildId = '1083080';
|
export const testChromiumBuildId = '1083080';
|
||||||
// TODO: We can add a Cron job to auto-update on change.
|
// TODO: We can add a Cron job to auto-update on change.
|
||||||
// Firefox keeps only `latest` version of Nightly builds.
|
// Firefox keeps only `latest` version of Nightly builds.
|
||||||
export const testFirefoxBuildId = '114.0a1';
|
export const testFirefoxBuildId = '115.0a1';
|
||||||
export const testChromeDriverBuildId = '112.0.5615.49';
|
export const testChromeDriverBuildId = '112.0.5615.49';
|
||||||
|
Loading…
Reference in New Issue
Block a user