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
|
The terminal benchmark script connects to an already-running dev server; it does
|
||||||
not start or stop services.
|
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
|
```bash
|
||||||
npm install
|
npm install
|
||||||
npx playwright install chromium
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run terminal:bench -- --url http://127.0.0.1:3100/rustui/terminal
|
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
|
It writes `target/terminal-bench/terminal-bench.json` plus screenshots when
|
||||||
Playwright is available in the workspace.
|
Playwright is available in the workspace.
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ export function parseArgs(argv) {
|
|||||||
viewports: [...DEFAULT_VIEWPORTS],
|
viewports: [...DEFAULT_VIEWPORTS],
|
||||||
timeoutMs: 120000,
|
timeoutMs: 120000,
|
||||||
screenshot: true,
|
screenshot: true,
|
||||||
|
browserChannel: process.env.PLAYWRIGHT_BROWSER_CHANNEL || "",
|
||||||
|
browserExecutable: process.env.PLAYWRIGHT_BROWSER_EXECUTABLE || "",
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let index = 0; index < argv.length; index += 1) {
|
for (let index = 0; index < argv.length; index += 1) {
|
||||||
@@ -44,6 +46,10 @@ export function parseArgs(argv) {
|
|||||||
options.timeoutMs = positiveInt(next(), "--timeout-ms");
|
options.timeoutMs = positiveInt(next(), "--timeout-ms");
|
||||||
} else if (arg === "--viewport") {
|
} else if (arg === "--viewport") {
|
||||||
options.viewports = [parseViewport(next())];
|
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") {
|
} else if (arg === "--no-screenshot") {
|
||||||
options.screenshot = false;
|
options.screenshot = false;
|
||||||
} else if (arg === "--help" || arg === "-h") {
|
} else if (arg === "--help" || arg === "-h") {
|
||||||
@@ -52,6 +58,9 @@ export function parseArgs(argv) {
|
|||||||
throw new Error(`Unknown argument: ${arg}`);
|
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;
|
return options;
|
||||||
}
|
}
|
||||||
@@ -133,7 +142,7 @@ async function main() {
|
|||||||
const { chromium } = await importPlaywright();
|
const { chromium } = await importPlaywright();
|
||||||
fs.mkdirSync(options.outputDir, { recursive: true });
|
fs.mkdirSync(options.outputDir, { recursive: true });
|
||||||
|
|
||||||
const browser = await chromium.launch();
|
const browser = await chromium.launch(browserLaunchOptions(options));
|
||||||
const results = [];
|
const results = [];
|
||||||
try {
|
try {
|
||||||
for (const viewport of options.viewports) {
|
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) {
|
export function pngSmokeFromBuffer(buffer) {
|
||||||
const signature = buffer.subarray(0, 8).toString("hex");
|
const signature = buffer.subarray(0, 8).toString("hex");
|
||||||
const isPng = signature === "89504e470d0a1a0a";
|
const isPng = signature === "89504e470d0a1a0a";
|
||||||
@@ -342,6 +361,8 @@ Options:
|
|||||||
--lines <n> Default: ${DEFAULT_LINES}
|
--lines <n> Default: ${DEFAULT_LINES}
|
||||||
--viewport <cols>x<rows> Run one scenario with inferred browser size
|
--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
|
--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
|
--timeout-ms <n> Default: 120000
|
||||||
--no-screenshot Skip screenshot capture
|
--no-screenshot Skip screenshot capture
|
||||||
--help Show this help
|
--help Show this help
|
||||||
|
|||||||
Reference in New Issue
Block a user