The page's reader: a Web Worker with a second instance of the program reads a database (PGN, CBV, ZIP, 7Z) and gives back its text and index; the page puts it together without reading it again (chess_core::PgnIndex, PgnDatabase::into_index / from_index, serde behind a feature). A 13 MB CBV: the longest frame 17 ms in Firefox, 67 ms in Chromium (1000 ms before). platform::open_database is the same on both sides: away from the screen, done when read. The shelf's cards count the games the same way (one file at a time); the counts are kept through platform::fs. Chrome, Edge (File System Access): a chosen file's handle is kept in the browser's storage; at the next visit the file is read again by itself when the browser allows it, else the card offers «Allow reading» (the browser's own question). Files of different visits get folders of their own. Checks: t.choose(files, open) for both browsers (in Chromium the handles of the site's private file system stand for the dialog's); app.mjs checks the draft, the question on leaving and the remembered file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
2.7 KiB
JavaScript
64 lines
2.7 KiB
JavaScript
// A session of the web version in a headless browser (browser.mjs: Firefox, or
|
|
// Chromium with CP_BROWSER=chromium) over the site's layout (serve.py), and a runner of
|
|
// step lists — for finding the places of buttons, and for the scenario checks.
|
|
//
|
|
// node apps/web/check/steps.mjs <app-dir> <out-dir> <steps.json>
|
|
//
|
|
// A step: {"url": "?lang=en"} | {"wait": ms} | {"click": [x, y], "double": true}
|
|
// | {"key": "l", "mods": ["ctrl"], "times": 3} | {"shot": "name.png"} | {"eval": "js"}
|
|
// | {"until": "js expression", "ms": 60000}
|
|
import { spawn } from 'node:child_process';
|
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
import { join, resolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { open } from './browser.mjs';
|
|
import { sleep } from './bidi.mjs';
|
|
|
|
export async function session(appDir, port = Number(process.env.CP_CHECK_PORT || 18767)) {
|
|
const root = fileURLToPath(new URL('../../..', import.meta.url));
|
|
const server = spawn('python3', ['-I', join(root, 'apps/web/check/serve.py'), resolve(appDir), join(root, 'website/static'), String(port)], { stdio: 'ignore' });
|
|
const b = await open(port + 457);
|
|
const errors = [];
|
|
const logs = [];
|
|
const t = await b.tab(1400, 860, (line) => {
|
|
logs.push(line);
|
|
if (/panicked|RuntimeError|\[error\]/.test(line) && !/favicon|404/.test(line)) errors.push(line);
|
|
if (process.env.CONSOLE) console.log(line);
|
|
});
|
|
const base = `http://127.0.0.1:${port}/app/`;
|
|
const run = async (step, outDir) => {
|
|
if (step.url !== undefined) {
|
|
await t.navigate(base + step.url);
|
|
await t.waitFor(`document.getElementById('cp-status').hidden || !document.getElementById('cp-device').hidden`, 30000);
|
|
}
|
|
if (step.wait) await sleep(step.wait);
|
|
if (step.click) {
|
|
await t.click(step.click[0], step.click[1], step);
|
|
await sleep(300);
|
|
}
|
|
if (step.key) {
|
|
await t.key(step.key, step.mods || [], step.times || 1);
|
|
await sleep(300);
|
|
}
|
|
if (step.eval) console.log('eval:', JSON.stringify(await t.evaluate(step.eval)).slice(0, 2000));
|
|
if (step.until) await t.waitFor(step.until, step.ms || 60000);
|
|
if (step.shot) writeFileSync(join(outDir, step.shot), await t.screenshot());
|
|
};
|
|
return {
|
|
t, b, base, errors, logs, run,
|
|
stop: async () => { await b.stop(); server.kill(); },
|
|
};
|
|
}
|
|
|
|
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
const [appDir, outDir, stepsFile] = process.argv.slice(2);
|
|
mkdirSync(outDir, { recursive: true });
|
|
const steps = JSON.parse(readFileSync(stepsFile, 'utf8'));
|
|
const s = await session(appDir);
|
|
try {
|
|
for (const step of steps) await s.run(step, outDir);
|
|
} finally {
|
|
await s.stop();
|
|
}
|
|
for (const e of s.errors) console.log('console:', e);
|
|
}
|