test(terminal): support local browser bench runs
This commit is contained in:
10
README.md
10
README.md
@@ -21,16 +21,22 @@ Change `app_config/src/lib.rs` to test another base path.
|
||||
The terminal benchmark script connects to an already-running dev server; it does
|
||||
not start or stop services.
|
||||
|
||||
Install the Node dependency and Chromium browser once before running it:
|
||||
Install the Node dependency once before running it:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npx playwright install chromium
|
||||
```
|
||||
|
||||
```bash
|
||||
npm run terminal:bench -- --url http://127.0.0.1:3100/rustui/terminal
|
||||
```
|
||||
|
||||
If Playwright's browser download is slow, use an installed Chrome/Chromium
|
||||
instead:
|
||||
|
||||
```bash
|
||||
npm run terminal:bench -- --url http://127.0.0.1:3100/rustui/terminal --browser-executable /usr/bin/google-chrome
|
||||
```
|
||||
|
||||
It writes `target/terminal-bench/terminal-bench.json` plus screenshots when
|
||||
Playwright is available in the workspace.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user