diff options
| author | Gabriel Schneider <[email protected]> | 2026-08-01 22:44:19 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-10 09:17:07 -0300 |
| commit | d59397d4146ffa23adbbe6dc99c64ebb22a93b2d (patch) | |
| tree | a06984bf172a6c894c1586d58aad02ec302b6c2d /test/web_snapshot.mjs | |
| parent | cbcdf01764e2e144a821643c3a8e9a5ad39eda2e (diff) | |
| download | pardes-d59397d4146ffa23adbbe6dc99c64ebb22a93b2d.tar.gz pardes-d59397d4146ffa23adbbe6dc99c64ebb22a93b2d.zip | |
add vanilla DOM web backend
Diffstat (limited to 'test/web_snapshot.mjs')
| -rw-r--r-- | test/web_snapshot.mjs | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/test/web_snapshot.mjs b/test/web_snapshot.mjs index 7c0c7462..4c50956e 100644 --- a/test/web_snapshot.mjs +++ b/test/web_snapshot.mjs @@ -1,5 +1,7 @@ #!/usr/bin/env node -// Drive the Emscripten build in a real headless Chromium using .snap scripts. +// Drive the freestanding WASM + DOM build in a real headless Chromium using +// .snap scripts. This is an end-to-end browser test: Chrome creates genuine +// touch events and the JS shell translates them into core events. // Shared commands retain test/snapshot.zig's spelling and output format: // wait <ms> <text> | stable <quiet-ms> <timeout-ms> // snap <label> | snapstyle <label> @@ -183,10 +185,7 @@ async function runScript(source) { } async function dispatchTouch(phase, id, col, row, active) { - const point = await evaluate(`({ - x: Module._pardes_web_test_cell_x(${JSON.stringify(col)}), - y: Module._pardes_web_test_cell_y(${JSON.stringify(row)}) - })`); + const point = await evaluate(`pardes.test.cellPoint(${JSON.stringify(col)}, ${JSON.stringify(row)})`); const touch = { x: point.x, y: point.y, id, radiusX: 1, radiusY: 1, force: 1 }; if (phase === "down") { if (active) throw new Error("only one finger is supported by this web test"); @@ -207,29 +206,24 @@ async function dispatchTouch(phase, id, col, row, active) { async function grid() { return evaluate(`(() => { - const cols = Module._pardes_web_test_cols(); - const rows = Module._pardes_web_test_rows(); + const frame = pardes.test.grid(); + const { cols, rows, cursorX, cursorY } = frame; const lines = []; const styleRows = []; for (let y = 0; y < rows; y++) { let line = ""; const styles = []; for (let x = 0; x < cols; x++) { - const cp = Module._pardes_web_test_cell(x, y) || 32; - line += String.fromCodePoint(cp); - styles.push([ - Module._pardes_web_test_cell_fg(x, y), - Module._pardes_web_test_cell_bg(x, y), - Module._pardes_web_test_cell_attrs(x, y), - ]); + const cell = frame.cells[y * cols + x]; + line += cell.text || " "; + styles.push([cell.fg, cell.bg, cell.attrs]); } lines.push(line.replace(/ +$/, "")); styleRows.push(styles); } return { cols, rows, lines, styleRows, - cursorX: Module._pardes_web_test_cursor_x(), - cursorY: Module._pardes_web_test_cursor_y(), + cursorX, cursorY, text: lines.join("\\n"), }; })()`); @@ -301,7 +295,14 @@ async function waitStable(quiet, timeout) { async function waitForRuntime(timeout) { await waitUntil(async () => { try { - return await evaluate(`typeof Module?._pardes_web_test_cols === "function" && Module._pardes_web_test_cols() > 0`); + return await evaluate(`(() => { + const app = globalThis.pardes; + if (!app?.test?.grid()?.cols || document.querySelector("canvas")) return false; + const want = app.runtime.gridSize(); + const frame = app.test.grid(); + return frame.cols === want.cols && frame.rows === want.rows && + document.querySelectorAll(".pardes-row").length === want.rows; + })()`); } catch { return false; } @@ -388,8 +389,10 @@ async function serveDirectory(root) { } const contents = await fsp.readFile(filename); const contentType = filename.endsWith(".wasm") ? "application/wasm" - : filename.endsWith(".js") ? "text/javascript; charset=utf-8" - : "text/html; charset=utf-8"; + : filename.endsWith(".js") || filename.endsWith(".mjs") ? "text/javascript; charset=utf-8" + : filename.endsWith(".css") ? "text/css; charset=utf-8" + : filename.endsWith(".ttf") ? "font/ttf" + : "text/html; charset=utf-8"; response.writeHead(200, { "content-type": contentType, "cache-control": "no-store" }); response.end(contents); } catch { |
