chore: removes dependency on Firefox Json endpoint (#10668)

This commit is contained in:
Nikolay Vitkov 2023-08-01 13:55:16 +02:00 committed by GitHub
parent 6bca1db956
commit c476058a16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 11 deletions

View File

@ -19,7 +19,10 @@ import fs from 'fs';
import os from 'os';
import path from 'path';
import sinon from 'sinon';
import {CLI} from '../../../lib/cjs/CLI.js';
import * as httpUtil from '../../../lib/cjs/httpUtil.js';
import {
createMockedReadlineInterface,
getServerUrl,
@ -46,6 +49,8 @@ describe('Firefox CLI', function () {
`--path=${tmpDir}`,
`--base-url=${getServerUrl()}`,
]);
sinon.restore();
});
it('should download Firefox binaries', async () => {
@ -66,6 +71,9 @@ describe('Firefox CLI', function () {
});
it('should download latest Firefox binaries', async () => {
sinon
.stub(httpUtil, 'getJSON')
.returns(Promise.resolve({FIREFOX_NIGHTLY: testFirefoxBuildId}));
await new CLI(tmpDir).run([
'npx',
'@puppeteer/browsers',

View File

@ -19,12 +19,13 @@
* mirrors the structure of the download server.
*/
import {BrowserPlatform, install} from '@puppeteer/browsers';
import path from 'path';
import fs from 'fs';
import {existsSync, mkdirSync, copyFileSync, rmSync} from 'fs';
import {normalize, join, dirname} from 'path';
import {BrowserPlatform, install} from '@puppeteer/browsers';
import * as versions from '../test/build/versions.js';
import {downloadPaths} from '../lib/esm/browser-data/browser-data.js';
import * as versions from '../test/build/versions.js';
function getBrowser(str) {
const regex = /test(.+)BuildId/;
@ -37,7 +38,7 @@ function getBrowser(str) {
}
}
const cacheDir = path.normalize(path.join('.', 'test', 'cache'));
const cacheDir = normalize(join('.', 'test', 'cache'));
for (const version of Object.keys(versions)) {
const browser = getBrowser(version);
@ -49,13 +50,13 @@ for (const version of Object.keys(versions)) {
const buildId = versions[version];
for (const platform of Object.values(BrowserPlatform)) {
const targetPath = path.join(
const targetPath = join(
cacheDir,
'server',
...downloadPaths[browser](platform, buildId)
);
if (fs.existsSync(targetPath)) {
if (existsSync(targetPath)) {
continue;
}
@ -63,18 +64,18 @@ for (const version of Object.keys(versions)) {
browser,
buildId,
platform,
cacheDir: path.join(cacheDir, 'tmp'),
cacheDir: join(cacheDir, 'tmp'),
unpack: false,
});
fs.mkdirSync(path.dirname(targetPath), {
mkdirSync(dirname(targetPath), {
recursive: true,
});
fs.copyFileSync(archivePath, targetPath);
copyFileSync(archivePath, targetPath);
}
}
fs.rmSync(path.join(cacheDir, 'tmp'), {
rmSync(join(cacheDir, 'tmp'), {
recursive: true,
force: true,
maxRetries: 10,