test(terminal): support local browser bench runs

This commit is contained in:
zhangheng
2026-06-24 14:48:32 +08:00
parent 21019d82e0
commit a10c638e60
2 changed files with 30 additions and 3 deletions

View File

@@ -22,6 +22,8 @@ export function parseArgs(argv) {
viewports: [...DEFAULT_VIEWPORTS],
timeoutMs: 120000,
screenshot: true,
browserChannel: process.env.PLAYWRIGHT_BROWSER_CHANNEL || "",
browserExecutable: process.env.PLAYWRIGHT_BROWSER_EXECUTABLE || "",
};
for (let index = 0; index < argv.length; index += 1) {
@@ -44,6 +46,10 @@ export function parseArgs(argv) {
options.timeoutMs = positiveInt(next(), "--timeout-ms");
} else if (arg === "--viewport") {
options.viewports = [parseViewport(next())];
} else if (arg === "--browser-channel") {
options.browserChannel = next();
} else if (arg === "--browser-executable") {
options.browserExecutable = next();
} else if (arg === "--no-screenshot") {
options.screenshot = false;
} else if (arg === "--help" || arg === "-h") {
@@ -52,6 +58,9 @@ export function parseArgs(argv) {
throw new Error(`Unknown argument: ${arg}`);
}
}
if (options.browserChannel && options.browserExecutable) {
throw new Error("Use only one of --browser-channel or --browser-executable");
}
return options;
}
@@ -133,7 +142,7 @@ async function main() {
const { chromium } = await importPlaywright();
fs.mkdirSync(options.outputDir, { recursive: true });
const browser = await chromium.launch();
const browser = await chromium.launch(browserLaunchOptions(options));
const results = [];
try {
for (const viewport of options.viewports) {
@@ -253,6 +262,16 @@ async function runScenario(browser, options, viewport) {
}
}
function browserLaunchOptions(options) {
if (options.browserChannel) {
return { channel: options.browserChannel };
}
if (options.browserExecutable) {
return { executablePath: options.browserExecutable };
}
return {};
}
export function pngSmokeFromBuffer(buffer) {
const signature = buffer.subarray(0, 8).toString("hex");
const isPng = signature === "89504e470d0a1a0a";
@@ -342,6 +361,8 @@ Options:
--lines <n> Default: ${DEFAULT_LINES}
--viewport <cols>x<rows> Run one scenario with inferred browser size
--viewport <c>x<r>:<w>x<h> Run one scenario with explicit browser size
--browser-channel <name> Use an installed browser channel, e.g. chrome
--browser-executable <path> Use a local Chromium/Chrome executable path
--timeout-ms <n> Default: 120000
--no-screenshot Skip screenshot capture
--help Show this help