Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for selecting the browser to update #271

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/replay/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
launchBrowser,
} from "./main";
import {
BrowserName,
FilterOptions,
MetadataOptions,
Options,
Expand Down Expand Up @@ -110,6 +111,7 @@ commandWithGlobalOptions("rm-all")

commandWithGlobalOptions("update-browsers")
.description("Update browsers used in automation.")
.arguments("<browsers...>")
.action(commandUpdateBrowsers);

commandWithGlobalOptions("upload-sourcemaps")
Expand Down Expand Up @@ -302,11 +304,14 @@ function commandRemoveAllRecordings(opts: Pick<CommandLineOptions, "directory" |
}
}

async function commandUpdateBrowsers(opts: Pick<CommandLineOptions, "directory" | "warn">) {
async function commandUpdateBrowsers(
browsers: string[],
opts: Pick<CommandLineOptions, "directory" | "warn">
) {
try {
debug("Options", opts);

await updateBrowsers({ ...opts, verbose: true });
await updateBrowsers({ ...opts, browsers: browsers.map(fuzzyBrowserName), verbose: true });
process.exit(0);
} catch (e) {
console.error("Failed to updated browsers");
Expand Down
10 changes: 8 additions & 2 deletions packages/replay/src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,14 @@ function ensurePuppeteerBrowsersInstalled(kind: BrowserName | "all" = "all", opt
return ensureBrowsersInstalled("chromium", false, opts);
}

function updateBrowsers(opts: Options) {
return ensureBrowsersInstalled("all", true, opts);
async function updateBrowsers(opts: Options & { browsers?: BrowserName[] }) {
if (opts.browsers) {
for (const browserName of opts.browsers) {
await ensureBrowsersInstalled(browserName, true, opts);
}
} else {
return ensureBrowsersInstalled("all", true, opts);
}
}

function getPlatformKey(browserName: BrowserName): PlatformKeys | undefined {
Expand Down
4 changes: 2 additions & 2 deletions packages/replay/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export async function exponentialBackoffRetry<T>(
throw Error("ShouldBeUnreachable");
}

function fuzzyBrowserName(browser?: string) {
function fuzzyBrowserName(browser?: string): BrowserName {
browser = browser?.toLowerCase();

switch (browser) {
Expand All @@ -104,7 +104,7 @@ function fuzzyBrowserName(browser?: string) {
return "firefox";
}

return browser;
return browser as BrowserName;
}

function assertValidBrowserName(browser?: string): asserts browser is BrowserName {
Expand Down
Loading