From 0a7f786474049a9625b017270e261f2e544ceadb Mon Sep 17 00:00:00 2001 From: Roman Kuznetsov Date: Tue, 24 Dec 2024 18:13:06 +0300 Subject: [PATCH] chore: refactor(move) browser-installer utils --- src/browser-installer/chrome/browser.ts | 14 ++-- src/browser-installer/chrome/driver.ts | 18 +++-- src/browser-installer/chromium/browser.ts | 13 +-- src/browser-installer/chromium/driver.ts | 4 +- src/browser-installer/edge/driver.ts | 8 +- src/browser-installer/firefox/browser.ts | 19 ++--- src/browser-installer/firefox/driver.ts | 12 ++- src/browser-installer/index.ts | 1 - src/browser-installer/install.ts | 14 ++-- src/browser-installer/registry/index.ts | 16 ++-- src/browser-installer/run.ts | 17 ++-- .../browser-versions/index.ts | 9 ++- src/browser-installer/utils.ts | 41 +--------- src/browser-pool/webdriver-pool.ts | 3 +- src/browser/new-browser.ts | 80 ++++++++++--------- src/browser/types.ts | 11 +++ src/constants/config.js | 14 ---- src/constants/config.ts | 10 +++ src/utils/browser.ts | 25 ++++++ test/src/browser-installer/chrome/browser.ts | 22 ++--- test/src/browser-installer/chrome/driver.ts | 22 ++--- .../src/browser-installer/chromium/browser.ts | 22 ++--- test/src/browser-installer/chromium/driver.ts | 4 +- test/src/browser-installer/edge/driver.ts | 14 ++-- test/src/browser-installer/firefox/browser.ts | 16 ++-- test/src/browser-installer/firefox/driver.ts | 14 ++-- test/src/browser-installer/install.ts | 12 +-- test/src/browser-installer/registry.ts | 75 +++++++++++------ test/src/browser-installer/run.ts | 12 +-- .../collect-dependencies/cache.ts | 10 +-- test/src/browser-installer/utils.ts | 28 ------- test/src/utils/browser.ts | 30 ++++++- 32 files changed, 325 insertions(+), 285 deletions(-) delete mode 100644 src/constants/config.js create mode 100644 src/constants/config.ts diff --git a/src/browser-installer/chrome/browser.ts b/src/browser-installer/chrome/browser.ts index bc980839d..2a8d49d66 100644 --- a/src/browser-installer/chrome/browser.ts +++ b/src/browser-installer/chrome/browser.ts @@ -5,13 +5,13 @@ import { getBrowserPlatform, getBrowsersDir, getMilestone, - Browser, type DownloadProgressCallback, } from "../utils"; import registry from "../registry"; import { normalizeChromeVersion } from "../utils"; import { installUbuntuPackageDependencies } from "../ubuntu-packages"; import { installChromeDriver } from "./driver"; +import { BrowserName } from "../../browser/types"; const installChromeBrowser = async (version: string, { force = false } = {}): Promise => { const milestone = getMilestone(version); @@ -25,19 +25,19 @@ const installChromeBrowser = async (version: string, { force = false } = {}): Pr } const platform = getBrowserPlatform(); - const existingLocallyBrowserVersion = registry.getMatchedBrowserVersion(Browser.CHROME, platform, version); + const existingLocallyBrowserVersion = registry.getMatchedBrowserVersion(BrowserName.CHROME, platform, version); if (existingLocallyBrowserVersion && !force) { browserInstallerDebug(`A locally installed chrome@${version} browser was found. Skipping the installation`); - return registry.getBinaryPath(Browser.CHROME, platform, existingLocallyBrowserVersion); + return registry.getBinaryPath(BrowserName.CHROME, platform, existingLocallyBrowserVersion); } const normalizedVersion = normalizeChromeVersion(version); - const buildId = await resolveBuildId(Browser.CHROME, platform, normalizedVersion); + const buildId = await resolveBuildId(BrowserName.CHROME, platform, normalizedVersion); const cacheDir = getBrowsersDir(); - const canBeInstalled = await canDownload({ browser: Browser.CHROME, platform, buildId, cacheDir }); + const canBeInstalled = await canDownload({ browser: BrowserName.CHROME, platform, buildId, cacheDir }); if (!canBeInstalled) { throw new Error( @@ -55,11 +55,11 @@ const installChromeBrowser = async (version: string, { force = false } = {}): Pr buildId, cacheDir, downloadProgressCallback, - browser: Browser.CHROME, + browser: BrowserName.CHROME, unpack: true, }).then(result => result.executablePath); - return registry.installBinary(Browser.CHROME, platform, buildId, installFn); + return registry.installBinary(BrowserName.CHROME, platform, buildId, installFn); }; export const installChrome = async ( diff --git a/src/browser-installer/chrome/driver.ts b/src/browser-installer/chrome/driver.ts index efb1ede45..5512d1625 100644 --- a/src/browser-installer/chrome/driver.ts +++ b/src/browser-installer/chrome/driver.ts @@ -5,21 +5,25 @@ import { getBrowserPlatform, getChromeDriverDir, getMilestone, - Driver, + DriverName, type DownloadProgressCallback, } from "../utils"; import registry from "../registry"; export const installChromeDriver = async (chromeVersion: string, { force = false } = {}): Promise => { const platform = getBrowserPlatform(); - const existingLocallyDriverVersion = registry.getMatchedDriverVersion(Driver.CHROMEDRIVER, platform, chromeVersion); + const existingLocallyDriverVersion = registry.getMatchedDriverVersion( + DriverName.CHROMEDRIVER, + platform, + chromeVersion, + ); if (existingLocallyDriverVersion && !force) { browserInstallerDebug( `A locally installed chromedriver for chrome@${chromeVersion} was found. Skipping the installation`, ); - return registry.getBinaryPath(Driver.CHROMEDRIVER, platform, existingLocallyDriverVersion); + return registry.getBinaryPath(DriverName.CHROMEDRIVER, platform, existingLocallyDriverVersion); } const milestone = getMilestone(chromeVersion); @@ -34,10 +38,10 @@ export const installChromeDriver = async (chromeVersion: string, { force = false return installChromeDriverManually(milestone); } - const buildId = await resolveBuildId(Driver.CHROMEDRIVER, platform, milestone); + const buildId = await resolveBuildId(DriverName.CHROMEDRIVER, platform, milestone); const cacheDir = getChromeDriverDir(); - const canBeInstalled = await canDownload({ browser: Driver.CHROMEDRIVER, platform, buildId, cacheDir }); + const canBeInstalled = await canDownload({ browser: DriverName.CHROMEDRIVER, platform, buildId, cacheDir }); if (!canBeInstalled) { throw new Error( @@ -54,10 +58,10 @@ export const installChromeDriver = async (chromeVersion: string, { force = false platform, buildId, cacheDir: getChromeDriverDir(), - browser: Driver.CHROMEDRIVER, + browser: DriverName.CHROMEDRIVER, unpack: true, downloadProgressCallback, }).then(result => result.executablePath); - return registry.installBinary(Driver.CHROMEDRIVER, platform, buildId, installFn); + return registry.installBinary(DriverName.CHROMEDRIVER, platform, buildId, installFn); }; diff --git a/src/browser-installer/chromium/browser.ts b/src/browser-installer/chromium/browser.ts index 029947a24..e8a6b8f9e 100644 --- a/src/browser-installer/chromium/browser.ts +++ b/src/browser-installer/chromium/browser.ts @@ -1,9 +1,10 @@ import { install as puppeteerInstall, canDownload } from "@puppeteer/browsers"; import registry from "../registry"; -import { getMilestone, browserInstallerDebug, getBrowsersDir, Browser, type DownloadProgressCallback } from "../utils"; +import { getMilestone, browserInstallerDebug, getBrowsersDir, type DownloadProgressCallback } from "../utils"; import { getChromiumBuildId } from "./utils"; import { getChromePlatform } from "../utils"; import { MIN_CHROMIUM_VERSION } from "../constants"; +import { BrowserName } from "../../browser/types"; export const installChromium = async (version: string, { force = false } = {}): Promise => { const milestone = getMilestone(version); @@ -18,17 +19,17 @@ export const installChromium = async (version: string, { force = false } = {}): } const platform = getChromePlatform(version); - const existingLocallyBrowserVersion = registry.getMatchedBrowserVersion(Browser.CHROMIUM, platform, version); + const existingLocallyBrowserVersion = registry.getMatchedBrowserVersion(BrowserName.CHROMIUM, platform, version); if (existingLocallyBrowserVersion && !force) { browserInstallerDebug(`A locally installed chromium@${version} browser was found. Skipping the installation`); - return registry.getBinaryPath(Browser.CHROMIUM, platform, existingLocallyBrowserVersion); + return registry.getBinaryPath(BrowserName.CHROMIUM, platform, existingLocallyBrowserVersion); } const buildId = await getChromiumBuildId(platform, milestone); const cacheDir = getBrowsersDir(); - const canBeInstalled = await canDownload({ browser: Browser.CHROMIUM, platform, buildId, cacheDir }); + const canBeInstalled = await canDownload({ browser: BrowserName.CHROMIUM, platform, buildId, cacheDir }); if (!canBeInstalled) { throw new Error( @@ -48,9 +49,9 @@ export const installChromium = async (version: string, { force = false } = {}): buildId, cacheDir, downloadProgressCallback, - browser: Browser.CHROMIUM, + browser: BrowserName.CHROMIUM, unpack: true, }).then(result => result.executablePath); - return registry.installBinary(Browser.CHROMIUM, platform, milestone, installFn); + return registry.installBinary(BrowserName.CHROMIUM, platform, milestone, installFn); }; diff --git a/src/browser-installer/chromium/driver.ts b/src/browser-installer/chromium/driver.ts index e53dd73b6..bf99ef06b 100644 --- a/src/browser-installer/chromium/driver.ts +++ b/src/browser-installer/chromium/driver.ts @@ -9,7 +9,7 @@ import { retryFetch, unzipFile, normalizeChromeVersion, - Driver, + DriverName, getBrowserPlatform, } from "../utils"; import { getChromeDriverArchiveTmpPath, getChromeDriverArchiveUrl } from "./utils"; @@ -50,5 +50,5 @@ export const installChromeDriverManually = async (milestone: string): Promise => { const platform = getBrowserPlatform(); - const existingLocallyDriverVersion = registry.getMatchedDriverVersion(Driver.EDGEDRIVER, platform, edgeVersion); + const existingLocallyDriverVersion = registry.getMatchedDriverVersion(DriverName.EDGEDRIVER, platform, edgeVersion); if (existingLocallyDriverVersion && !force) { browserInstallerDebug( `A locally installed edgedriver for edge@${edgeVersion} browser was found. Skipping the installation`, ); - return registry.getBinaryPath(Driver.EDGEDRIVER, platform, existingLocallyDriverVersion); + return registry.getBinaryPath(DriverName.EDGEDRIVER, platform, existingLocallyDriverVersion); } const milestone = getMilestone(edgeVersion); @@ -49,5 +49,5 @@ export const installEdgeDriver = async (edgeVersion: string, { force = false } = const installFn = (): Promise => downloadEdgeDriver(driverVersion, getEdgeDriverDir(driverVersion)); - return registry.installBinary(Driver.EDGEDRIVER, platform, driverVersion, installFn); + return registry.installBinary(DriverName.EDGEDRIVER, platform, driverVersion, installFn); }; diff --git a/src/browser-installer/firefox/browser.ts b/src/browser-installer/firefox/browser.ts index b366d4cf9..140df5619 100644 --- a/src/browser-installer/firefox/browser.ts +++ b/src/browser-installer/firefox/browser.ts @@ -1,31 +1,26 @@ import { canDownload, install as puppeteerInstall } from "@puppeteer/browsers"; -import { - Browser, - browserInstallerDebug, - getBrowserPlatform, - getBrowsersDir, - type DownloadProgressCallback, -} from "../utils"; +import { browserInstallerDebug, getBrowserPlatform, getBrowsersDir, type DownloadProgressCallback } from "../utils"; import registry from "../registry"; import { getFirefoxBuildId, normalizeFirefoxVersion } from "./utils"; import { installLatestGeckoDriver } from "./driver"; import { installUbuntuPackageDependencies } from "../ubuntu-packages"; +import { BrowserName } from "../../browser/types"; const installFirefoxBrowser = async (version: string, { force = false } = {}): Promise => { const platform = getBrowserPlatform(); - const existingLocallyBrowserVersion = registry.getMatchedBrowserVersion(Browser.FIREFOX, platform, version); + const existingLocallyBrowserVersion = registry.getMatchedBrowserVersion(BrowserName.FIREFOX, platform, version); if (existingLocallyBrowserVersion && !force) { browserInstallerDebug(`A locally installed firefox@${version} browser was found. Skipping the installation`); - return registry.getBinaryPath(Browser.FIREFOX, platform, existingLocallyBrowserVersion); + return registry.getBinaryPath(BrowserName.FIREFOX, platform, existingLocallyBrowserVersion); } const normalizedVersion = normalizeFirefoxVersion(version); const buildId = getFirefoxBuildId(normalizedVersion); const cacheDir = getBrowsersDir(); - const canBeInstalled = await canDownload({ browser: Browser.FIREFOX, platform, buildId, cacheDir }); + const canBeInstalled = await canDownload({ browser: BrowserName.FIREFOX, platform, buildId, cacheDir }); if (!canBeInstalled) { throw new Error( @@ -45,11 +40,11 @@ const installFirefoxBrowser = async (version: string, { force = false } = {}): P buildId, cacheDir, downloadProgressCallback, - browser: Browser.FIREFOX, + browser: BrowserName.FIREFOX, unpack: true, }).then(result => result.executablePath); - return registry.installBinary(Browser.FIREFOX, platform, buildId, installFn); + return registry.installBinary(BrowserName.FIREFOX, platform, buildId, installFn); }; export const installFirefox = async ( diff --git a/src/browser-installer/firefox/driver.ts b/src/browser-installer/firefox/driver.ts index 2843c709a..0dcbbc2a5 100644 --- a/src/browser-installer/firefox/driver.ts +++ b/src/browser-installer/firefox/driver.ts @@ -1,7 +1,7 @@ import { download as downloadGeckoDriver } from "geckodriver"; import { GECKODRIVER_CARGO_TOML } from "../constants"; import registry from "../registry"; -import { Driver, browserInstallerDebug, getBrowserPlatform, getGeckoDriverDir, retryFetch } from "../utils"; +import { DriverName, browserInstallerDebug, getBrowserPlatform, getGeckoDriverDir, retryFetch } from "../utils"; const getLatestGeckoDriverVersion = async (): Promise => { const cargoVersionsToml = await retryFetch(GECKODRIVER_CARGO_TOML).then(res => res.text()); @@ -20,19 +20,23 @@ const getLatestGeckoDriverVersion = async (): Promise => { export const installLatestGeckoDriver = async (firefoxVersion: string, { force = false } = {}): Promise => { const platform = getBrowserPlatform(); - const existingLocallyDriverVersion = registry.getMatchedDriverVersion(Driver.GECKODRIVER, platform, firefoxVersion); + const existingLocallyDriverVersion = registry.getMatchedDriverVersion( + DriverName.GECKODRIVER, + platform, + firefoxVersion, + ); if (existingLocallyDriverVersion && !force) { browserInstallerDebug( `A locally installed geckodriver for firefox@${firefoxVersion} browser was found. Skipping the installation`, ); - return registry.getBinaryPath(Driver.GECKODRIVER, platform, existingLocallyDriverVersion); + return registry.getBinaryPath(DriverName.GECKODRIVER, platform, existingLocallyDriverVersion); } const latestVersion = await getLatestGeckoDriverVersion(); const installFn = (): Promise => downloadGeckoDriver(latestVersion, getGeckoDriverDir(latestVersion)); - return registry.installBinary(Driver.GECKODRIVER, platform, latestVersion, installFn); + return registry.installBinary(DriverName.GECKODRIVER, platform, latestVersion, installFn); }; diff --git a/src/browser-installer/index.ts b/src/browser-installer/index.ts index e3b21c33f..c8c035e93 100644 --- a/src/browser-installer/index.ts +++ b/src/browser-installer/index.ts @@ -1,4 +1,3 @@ export { installBrowser, installBrowsersWithDrivers, BrowserInstallStatus } from "./install"; export { runBrowserDriver } from "./run"; -export { getNormalizedBrowserName } from "./utils"; export type { SupportedBrowser, SupportedDriver } from "./utils"; diff --git a/src/browser-installer/install.ts b/src/browser-installer/install.ts index d2552801d..dafec2a08 100644 --- a/src/browser-installer/install.ts +++ b/src/browser-installer/install.ts @@ -1,5 +1,7 @@ import _ from "lodash"; -import { Browser, browserInstallerDebug, getNormalizedBrowserName, type SupportedBrowser } from "./utils"; +import { browserInstallerDebug, type SupportedBrowser } from "./utils"; +import { getNormalizedBrowserName } from "../utils/browser"; +import { BrowserName } from "../browser/types"; /** * @returns path to installed browser binary @@ -29,20 +31,20 @@ export const installBrowser = async ( ); switch (browserName) { - case Browser.CHROME: - case Browser.CHROMIUM: { + case BrowserName.CHROME: + case BrowserName.CHROMIUM: { const { installChrome } = await import("./chrome"); return installChrome(browserVersion, { force, needUbuntuPackages, needWebDriver: shouldInstallWebDriver }); } - case Browser.FIREFOX: { + case BrowserName.FIREFOX: { const { installFirefox } = await import("./firefox"); return installFirefox(browserVersion, { force, needUbuntuPackages, needWebDriver: shouldInstallWebDriver }); } - case Browser.EDGE: { + case BrowserName.EDGE: { const { installEdgeDriver } = await import("./edge"); if (shouldInstallWebDriver) { @@ -52,7 +54,7 @@ export const installBrowser = async ( return null; } - case Browser.SAFARI: { + case BrowserName.SAFARI: { return null; } } diff --git a/src/browser-installer/registry/index.ts b/src/browser-installer/registry/index.ts index 33e29158c..e12eec26f 100644 --- a/src/browser-installer/registry/index.ts +++ b/src/browser-installer/registry/index.ts @@ -5,8 +5,7 @@ import path from "path"; import { getRegistryPath, browserInstallerDebug, - Driver, - Browser, + DriverName, getMilestone, normalizeChromeVersion, semverVersionsComparator, @@ -16,6 +15,7 @@ import { } from "../utils"; import { getFirefoxBuildId } from "../firefox/utils"; import logger from "../../utils/logger"; +import { BrowserName } from "../../browser/types"; type VersionToPathMap = Record>; type BinaryName = Exclude; @@ -98,7 +98,7 @@ class Registry { return null; } - if (driverName === Driver.CHROMEDRIVER || driverName === Driver.EDGEDRIVER) { + if (driverName === DriverName.CHROMEDRIVER || driverName === DriverName.EDGEDRIVER) { const milestone = getMilestone(browserVersion); const buildIds = this.getBinaryVersions(driverName, platform); const suitableBuildIds = buildIds.filter(buildId => buildId.startsWith(milestone)); @@ -110,7 +110,7 @@ class Registry { return suitableBuildIds.sort(semverVersionsComparator).pop() as string; } - if (driverName === Driver.GECKODRIVER) { + if (driverName === DriverName.GECKODRIVER) { const buildIds = Object.keys(this.registry.binaries[registryKey]); const buildIdsSorted = buildIds.sort(semverVersionsComparator); @@ -134,15 +134,15 @@ class Registry { let buildPrefix: string; switch (browserName) { - case Browser.CHROME: + case BrowserName.CHROME: buildPrefix = normalizeChromeVersion(browserVersion); break; - case Browser.CHROMIUM: + case BrowserName.CHROMIUM: buildPrefix = getMilestone(browserVersion); break; - case Browser.FIREFOX: + case BrowserName.FIREFOX: buildPrefix = getFirefoxBuildId(browserVersion); break; @@ -166,7 +166,7 @@ class Registry { return parseInt(a.replace(".", ""), 16) - parseInt(b.replace(".", ""), 16); }; - const comparator = browserName === Browser.FIREFOX ? firefoxVersionComparator : semverVersionsComparator; + const comparator = browserName === BrowserName.FIREFOX ? firefoxVersionComparator : semverVersionsComparator; const suitableBuildIdsSorted = suitableBuildIds.sort(comparator); return suitableBuildIdsSorted[suitableBuildIdsSorted.length - 1]; diff --git a/src/browser-installer/run.ts b/src/browser-installer/run.ts index c2dde8ebb..d1885768c 100644 --- a/src/browser-installer/run.ts +++ b/src/browser-installer/run.ts @@ -1,6 +1,7 @@ import type { ChildProcess } from "child_process"; import { installBrowser } from "./install"; -import { Browser, type SupportedBrowser } from "./utils"; +import type { SupportedBrowser } from "./utils"; +import { BrowserName } from "../browser/types"; export const runBrowserDriver = async ( browserName: SupportedBrowser, @@ -12,16 +13,18 @@ export const runBrowserDriver = async ( await installBrowser(browserName, browserVersion, installBrowserOpts); switch (browserName) { - case Browser.CHROME: - case Browser.CHROMIUM: + case BrowserName.CHROME: + case BrowserName.CHROMIUM: return import("./chrome").then(module => module.runChromeDriver(browserVersion, { debug })); - case Browser.FIREFOX: + case BrowserName.FIREFOX: return import("./firefox").then(module => module.runGeckoDriver(browserVersion, { debug })); - case Browser.EDGE: + case BrowserName.EDGE: return import("./edge").then(module => module.runEdgeDriver(browserVersion, { debug })); - case Browser.SAFARI: + case BrowserName.SAFARI: return import("./safari").then(module => module.runSafariDriver({ debug })); default: - throw new Error(`Invalid browser: ${browserName}. Expected one of: ${Object.values(Browser).join(", ")}`); + throw new Error( + `Invalid browser: ${browserName}. Expected one of: ${Object.values(BrowserName).join(", ")}`, + ); } }; diff --git a/src/browser-installer/ubuntu-packages/collect-dependencies/browser-versions/index.ts b/src/browser-installer/ubuntu-packages/collect-dependencies/browser-versions/index.ts index 43360df23..19a010937 100644 --- a/src/browser-installer/ubuntu-packages/collect-dependencies/browser-versions/index.ts +++ b/src/browser-installer/ubuntu-packages/collect-dependencies/browser-versions/index.ts @@ -2,16 +2,17 @@ import { fetchChromiumMilestoneVersions } from "./chromium"; import { fetchChromeMilestoneVersions } from "./chrome"; import { fetchFirefoxMilestoneVersions } from "./firefox"; import type { BrowserWithVersion } from "../utils"; -import { Browser, type SupportedBrowser } from "../../../utils"; +import type { SupportedBrowser } from "../../../utils"; +import { BrowserName } from "../../../../browser/types"; export const fetchBrowsersMilestones = async (): Promise => { const createMapToBrowser = (browserName: SupportedBrowser) => (data: string[]) => data.map(browserVersion => ({ browserName, browserVersion })); const [chromiumVersions, chromeVersions, firefoxVersions] = await Promise.all([ - fetchChromiumMilestoneVersions().then(createMapToBrowser(Browser.CHROME)), - fetchChromeMilestoneVersions().then(createMapToBrowser(Browser.CHROME)), - fetchFirefoxMilestoneVersions().then(createMapToBrowser(Browser.FIREFOX)), + fetchChromiumMilestoneVersions().then(createMapToBrowser(BrowserName.CHROME)), + fetchChromeMilestoneVersions().then(createMapToBrowser(BrowserName.CHROME)), + fetchFirefoxMilestoneVersions().then(createMapToBrowser(BrowserName.FIREFOX)), ]); return [...chromiumVersions, ...chromeVersions, ...firefoxVersions]; diff --git a/src/browser-installer/utils.ts b/src/browser-installer/utils.ts index 850a7209e..74e4cdb62 100644 --- a/src/browser-installer/utils.ts +++ b/src/browser-installer/utils.ts @@ -6,54 +6,21 @@ import fs from "fs-extra"; import { Readable } from "stream"; import debug from "debug"; import { MIN_CHROMIUM_MAC_ARM_VERSION } from "./constants"; +import type { BrowserName } from "../browser/types"; export type DownloadProgressCallback = (done: number, total?: number) => void; export const browserInstallerDebug = debug("testplane:browser-installer"); -export const Browser = { - CHROME: PuppeteerBrowser.CHROME, - CHROMIUM: PuppeteerBrowser.CHROMIUM, - FIREFOX: PuppeteerBrowser.FIREFOX, - SAFARI: "safari", - EDGE: "MicrosoftEdge", -} as const; - -export const Driver = { +export const DriverName = { CHROMEDRIVER: PuppeteerBrowser.CHROMEDRIVER, GECKODRIVER: "geckodriver", SAFARIDRIVER: "safaridriver", EDGEDRIVER: "edgedriver", } as const; -export type SupportedBrowser = (typeof Browser)[keyof typeof Browser]; -export type SupportedDriver = (typeof Driver)[keyof typeof Driver]; - -export const getNormalizedBrowserName = ( - browserName?: string, -): Exclude | null => { - if (!browserName) { - return null; - } - - if (/chrome/i.test(browserName)) { - return Browser.CHROME; - } - - if (/firefox/i.test(browserName)) { - return Browser.FIREFOX; - } - - if (/edge/i.test(browserName)) { - return Browser.EDGE; - } - - if (/safari/i.test(browserName)) { - return Browser.SAFARI; - } - - return null; -}; +export type SupportedBrowser = (typeof BrowserName)[keyof typeof BrowserName]; +export type SupportedDriver = (typeof DriverName)[keyof typeof DriverName]; export const createBrowserLabel = (browserName: string, version = "latest"): string => browserName + "@" + version; diff --git a/src/browser-pool/webdriver-pool.ts b/src/browser-pool/webdriver-pool.ts index e102f49c1..0466e5083 100644 --- a/src/browser-pool/webdriver-pool.ts +++ b/src/browser-pool/webdriver-pool.ts @@ -1,5 +1,6 @@ import type { ChildProcess } from "child_process"; -import { runBrowserDriver, getNormalizedBrowserName } from "../browser-installer"; +import { runBrowserDriver } from "../browser-installer"; +import { getNormalizedBrowserName } from "../utils/browser"; import type { SupportedBrowser } from "../browser-installer"; type BrowserVersion = string; diff --git a/src/browser/new-browser.ts b/src/browser/new-browser.ts index 44b47a330..8a8763f66 100644 --- a/src/browser/new-browser.ts +++ b/src/browser/new-browser.ts @@ -8,24 +8,28 @@ import { Browser, BrowserOpts } from "./browser"; import signalHandler from "../signal-handler"; import { runGroup } from "./history"; import { warn } from "../utils/logger"; +import { getNormalizedBrowserName } from "../utils/browser"; import { getInstance } from "../config/runtime-config"; import { DEVTOOLS_PROTOCOL, WEBDRIVER_PROTOCOL, LOCAL_GRID_URL } from "../constants/config"; import { Config } from "../config"; import { BrowserConfig } from "../config/browser-config"; import { gridUrl as DEFAULT_GRID_URL } from "../config/defaults"; - -export type CapabilityName = "goog:chromeOptions" | "moz:firefoxOptions" | "ms:edgeOptions"; -export type HeadlessBrowserOptions = Record< - string, - { - capabilityName: CapabilityName; - getArgs: (headlessMode: BrowserConfig["headless"]) => string[]; - } +import { BrowserName, type W3CBrowserName } from "./types"; + +export type VendorSpecificCapabilityName = "goog:chromeOptions" | "moz:firefoxOptions" | "ms:edgeOptions"; +export type HeadlessBrowserOptions = Partial< + Record< + W3CBrowserName, + { + capabilityName: VendorSpecificCapabilityName; + getArgs: (headlessMode: BrowserConfig["headless"]) => string[]; + } + > >; const DEFAULT_PORT = 4444; const headlessBrowserOptions: HeadlessBrowserOptions = { - chrome: { + [BrowserName.CHROME]: { capabilityName: "goog:chromeOptions", getArgs: (headlessMode: BrowserConfig["headless"]): string[] => { const headlessValue = isBoolean(headlessMode) ? "headless" : `headless=${headlessMode}`; @@ -33,19 +37,11 @@ const headlessBrowserOptions: HeadlessBrowserOptions = { return [headlessValue, "disable-gpu"]; }, }, - firefox: { + [BrowserName.FIREFOX]: { capabilityName: "moz:firefoxOptions", getArgs: (): string[] => ["-headless"], }, - msedge: { - capabilityName: "ms:edgeOptions", - getArgs: (): string[] => ["--headless"], - }, - edge: { - capabilityName: "ms:edgeOptions", - getArgs: (): string[] => ["--headless"], - }, - microsoftedge: { + [BrowserName.EDGE]: { capabilityName: "ms:edgeOptions", getArgs: (): string[] => ["--headless"], }, @@ -168,7 +164,7 @@ export class NewBrowser extends Browser { ); return this._isLocalGridUrl() - ? this._addExecutablePath(config, capabilitiesWithAddedHeadless) + ? this._applyLocalBrowserCapabilities(config, capabilitiesWithAddedHeadless) : Promise.resolve(capabilitiesWithAddedHeadless); } @@ -179,14 +175,19 @@ export class NewBrowser extends Browser { if (!headless) { return capabilities; } - const browserNameLowerCase = capabilities.browserName?.toLocaleLowerCase() as string; - const capabilitySettings = headlessBrowserOptions[browserNameLowerCase]; + const browserNameW3C = getNormalizedBrowserName(capabilities.browserName); + + if (!browserNameW3C) { + return capabilities; + } + + const capabilitySettings = headlessBrowserOptions[browserNameW3C]; if (!capabilitySettings) { warn(`WARNING: Headless setting is not supported for ${capabilities.browserName} browserName`); return capabilities; } - const browserCapabilities = (capabilities[capabilitySettings.capabilityName as CapabilityName] ?? - {}) as WebdriverIO.Capabilities[CapabilityName]; + const browserCapabilities = (capabilities[capabilitySettings.capabilityName as VendorSpecificCapabilityName] ?? + {}) as WebdriverIO.Capabilities[VendorSpecificCapabilityName]; // eslint-disable-next-line @typescript-eslint/no-explicit-any (capabilities as any)[capabilitySettings.capabilityName] = { ...browserCapabilities, @@ -221,33 +222,36 @@ export class NewBrowser extends Browser { return this._wdProcess.gridUrl; } - protected async _addExecutablePath( + protected async _applyLocalBrowserCapabilities( config: BrowserConfig, capabilities: WebdriverIO.Capabilities, ): Promise { - const { getNormalizedBrowserName, installBrowser } = await import("../browser-installer"); - const normalizedBrowserName = getNormalizedBrowserName(this._config.desiredCapabilities?.browserName); + const { installBrowser } = await import("../browser-installer"); + const browserNameW3C = getNormalizedBrowserName(config.desiredCapabilities?.browserName); - if (!normalizedBrowserName) { + if (!browserNameW3C) { throw new Error( [ - `Running auto local "${this._config.desiredCapabilities?.browserName}" is unsupported`, + `Running auto local "${config.desiredCapabilities?.browserName}" is unsupported`, `Supported browsers: "chrome", "firefox", "safari", "edge"`, ].join("\n"), ); } - const executablePath = await installBrowser( - normalizedBrowserName, - this._config.desiredCapabilities?.browserVersion, - { shouldInstallWebDriver: false, shouldInstallUbuntuPackages: true }, - ); + const executablePath = await installBrowser(browserNameW3C, config.desiredCapabilities?.browserVersion, { + shouldInstallWebDriver: false, + shouldInstallUbuntuPackages: true, + }); if (executablePath) { - const browserNameLowerCase = config.desiredCapabilities?.browserName?.toLowerCase() as string; - const { capabilityName } = headlessBrowserOptions[browserNameLowerCase]; - capabilities[capabilityName] ||= {}; - capabilities[capabilityName]!.binary ||= executablePath; + const capabilitySettings = headlessBrowserOptions[browserNameW3C]; + + if (!capabilitySettings) { + return capabilities; + } + + capabilities[capabilitySettings.capabilityName] ||= {}; + capabilities[capabilitySettings.capabilityName]!.binary ||= executablePath; } return capabilities; diff --git a/src/browser/types.ts b/src/browser/types.ts index 6bf2352bf..6fd8cdb97 100644 --- a/src/browser/types.ts +++ b/src/browser/types.ts @@ -1,3 +1,4 @@ +import { Browser as PuppeteerBrowser } from "@puppeteer/browsers"; import type { EventEmitter } from "events"; import type { AssertViewCommand, AssertViewElementCommand } from "./commands/types"; import type { BrowserConfig } from "./../config/browser-config"; @@ -7,6 +8,16 @@ import { OpenAndWaitCommand } from "./commands/openAndWait"; import Callstack from "./history/callstack"; import { Test, Hook } from "../test-reader/test-object"; +export const BrowserName = { + CHROME: PuppeteerBrowser.CHROME, + CHROMIUM: PuppeteerBrowser.CHROMIUM, + FIREFOX: PuppeteerBrowser.FIREFOX, + SAFARI: "safari", + EDGE: "MicrosoftEdge", +} as const; + +export type W3CBrowserName = Exclude<(typeof BrowserName)[keyof typeof BrowserName], PuppeteerBrowser.CHROMIUM>; + export interface BrowserMeta { pid: number; browserVersion: string; diff --git a/src/constants/config.js b/src/constants/config.js deleted file mode 100644 index a37d86882..000000000 --- a/src/constants/config.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; - -module.exports = { - WEBDRIVER_PROTOCOL: "webdriver", - DEVTOOLS_PROTOCOL: "devtools", - SAVE_HISTORY_MODE: { - ALL: "all", - NONE: "none", - ONLY_FAILED: "onlyFailed", - }, - NODEJS_TEST_RUN_ENV: "nodejs", - BROWSER_TEST_RUN_ENV: "browser", - LOCAL_GRID_URL: "local", -}; diff --git a/src/constants/config.ts b/src/constants/config.ts new file mode 100644 index 000000000..6295e90d3 --- /dev/null +++ b/src/constants/config.ts @@ -0,0 +1,10 @@ +export const WEBDRIVER_PROTOCOL = "webdriver"; +export const DEVTOOLS_PROTOCOL = "devtools"; +export const SAVE_HISTORY_MODE = { + ALL: "all", + NONE: "none", + ONLY_FAILED: "onlyFailed", +}; +export const NODEJS_TEST_RUN_ENV = "nodejs"; +export const BROWSER_TEST_RUN_ENV = "browser"; +export const LOCAL_GRID_URL = "local"; diff --git a/src/utils/browser.ts b/src/utils/browser.ts index 1830a2a5d..7da839f62 100644 --- a/src/utils/browser.ts +++ b/src/utils/browser.ts @@ -1,3 +1,4 @@ +import { BrowserName, type W3CBrowserName } from "../browser/types"; import { MIN_CHROME_VERSION_SUPPORT_ISOLATION } from "../constants/browser"; export const isSupportIsolation = (browserName: string, browserVersion = ""): boolean => { @@ -5,3 +6,27 @@ export const isSupportIsolation = (browserName: string, browserVersion = ""): bo return browserName === "chrome" && Number(browserVersionMajor) >= MIN_CHROME_VERSION_SUPPORT_ISOLATION; }; + +export const getNormalizedBrowserName = (browserName?: string): W3CBrowserName | null => { + if (!browserName) { + return null; + } + + if (/chrome/i.test(browserName)) { + return BrowserName.CHROME; + } + + if (/firefox/i.test(browserName)) { + return BrowserName.FIREFOX; + } + + if (/edge/i.test(browserName)) { + return BrowserName.EDGE; + } + + if (/safari/i.test(browserName)) { + return BrowserName.SAFARI; + } + + return null; +}; diff --git a/test/src/browser-installer/chrome/browser.ts b/test/src/browser-installer/chrome/browser.ts index 2192c5683..5da350501 100644 --- a/test/src/browser-installer/chrome/browser.ts +++ b/test/src/browser-installer/chrome/browser.ts @@ -1,7 +1,7 @@ import proxyquire from "proxyquire"; import sinon, { type SinonStub } from "sinon"; +import { BrowserName } from "../../../../src/browser/types"; import type { installChrome as InstallChromeType } from "../../../../src/browser-installer/chrome/browser"; -import { Browser } from "../../../../src/browser-installer/utils"; describe("browser-installer/chrome/browser", () => { const sandbox = sinon.createSandbox(); @@ -57,8 +57,8 @@ describe("browser-installer/chrome/browser", () => { afterEach(() => sandbox.restore()); it("should try to resolve browser path locally by default", async () => { - getMatchedBrowserVersionStub.withArgs(Browser.CHROME, sinon.match.string, "115").returns("115.0"); - getBinaryPathStub.withArgs(Browser.CHROME, sinon.match.string, "115.0").returns("/browser/path"); + getMatchedBrowserVersionStub.withArgs(BrowserName.CHROME, sinon.match.string, "115").returns("115.0"); + getBinaryPathStub.withArgs(BrowserName.CHROME, sinon.match.string, "115.0").returns("/browser/path"); const binaryPath = await installChrome("115"); @@ -68,11 +68,11 @@ describe("browser-installer/chrome/browser", () => { }); it("should not try to resolve browser path locally with 'force' flag", async () => { - getMatchedBrowserVersionStub.withArgs(Browser.CHROME, sinon.match.string, "115").returns("115.0"); - resolveBuildIdStub.withArgs(Browser.CHROME, sinon.match.string, "115").resolves("115.0.5678.170"); + getMatchedBrowserVersionStub.withArgs(BrowserName.CHROME, sinon.match.string, "115").returns("115.0"); + resolveBuildIdStub.withArgs(BrowserName.CHROME, sinon.match.string, "115").resolves("115.0.5678.170"); installBinaryStub - .withArgs(Browser.CHROME, sinon.match.string, "115.0.5678.170", sinon.match.func) + .withArgs(BrowserName.CHROME, sinon.match.string, "115.0.5678.170", sinon.match.func) .resolves("/new/downloaded/browser/path"); const binaryPath = await installChrome("115", { force: true }); @@ -82,10 +82,10 @@ describe("browser-installer/chrome/browser", () => { }); it("should download browser if it is not downloaded", async () => { - getMatchedBrowserVersionStub.withArgs(Browser.CHROME, sinon.match.string, "115").returns(null); - resolveBuildIdStub.withArgs(Browser.CHROME, sinon.match.string, "115").resolves("115.0.5678.170"); + getMatchedBrowserVersionStub.withArgs(BrowserName.CHROME, sinon.match.string, "115").returns(null); + resolveBuildIdStub.withArgs(BrowserName.CHROME, sinon.match.string, "115").resolves("115.0.5678.170"); installBinaryStub - .withArgs(Browser.CHROME, sinon.match.string, "115.0.5678.170", sinon.match.func) + .withArgs(BrowserName.CHROME, sinon.match.string, "115.0.5678.170", sinon.match.func) .resolves("/new/downloaded/browser/path"); const binaryPath = await installChrome("115"); @@ -105,8 +105,8 @@ describe("browser-installer/chrome/browser", () => { }); it("should throw an error if can't download the browser", async () => { - getMatchedBrowserVersionStub.withArgs(Browser.CHROME, sinon.match.string, "115").returns(null); - resolveBuildIdStub.withArgs(Browser.CHROME, sinon.match.string, "115").resolves("115"); + getMatchedBrowserVersionStub.withArgs(BrowserName.CHROME, sinon.match.string, "115").returns(null); + resolveBuildIdStub.withArgs(BrowserName.CHROME, sinon.match.string, "115").resolves("115"); canDownloadStub.resolves(false); await assert.isRejected( diff --git a/test/src/browser-installer/chrome/driver.ts b/test/src/browser-installer/chrome/driver.ts index 11e8673d7..dd387a3ce 100644 --- a/test/src/browser-installer/chrome/driver.ts +++ b/test/src/browser-installer/chrome/driver.ts @@ -1,7 +1,7 @@ import proxyquire from "proxyquire"; import sinon, { type SinonStub } from "sinon"; import type { installChromeDriver as InstallChromeDriverType } from "../../../../src/browser-installer/chrome/driver"; -import { Driver } from "../../../../src/browser-installer/utils"; +import { DriverName } from "../../../../src/browser-installer/utils"; describe("browser-installer/chrome/driver", () => { const sandbox = sinon.createSandbox(); @@ -49,8 +49,8 @@ describe("browser-installer/chrome/driver", () => { afterEach(() => sandbox.restore()); it("should try to resolve driver path locally by default", async () => { - getMatchedDriverVersionStub.withArgs(Driver.CHROMEDRIVER, sinon.match.string, "115").returns("115.0"); - getBinaryPathStub.withArgs(Driver.CHROMEDRIVER, sinon.match.string, "115.0").returns("/driver/path"); + getMatchedDriverVersionStub.withArgs(DriverName.CHROMEDRIVER, sinon.match.string, "115").returns("115.0"); + getBinaryPathStub.withArgs(DriverName.CHROMEDRIVER, sinon.match.string, "115.0").returns("/driver/path"); const driverPath = await installChromeDriver("115"); @@ -60,10 +60,10 @@ describe("browser-installer/chrome/driver", () => { }); it("should not try to resolve driver path locally with 'force' flag", async () => { - getMatchedDriverVersionStub.withArgs(Driver.CHROMEDRIVER, sinon.match.string, "115").returns("115.0"); - resolveBuildIdStub.withArgs(Driver.CHROMEDRIVER, sinon.match.string, "115").resolves("115.0.5678.170"); + getMatchedDriverVersionStub.withArgs(DriverName.CHROMEDRIVER, sinon.match.string, "115").returns("115.0"); + resolveBuildIdStub.withArgs(DriverName.CHROMEDRIVER, sinon.match.string, "115").resolves("115.0.5678.170"); installBinaryStub - .withArgs(Driver.CHROMEDRIVER, sinon.match.string, "115.0.5678.170", sinon.match.func) + .withArgs(DriverName.CHROMEDRIVER, sinon.match.string, "115.0.5678.170", sinon.match.func) .resolves("/new/downloaded/driver/path"); const driverPath = await installChromeDriver("115", { force: true }); @@ -73,10 +73,10 @@ describe("browser-installer/chrome/driver", () => { }); it("should download driver if it is not downloaded", async () => { - getMatchedDriverVersionStub.withArgs(Driver.CHROMEDRIVER, sinon.match.string, "115").returns(null); - resolveBuildIdStub.withArgs(Driver.CHROMEDRIVER, sinon.match.string, "115").resolves("115.0.5678.170"); + getMatchedDriverVersionStub.withArgs(DriverName.CHROMEDRIVER, sinon.match.string, "115").returns(null); + resolveBuildIdStub.withArgs(DriverName.CHROMEDRIVER, sinon.match.string, "115").resolves("115.0.5678.170"); installBinaryStub - .withArgs(Driver.CHROMEDRIVER, sinon.match.string, "115.0.5678.170", sinon.match.func) + .withArgs(DriverName.CHROMEDRIVER, sinon.match.string, "115.0.5678.170", sinon.match.func) .resolves("/new/downloaded/driver/path"); const driverPath = await installChromeDriver("115"); @@ -96,8 +96,8 @@ describe("browser-installer/chrome/driver", () => { }); it("should throw an error if can't download the driver", async () => { - getMatchedDriverVersionStub.withArgs(Driver.CHROMEDRIVER, sinon.match.string, "115").returns(null); - resolveBuildIdStub.withArgs(Driver.CHROMEDRIVER, sinon.match.string, "115").resolves("115.0.5678.170"); + getMatchedDriverVersionStub.withArgs(DriverName.CHROMEDRIVER, sinon.match.string, "115").returns(null); + resolveBuildIdStub.withArgs(DriverName.CHROMEDRIVER, sinon.match.string, "115").resolves("115.0.5678.170"); canDownloadStub.resolves(false); await assert.isRejected( diff --git a/test/src/browser-installer/chromium/browser.ts b/test/src/browser-installer/chromium/browser.ts index fdf9d2f22..ae19055fe 100644 --- a/test/src/browser-installer/chromium/browser.ts +++ b/test/src/browser-installer/chromium/browser.ts @@ -1,7 +1,7 @@ import proxyquire from "proxyquire"; import sinon, { type SinonStub } from "sinon"; import type { installChromium as InstallChromiumType } from "../../../../src/browser-installer/chromium/browser"; -import { Browser } from "../../../../src/browser-installer/utils"; +import { BrowserName } from "../../../../src/browser/types"; describe("browser-installer/chromium/browser", () => { const sandbox = sinon.createSandbox(); @@ -44,8 +44,8 @@ describe("browser-installer/chromium/browser", () => { afterEach(() => sandbox.restore()); it("should try to resolve browser path locally by default", async () => { - getMatchedBrowserVersionStub.withArgs(Browser.CHROMIUM, sinon.match.string, "80").returns("80"); - getBinaryPathStub.withArgs(Browser.CHROMIUM, sinon.match.string, "80").returns("/browser/path"); + getMatchedBrowserVersionStub.withArgs(BrowserName.CHROMIUM, sinon.match.string, "80").returns("80"); + getBinaryPathStub.withArgs(BrowserName.CHROMIUM, sinon.match.string, "80").returns("/browser/path"); const binaryPath = await installChromium("80"); @@ -55,11 +55,11 @@ describe("browser-installer/chromium/browser", () => { }); it("should not try to resolve browser path locally with 'force' flag", async () => { - getMatchedBrowserVersionStub.withArgs(Browser.CHROMIUM, sinon.match.string, "80").returns("80"); - getChromiumBuildIdStub.withArgs(Browser.CHROMIUM, sinon.match.string, "80").resolves("100500"); + getMatchedBrowserVersionStub.withArgs(BrowserName.CHROMIUM, sinon.match.string, "80").returns("80"); + getChromiumBuildIdStub.withArgs(BrowserName.CHROMIUM, sinon.match.string, "80").resolves("100500"); installBinaryStub - .withArgs(Browser.CHROMIUM, sinon.match.string, "80", sinon.match.func) + .withArgs(BrowserName.CHROMIUM, sinon.match.string, "80", sinon.match.func) .resolves("/new/downloaded/browser/path"); const binaryPath = await installChromium("80", { force: true }); @@ -69,10 +69,10 @@ describe("browser-installer/chromium/browser", () => { }); it("should download browser if it is not downloaded", async () => { - getMatchedBrowserVersionStub.withArgs(Browser.CHROMIUM, sinon.match.string, "80").returns(null); - getChromiumBuildIdStub.withArgs(Browser.CHROMIUM, sinon.match.string, "80").resolves("100500"); + getMatchedBrowserVersionStub.withArgs(BrowserName.CHROMIUM, sinon.match.string, "80").returns(null); + getChromiumBuildIdStub.withArgs(BrowserName.CHROMIUM, sinon.match.string, "80").resolves("100500"); installBinaryStub - .withArgs(Browser.CHROMIUM, sinon.match.string, "80", sinon.match.func) + .withArgs(BrowserName.CHROMIUM, sinon.match.string, "80", sinon.match.func) .resolves("/new/downloaded/browser/path"); const binaryPath = await installChromium("80"); @@ -95,8 +95,8 @@ describe("browser-installer/chromium/browser", () => { }); it("should throw an error if can't download the browser", async () => { - getMatchedBrowserVersionStub.withArgs(Browser.CHROMIUM, sinon.match.string, "115").returns(null); - getChromiumBuildIdStub.withArgs(Browser.CHROMIUM, sinon.match.string, "115").resolves("100500"); + getMatchedBrowserVersionStub.withArgs(BrowserName.CHROMIUM, sinon.match.string, "115").returns(null); + getChromiumBuildIdStub.withArgs(BrowserName.CHROMIUM, sinon.match.string, "115").resolves("100500"); canDownloadStub.resolves(false); await assert.isRejected( diff --git a/test/src/browser-installer/chromium/driver.ts b/test/src/browser-installer/chromium/driver.ts index 394e65b7c..024069571 100644 --- a/test/src/browser-installer/chromium/driver.ts +++ b/test/src/browser-installer/chromium/driver.ts @@ -1,7 +1,7 @@ import proxyquire from "proxyquire"; import sinon, { type SinonStub } from "sinon"; import type { installChromeDriverManually as installChromeDriverManuallyType } from "../../../../src/browser-installer/chromium/driver"; -import { Driver } from "../../../../src/browser-installer/utils"; +import { DriverName } from "../../../../src/browser-installer/utils"; describe("browser-installer/chromium/driver", () => { const sandbox = sinon.createSandbox(); @@ -31,7 +31,7 @@ describe("browser-installer/chromium/driver", () => { text: () => Promise.resolve("115.0.5678.170"), }); installBinaryStub - .withArgs(Driver.CHROMEDRIVER, sinon.match.string, "115.0.5678.170", sinon.match.func) + .withArgs(DriverName.CHROMEDRIVER, sinon.match.string, "115.0.5678.170", sinon.match.func) .resolves("/driver/path"); const driverPath = await installChromeDriverManually("115"); diff --git a/test/src/browser-installer/edge/driver.ts b/test/src/browser-installer/edge/driver.ts index f7f9c4b39..7db67d23c 100644 --- a/test/src/browser-installer/edge/driver.ts +++ b/test/src/browser-installer/edge/driver.ts @@ -1,7 +1,7 @@ import proxyquire from "proxyquire"; import sinon, { type SinonStub } from "sinon"; import type { installEdgeDriver as InstallEdgeDriverType } from "../../../../src/browser-installer/edge/driver"; -import { Driver } from "../../../../src/browser-installer/utils"; +import { DriverName } from "../../../../src/browser-installer/utils"; describe("browser-installer/edge/driver", () => { const sandbox = sinon.createSandbox(); @@ -40,8 +40,8 @@ describe("browser-installer/edge/driver", () => { afterEach(() => sandbox.restore()); it("should try to resolve driver path locally by default", async () => { - getMatchedDriverVersionStub.withArgs(Driver.EDGEDRIVER, sinon.match.string, "115").returns("115.0"); - getBinaryPathStub.withArgs(Driver.EDGEDRIVER, sinon.match.string, "115.0").returns("/driver/path"); + getMatchedDriverVersionStub.withArgs(DriverName.EDGEDRIVER, sinon.match.string, "115").returns("115.0"); + getBinaryPathStub.withArgs(DriverName.EDGEDRIVER, sinon.match.string, "115.0").returns("/driver/path"); const driverPath = await installEdgeDriver("115"); @@ -51,12 +51,12 @@ describe("browser-installer/edge/driver", () => { }); it("should not try to resolve driver path locally with 'force' flag", async () => { - getMatchedDriverVersionStub.withArgs(Driver.EDGEDRIVER, sinon.match.string, "115").returns("115.0"); + getMatchedDriverVersionStub.withArgs(DriverName.EDGEDRIVER, sinon.match.string, "115").returns("115.0"); retryFetchStub.withArgs("https://msedgedriver.azureedge.net/LATEST_RELEASE_115").resolves({ text: () => Promise.resolve("115.0.5678.170"), }); installBinaryStub - .withArgs(Driver.EDGEDRIVER, sinon.match.string, "115.0.5678.170", sinon.match.func) + .withArgs(DriverName.EDGEDRIVER, sinon.match.string, "115.0.5678.170", sinon.match.func) .resolves("/new/downloaded/driver/path"); const driverPath = await installEdgeDriver("115", { force: true }); @@ -66,12 +66,12 @@ describe("browser-installer/edge/driver", () => { }); it("should download driver if it is not downloaded", async () => { - getMatchedDriverVersionStub.withArgs(Driver.EDGEDRIVER, sinon.match.string, "115").returns(null); + getMatchedDriverVersionStub.withArgs(DriverName.EDGEDRIVER, sinon.match.string, "115").returns(null); retryFetchStub.withArgs("https://msedgedriver.azureedge.net/LATEST_RELEASE_115").resolves({ text: () => Promise.resolve("115.0.5678.170"), }); installBinaryStub - .withArgs(Driver.EDGEDRIVER, sinon.match.string, "115.0.5678.170", sinon.match.func) + .withArgs(DriverName.EDGEDRIVER, sinon.match.string, "115.0.5678.170", sinon.match.func) .resolves("/new/downloaded/driver/path"); const driverPath = await installEdgeDriver("115"); diff --git a/test/src/browser-installer/firefox/browser.ts b/test/src/browser-installer/firefox/browser.ts index 9b64b2cb1..08fd6d358 100644 --- a/test/src/browser-installer/firefox/browser.ts +++ b/test/src/browser-installer/firefox/browser.ts @@ -1,7 +1,7 @@ import proxyquire from "proxyquire"; import sinon, { type SinonStub } from "sinon"; import type { installFirefox as InstallFirefoxType } from "../../../../src/browser-installer/firefox/browser"; -import { Browser } from "../../../../src/browser-installer/utils"; +import { BrowserName } from "../../../../src/browser/types"; describe("browser-installer/firefox/browser", () => { const sandbox = sinon.createSandbox(); @@ -49,8 +49,8 @@ describe("browser-installer/firefox/browser", () => { afterEach(() => sandbox.restore()); it("should try to resolve browser path locally by default", async () => { - getMatchedBrowserVersionStub.withArgs(Browser.FIREFOX, sinon.match.string, "115").returns("115.0"); - getBinaryPathStub.withArgs(Browser.FIREFOX, sinon.match.string, "115.0").returns("/browser/path"); + getMatchedBrowserVersionStub.withArgs(BrowserName.FIREFOX, sinon.match.string, "115").returns("115.0"); + getBinaryPathStub.withArgs(BrowserName.FIREFOX, sinon.match.string, "115.0").returns("/browser/path"); const binaryPath = await installFirefox("115"); @@ -59,9 +59,9 @@ describe("browser-installer/firefox/browser", () => { }); it("should not try to resolve browser path locally with 'force' flag", async () => { - getMatchedBrowserVersionStub.withArgs(Browser.FIREFOX, sinon.match.string, "115").returns("stable_115.0"); + getMatchedBrowserVersionStub.withArgs(BrowserName.FIREFOX, sinon.match.string, "115").returns("stable_115.0"); installBinaryStub - .withArgs(Browser.FIREFOX, sinon.match.string, "stable_115.0", sinon.match.func) + .withArgs(BrowserName.FIREFOX, sinon.match.string, "stable_115.0", sinon.match.func) .resolves("/new/downloaded/browser/path"); const binaryPath = await installFirefox("115", { force: true }); @@ -71,9 +71,9 @@ describe("browser-installer/firefox/browser", () => { }); it("should download browser if it is not downloaded", async () => { - getMatchedBrowserVersionStub.withArgs(Browser.FIREFOX, sinon.match.string, "115").returns(null); + getMatchedBrowserVersionStub.withArgs(BrowserName.FIREFOX, sinon.match.string, "115").returns(null); installBinaryStub - .withArgs(Browser.FIREFOX, sinon.match.string, "stable_115.0", sinon.match.func) + .withArgs(BrowserName.FIREFOX, sinon.match.string, "stable_115.0", sinon.match.func) .resolves("/new/downloaded/browser/path"); const binaryPath = await installFirefox("115"); @@ -82,7 +82,7 @@ describe("browser-installer/firefox/browser", () => { }); it("should throw an error if can't download the browser", async () => { - getMatchedBrowserVersionStub.withArgs(Browser.FIREFOX, sinon.match.string, "115").returns(null); + getMatchedBrowserVersionStub.withArgs(BrowserName.FIREFOX, sinon.match.string, "115").returns(null); canDownloadStub.resolves(false); await assert.isRejected( diff --git a/test/src/browser-installer/firefox/driver.ts b/test/src/browser-installer/firefox/driver.ts index 4fbd8c4fe..787c260f6 100644 --- a/test/src/browser-installer/firefox/driver.ts +++ b/test/src/browser-installer/firefox/driver.ts @@ -1,7 +1,7 @@ import proxyquire from "proxyquire"; import sinon, { type SinonStub } from "sinon"; import type { installLatestGeckoDriver as InstallLatestGeckoDriverType } from "../../../../src/browser-installer/firefox/driver"; -import { Driver } from "../../../../src/browser-installer/utils"; +import { DriverName } from "../../../../src/browser-installer/utils"; describe("browser-installer/firefox/driver", () => { const sandbox = sinon.createSandbox(); @@ -40,8 +40,8 @@ describe("browser-installer/firefox/driver", () => { afterEach(() => sandbox.restore()); it("should try to resolve driver path locally by default", async () => { - getMatchedDriverVersionStub.withArgs(Driver.GECKODRIVER, sinon.match.string, "115").returns("115.0"); - getBinaryPathStub.withArgs(Driver.GECKODRIVER, sinon.match.string, "115.0").returns("/driver/path"); + getMatchedDriverVersionStub.withArgs(DriverName.GECKODRIVER, sinon.match.string, "115").returns("115.0"); + getBinaryPathStub.withArgs(DriverName.GECKODRIVER, sinon.match.string, "115.0").returns("/driver/path"); const driverPath = await installLatestGeckoDriver("115"); @@ -51,12 +51,12 @@ describe("browser-installer/firefox/driver", () => { }); it("should not try to resolve driver path locally with 'force' flag", async () => { - getMatchedDriverVersionStub.withArgs(Driver.GECKODRIVER, sinon.match.string, "115").returns("115.0"); + getMatchedDriverVersionStub.withArgs(DriverName.GECKODRIVER, sinon.match.string, "115").returns("115.0"); retryFetchStub.withArgs("https://raw.githubusercontent.com/mozilla/geckodriver/release/Cargo.toml").resolves({ text: () => Promise.resolve("version = '0.35.0'"), }); installBinaryStub - .withArgs(Driver.GECKODRIVER, sinon.match.string, "0.35.0", sinon.match.func) + .withArgs(DriverName.GECKODRIVER, sinon.match.string, "0.35.0", sinon.match.func) .resolves("/new/downloaded/driver/path"); const driverPath = await installLatestGeckoDriver("115", { force: true }); @@ -66,12 +66,12 @@ describe("browser-installer/firefox/driver", () => { }); it("should download driver if it is not downloaded", async () => { - getMatchedDriverVersionStub.withArgs(Driver.GECKODRIVER, sinon.match.string, "115").returns(null); + getMatchedDriverVersionStub.withArgs(DriverName.GECKODRIVER, sinon.match.string, "115").returns(null); retryFetchStub.withArgs("https://raw.githubusercontent.com/mozilla/geckodriver/release/Cargo.toml").resolves({ text: () => Promise.resolve("version = '0.35.0'"), }); installBinaryStub - .withArgs(Driver.GECKODRIVER, sinon.match.string, "0.35.0", sinon.match.func) + .withArgs(DriverName.GECKODRIVER, sinon.match.string, "0.35.0", sinon.match.func) .resolves("/new/downloaded/driver/path"); const driverPath = await installLatestGeckoDriver("115"); diff --git a/test/src/browser-installer/install.ts b/test/src/browser-installer/install.ts index 8c2cf00b3..6a8a155f0 100644 --- a/test/src/browser-installer/install.ts +++ b/test/src/browser-installer/install.ts @@ -4,7 +4,7 @@ import type { installBrowser as InstallBrowser, installBrowsersWithDrivers as InstallBrowsersWithDrivers, } from "../../../src/browser-installer/install"; -import { Browser } from "../../../src/browser-installer/utils"; +import { BrowserName } from "../../../src/browser/types"; describe("browser-installer/install", () => { const sandbox = sinon.createSandbox(); @@ -54,7 +54,7 @@ describe("browser-installer/install", () => { it("should install browser", async () => { installChromeStub.withArgs("115").resolves("/browser/path"); - const binaryPath = await installBrowser(Browser.CHROME, "115", { force }); + const binaryPath = await installBrowser(BrowserName.CHROME, "115", { force }); assert.equal(binaryPath, "/browser/path"); assert.calledOnceWith(installChromeStub, "115", { @@ -67,7 +67,7 @@ describe("browser-installer/install", () => { it("should install browser with webdriver", async () => { installChromeStub.withArgs("115").resolves("/browser/path"); - const binaryPath = await installBrowser(Browser.CHROME, "115", { + const binaryPath = await installBrowser(BrowserName.CHROME, "115", { force, shouldInstallWebDriver: true, }); @@ -85,7 +85,7 @@ describe("browser-installer/install", () => { it("should install browser", async () => { installFirefoxStub.withArgs("115").resolves("/browser/path"); - const binaryPath = await installBrowser(Browser.FIREFOX, "115", { force }); + const binaryPath = await installBrowser(BrowserName.FIREFOX, "115", { force }); assert.equal(binaryPath, "/browser/path"); assert.calledOnceWith(installFirefoxStub, "115", { @@ -98,7 +98,7 @@ describe("browser-installer/install", () => { it("should install browser with webdriver", async () => { installFirefoxStub.withArgs("115").resolves("/browser/path"); - const binaryPath = await installBrowser(Browser.FIREFOX, "115", { + const binaryPath = await installBrowser(BrowserName.FIREFOX, "115", { force, shouldInstallWebDriver: true, }); @@ -144,7 +144,7 @@ describe("browser-installer/install", () => { it("should throw exception on empty browser version", async () => { await assert.isRejected( - installBrowser(Browser.CHROME, "", { force }), + installBrowser(BrowserName.CHROME, "", { force }), /Couldn't install browser 'chrome' because it has invalid version: ''/, ); }); diff --git a/test/src/browser-installer/registry.ts b/test/src/browser-installer/registry.ts index 2a49eef9f..d55bed8a4 100644 --- a/test/src/browser-installer/registry.ts +++ b/test/src/browser-installer/registry.ts @@ -2,9 +2,10 @@ import proxyquire from "proxyquire"; import sinon, { type SinonStub } from "sinon"; import type RegistryType from "../../../src/browser-installer/registry"; import type { RegistryFileContents } from "../../../src/browser-installer/registry"; -import { Browser, Driver, type DownloadProgressCallback } from "../../../src/browser-installer/utils"; +import { DriverName, type DownloadProgressCallback } from "../../../src/browser-installer/utils"; import { BrowserPlatform } from "@puppeteer/browsers"; import type { PartialDeep } from "type-fest"; +import { BrowserName } from "../../../src/browser/types"; describe("browser-installer/registry", () => { const sandbox = sinon.createSandbox(); @@ -70,7 +71,7 @@ describe("browser-installer/registry", () => { }, }); - const result = await registry.getBinaryPath(Browser.CHROME, BrowserPlatform.MAC_ARM, "115.0.5790.170"); + const result = await registry.getBinaryPath(BrowserName.CHROME, BrowserPlatform.MAC_ARM, "115.0.5790.170"); assert.equal(result, "/testplane/registry/browsers/chrome"); }); @@ -78,7 +79,8 @@ describe("browser-installer/registry", () => { it("should throw an error if browser is not installed", async () => { registry = createRegistry_({}); - const fn = (): Promise => registry.getBinaryPath(Browser.CHROME, BrowserPlatform.MAC_ARM, "115"); + const fn = (): Promise => + registry.getBinaryPath(BrowserName.CHROME, BrowserPlatform.MAC_ARM, "115"); await assert.isRejected(fn(), "Binary 'chrome' on 'mac_arm' is not installed"); }); @@ -87,7 +89,8 @@ describe("browser-installer/registry", () => { // eslint-disable-next-line camelcase registry = createRegistry_({ binaries: { chrome_mac_arm: {} } }); - const fn = (): Promise => registry.getBinaryPath(Browser.CHROME, BrowserPlatform.MAC_ARM, "120"); + const fn = (): Promise => + registry.getBinaryPath(BrowserName.CHROME, BrowserPlatform.MAC_ARM, "120"); await assert.isRejected(fn(), "Version '120' of driver 'chrome' on 'mac_arm' is not installed"); }); @@ -106,8 +109,8 @@ describe("browser-installer/registry", () => { }, }); - const version = registry.getMatchedBrowserVersion(Browser.CHROME, BrowserPlatform.MAC_ARM, "115"); - const versionFull = registry.getMatchedBrowserVersion(Browser.CHROME, BrowserPlatform.MAC_ARM, "115.0"); + const version = registry.getMatchedBrowserVersion(BrowserName.CHROME, BrowserPlatform.MAC_ARM, "115"); + const versionFull = registry.getMatchedBrowserVersion(BrowserName.CHROME, BrowserPlatform.MAC_ARM, "115.0"); assert.equal(version, "115.0.5790.170"); assert.equal(versionFull, "115.0.5790.170"); @@ -125,8 +128,12 @@ describe("browser-installer/registry", () => { }, }); - const version = registry.getMatchedBrowserVersion(Browser.FIREFOX, BrowserPlatform.MAC_ARM, "117"); - const versionFull = registry.getMatchedBrowserVersion(Browser.FIREFOX, BrowserPlatform.MAC_ARM, "117.0"); + const version = registry.getMatchedBrowserVersion(BrowserName.FIREFOX, BrowserPlatform.MAC_ARM, "117"); + const versionFull = registry.getMatchedBrowserVersion( + BrowserName.FIREFOX, + BrowserPlatform.MAC_ARM, + "117.0", + ); assert.equal(version, "stable_117.0b9"); assert.equal(versionFull, "stable_117.0b9"); @@ -144,8 +151,8 @@ describe("browser-installer/registry", () => { }, }); - const version = registry.getMatchedBrowserVersion(Browser.CHROME, BrowserPlatform.MAC_ARM, "116"); - const versionFull = registry.getMatchedBrowserVersion(Browser.CHROME, BrowserPlatform.MAC_ARM, "116.0"); + const version = registry.getMatchedBrowserVersion(BrowserName.CHROME, BrowserPlatform.MAC_ARM, "116"); + const versionFull = registry.getMatchedBrowserVersion(BrowserName.CHROME, BrowserPlatform.MAC_ARM, "116.0"); assert.equal(version, null); assert.equal(versionFull, null); @@ -165,8 +172,12 @@ describe("browser-installer/registry", () => { }, }); - const version = registry.getMatchedDriverVersion(Driver.CHROMEDRIVER, BrowserPlatform.MAC_ARM, "115"); - const versionFull = registry.getMatchedDriverVersion(Driver.CHROMEDRIVER, BrowserPlatform.MAC_ARM, "115.0"); + const version = registry.getMatchedDriverVersion(DriverName.CHROMEDRIVER, BrowserPlatform.MAC_ARM, "115"); + const versionFull = registry.getMatchedDriverVersion( + DriverName.CHROMEDRIVER, + BrowserPlatform.MAC_ARM, + "115.0", + ); assert.equal(version, "115.0.5790.170"); assert.equal(versionFull, "115.0.5790.170"); @@ -184,8 +195,12 @@ describe("browser-installer/registry", () => { }, }); - const version = registry.getMatchedDriverVersion(Driver.EDGEDRIVER, BrowserPlatform.MAC_ARM, "115"); - const versionFull = registry.getMatchedDriverVersion(Driver.EDGEDRIVER, BrowserPlatform.MAC_ARM, "115.0"); + const version = registry.getMatchedDriverVersion(DriverName.EDGEDRIVER, BrowserPlatform.MAC_ARM, "115"); + const versionFull = registry.getMatchedDriverVersion( + DriverName.EDGEDRIVER, + BrowserPlatform.MAC_ARM, + "115.0", + ); assert.equal(version, "115.0.5790.170"); assert.equal(versionFull, "115.0.5790.170"); @@ -203,8 +218,12 @@ describe("browser-installer/registry", () => { }, }); - const version = registry.getMatchedDriverVersion(Driver.GECKODRIVER, BrowserPlatform.MAC_ARM, "115"); - const versionFull = registry.getMatchedDriverVersion(Driver.GECKODRIVER, BrowserPlatform.MAC_ARM, "115.0"); + const version = registry.getMatchedDriverVersion(DriverName.GECKODRIVER, BrowserPlatform.MAC_ARM, "115"); + const versionFull = registry.getMatchedDriverVersion( + DriverName.GECKODRIVER, + BrowserPlatform.MAC_ARM, + "115.0", + ); assert.equal(version, "0.35.0"); assert.equal(versionFull, "0.35.0"); @@ -218,8 +237,12 @@ describe("browser-installer/registry", () => { }, }); - const version = registry.getMatchedDriverVersion(Driver.GECKODRIVER, BrowserPlatform.MAC_ARM, "115"); - const versionFull = registry.getMatchedDriverVersion(Driver.GECKODRIVER, BrowserPlatform.MAC_ARM, "115.0"); + const version = registry.getMatchedDriverVersion(DriverName.GECKODRIVER, BrowserPlatform.MAC_ARM, "115"); + const versionFull = registry.getMatchedDriverVersion( + DriverName.GECKODRIVER, + BrowserPlatform.MAC_ARM, + "115.0", + ); assert.equal(version, null); assert.equal(versionFull, null); @@ -228,7 +251,7 @@ describe("browser-installer/registry", () => { describe("installBinary", () => { it("should install binary and return its executable path", async () => { - const result = await registry.installBinary(Browser.CHROME, BrowserPlatform.LINUX, "100.0.0.0", () => + const result = await registry.installBinary(BrowserName.CHROME, BrowserPlatform.LINUX, "100.0.0.0", () => Promise.resolve("/browser/path"), ); @@ -247,7 +270,7 @@ describe("browser-installer/registry", () => { const installFn = sinon.stub().resolves("/another/browser/path"); const result = await registry.installBinary( - Browser.CHROME, + BrowserName.CHROME, BrowserPlatform.MAC_ARM, "115.0.5320.180", installFn, @@ -259,9 +282,13 @@ describe("browser-installer/registry", () => { it("should save binary to registry after install", async () => { const installFn = sinon.stub().resolves("/testplane/registry/browser/path"); - await registry.installBinary(Browser.CHROME, BrowserPlatform.MAC_ARM, "115.0.5320.180", installFn); + await registry.installBinary(BrowserName.CHROME, BrowserPlatform.MAC_ARM, "115.0.5320.180", installFn); - const savedPath = await registry.getBinaryPath(Browser.CHROME, BrowserPlatform.MAC_ARM, "115.0.5320.180"); + const savedPath = await registry.getBinaryPath( + BrowserName.CHROME, + BrowserPlatform.MAC_ARM, + "115.0.5320.180", + ); assert.equal(savedPath, "/testplane/registry/browser/path"); assert.calledOnceWith( @@ -288,9 +315,9 @@ describe("browser-installer/registry", () => { return "/testplane/registry/browser/path"; }; - await registry.installBinary(Browser.CHROME, BrowserPlatform.MAC_ARM, "115.0.5320.180", installFn); + await registry.installBinary(BrowserName.CHROME, BrowserPlatform.MAC_ARM, "115.0.5320.180", installFn); - await registry.installBinary(Browser.FIREFOX, BrowserPlatform.MAC_ARM, "120.0.5320.180", installFn); + await registry.installBinary(BrowserName.FIREFOX, BrowserPlatform.MAC_ARM, "120.0.5320.180", installFn); assert.calledWith(loggerWarnStub, "Downloading Testplane browsers"); assert.calledWith(loggerWarnStub, "Note: this is one-time action. It may take a while..."); diff --git a/test/src/browser-installer/run.ts b/test/src/browser-installer/run.ts index 522463315..334691a8d 100644 --- a/test/src/browser-installer/run.ts +++ b/test/src/browser-installer/run.ts @@ -1,7 +1,7 @@ import proxyquire from "proxyquire"; import sinon, { type SinonStub } from "sinon"; import type { runBrowserDriver as RunBrowserDriver } from "../../../src/browser-installer/run"; -import { Browser } from "../../../src/browser-installer/utils"; +import { BrowserName } from "../../../src/browser/types"; describe("browser-installer/run", () => { const sandbox = sinon.createSandbox(); @@ -28,16 +28,16 @@ describe("browser-installer/run", () => { [true, false, undefined].forEach(debug => { it(`should run chrome driver with debug: ${debug}`, async () => { - await runBrowserDriver(Browser.CHROME, "some-version", { debug }); + await runBrowserDriver(BrowserName.CHROME, "some-version", { debug }); assert.calledOnceWith(runChromeDriverStub, "some-version", { debug: Boolean(debug) }); }); }); it(`should try to install chrome before running its driver`, async () => { - await runBrowserDriver(Browser.CHROME, "some-version"); + await runBrowserDriver(BrowserName.CHROME, "some-version"); - assert.calledOnceWith(installBrowserStub, Browser.CHROME, "some-version", { + assert.calledOnceWith(installBrowserStub, BrowserName.CHROME, "some-version", { shouldInstallWebDriver: true, shouldInstallUbuntuPackages: true, }); @@ -45,9 +45,9 @@ describe("browser-installer/run", () => { }); it(`should try to install firefox before running its driver`, async () => { - await runBrowserDriver(Browser.FIREFOX, "some-version"); + await runBrowserDriver(BrowserName.FIREFOX, "some-version"); - assert.calledOnceWith(installBrowserStub, Browser.FIREFOX, "some-version", { + assert.calledOnceWith(installBrowserStub, BrowserName.FIREFOX, "some-version", { shouldInstallWebDriver: true, shouldInstallUbuntuPackages: true, }); diff --git a/test/src/browser-installer/ubuntu-packages/collect-dependencies/cache.ts b/test/src/browser-installer/ubuntu-packages/collect-dependencies/cache.ts index 64d7bbe64..983f52502 100644 --- a/test/src/browser-installer/ubuntu-packages/collect-dependencies/cache.ts +++ b/test/src/browser-installer/ubuntu-packages/collect-dependencies/cache.ts @@ -4,7 +4,7 @@ import type { Cache as CacheType, CacheData, } from "../../../../../src/browser-installer/ubuntu-packages/collect-dependencies/cache"; -import { Browser } from "../../../../../src/browser-installer/utils"; +import { BrowserName } from "../../../../../src/browser/types"; describe("browser-installer/ubuntu-packages/collect-dependencies/shared-object", () => { const sandbox = sinon.createSandbox(); @@ -59,8 +59,8 @@ describe("browser-installer/ubuntu-packages/collect-dependencies/shared-object", }); const filteredBrowsers = cache.filterProcessedBrowsers([ - { browserName: Browser.CHROME, browserVersion: "80.0.123.17" }, - { browserName: Browser.CHROME, browserVersion: "82.0.123.17" }, + { browserName: BrowserName.CHROME, browserVersion: "80.0.123.17" }, + { browserName: BrowserName.CHROME, browserVersion: "82.0.123.17" }, ]); assert.deepEqual(filteredBrowsers, [{ browserName: "chrome", browserVersion: "82.0.123.17" }]); @@ -68,8 +68,8 @@ describe("browser-installer/ubuntu-packages/collect-dependencies/shared-object", it("should save processed browsers", async () => { cache.saveProcessedBrowsers([ - { browserName: Browser.CHROME, browserVersion: "80.0.123.17" }, - { browserName: Browser.CHROME, browserVersion: "82.0.123.17" }, + { browserName: BrowserName.CHROME, browserVersion: "80.0.123.17" }, + { browserName: BrowserName.CHROME, browserVersion: "82.0.123.17" }, ]); const cacheData = await getCache_(); diff --git a/test/src/browser-installer/utils.ts b/test/src/browser-installer/utils.ts index abce0e804..5c8e0a96d 100644 --- a/test/src/browser-installer/utils.ts +++ b/test/src/browser-installer/utils.ts @@ -1,34 +1,6 @@ -import { Browser } from "../../../src/browser-installer/utils"; import * as utils from "../../../src/browser-installer/utils"; describe("browser-installer/utils", () => { - describe("getNormalizedBrowserName", () => { - it("CHROME", () => { - assert.equal(utils.getNormalizedBrowserName("chrome"), Browser.CHROME); - }); - - it("FIREFOX", () => { - assert.equal(utils.getNormalizedBrowserName("firefox"), Browser.FIREFOX); - }); - - it("EDGE", () => { - assert.equal(utils.getNormalizedBrowserName("edge"), Browser.EDGE); - assert.equal(utils.getNormalizedBrowserName("MicrosoftEdge"), Browser.EDGE); - assert.equal(utils.getNormalizedBrowserName("msedge"), Browser.EDGE); - }); - - it("SAFARI", () => { - assert.equal(utils.getNormalizedBrowserName("safari"), Browser.SAFARI); - }); - - it("null", () => { - const invalidValue = "unknown" as (typeof Browser)[keyof typeof Browser]; - - assert.equal(utils.getNormalizedBrowserName(invalidValue), null); - assert.equal(utils.getNormalizedBrowserName(), null); - }); - }); - it("createBrowserLabel", () => { assert.equal(utils.createBrowserLabel("browserName", "browserVersion"), "browserName@browserVersion"); }); diff --git a/test/src/utils/browser.ts b/test/src/utils/browser.ts index e0dff715f..6537a2a44 100644 --- a/test/src/utils/browser.ts +++ b/test/src/utils/browser.ts @@ -1,7 +1,35 @@ -import { isSupportIsolation } from "src/utils/browser"; +import { isSupportIsolation, getNormalizedBrowserName } from "src/utils/browser"; import { MIN_CHROME_VERSION_SUPPORT_ISOLATION } from "src/constants/browser"; +import { BrowserName } from "src/browser/types"; describe("browser-utils", () => { + describe("getNormalizedBrowserName", () => { + it("CHROME", () => { + assert.equal(getNormalizedBrowserName("chrome"), BrowserName.CHROME); + }); + + it("FIREFOX", () => { + assert.equal(getNormalizedBrowserName("firefox"), BrowserName.FIREFOX); + }); + + it("EDGE", () => { + assert.equal(getNormalizedBrowserName("edge"), BrowserName.EDGE); + assert.equal(getNormalizedBrowserName("MicrosoftEdge"), BrowserName.EDGE); + assert.equal(getNormalizedBrowserName("msedge"), BrowserName.EDGE); + }); + + it("SAFARI", () => { + assert.equal(getNormalizedBrowserName("safari"), BrowserName.SAFARI); + }); + + it("null", () => { + const invalidValue = "unknown" as (typeof BrowserName)[keyof typeof BrowserName]; + + assert.equal(getNormalizedBrowserName(invalidValue), null); + assert.equal(getNormalizedBrowserName(), null); + }); + }); + describe("isSupportIsolation", () => { describe("should return 'false' if", () => { it("specified browser is not chrome", () => {