From c476058a16e9d2fca2890155ebefbcceaa2c3816 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Tue, 1 Aug 2023 13:55:16 +0200 Subject: [PATCH] chore: removes dependency on Firefox Json endpoint (#10668) --- .../browsers/test/src/firefox/cli.spec.ts | 8 +++++++ .../src/firefox/{launch.ts => launch.spec.ts} | 0 .../browsers/tools/downloadTestBrowsers.mjs | 23 ++++++++++--------- 3 files changed, 20 insertions(+), 11 deletions(-) rename packages/browsers/test/src/firefox/{launch.ts => launch.spec.ts} (100%) diff --git a/packages/browsers/test/src/firefox/cli.spec.ts b/packages/browsers/test/src/firefox/cli.spec.ts index 004f8979c79..ce44810f87a 100644 --- a/packages/browsers/test/src/firefox/cli.spec.ts +++ b/packages/browsers/test/src/firefox/cli.spec.ts @@ -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', diff --git a/packages/browsers/test/src/firefox/launch.ts b/packages/browsers/test/src/firefox/launch.spec.ts similarity index 100% rename from packages/browsers/test/src/firefox/launch.ts rename to packages/browsers/test/src/firefox/launch.spec.ts diff --git a/packages/browsers/tools/downloadTestBrowsers.mjs b/packages/browsers/tools/downloadTestBrowsers.mjs index 40be6eaffb3..a54d23fbe88 100644 --- a/packages/browsers/tools/downloadTestBrowsers.mjs +++ b/packages/browsers/tools/downloadTestBrowsers.mjs @@ -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,