Expand description
cargo xtask test-wasm: run the GPU tests in a real browser.
The tests themselves are the same files cargo nextest runs natively — see
unlit_wgpu_test_util’s registry — but built for wasm32-unknown-unknown
and driven from a page. The pieces are:
- The wasm test binaries, built by
cargo nextest listso that the same target list, features and names are used as natively. wasm-bindgen, which turns each into a JS module exportingrun_test.- The test page, which loads one module and calls that export.
- A Playwright runner, which opens the page once per test.
- The same native test binaries, with
UNLIT3D_WASM_TESTset, which turns them into a proxy:cargo nextestdrives them, and each trial asks the runner to run that test in the browser. Nextest’s listing, filtering and exit code then all work as they do for an ordinary test suite.
Steps 1-4 set up the browser; step 5 is the part nextest actually runs.
Re-exports§
use std::net::TcpStream;🔒use std::path::Path;🔒use std::path::PathBuf;🔒use std::process::Child;🔒use std::process::Command;🔒use std::process::Stdio;🔒use std::time::Duration;🔒use std::time::Instant;🔒use crate::TestWasmArgs;🔒use crate::step;🔒
Structs§
- Runner 🔒
- The Playwright runner, stopped when the run is over.
Constants§
- BASE_
URL 🔒 - The runner’s own address.
- DIST 🔒
- Where the page, the built modules and
wasm_paths.jsonare assembled. - EXAMPLE_
DIST 🔒 - Where the built examples are assembled for the runner to serve.
- MISMATCH_
DIR 🔒 - Where this pass collects the frames that failed their comparison.
- MISMATCH_
DIR_ 🔒ENV - The environment variable that collects mismatched snapshot frames.
- PACKAGES 🔒
- The packages whose tests can run in a browser.
- PORT 🔒
- The port the runner listens on; also fixed in the harness’s proxy.
- RUNNER 🔒
- The Playwright runner, which serves
DISTand drives a browser. - SHUTDOWN_
TIMEOUT 🔒 - How long the runner is given to close its browser and exit.
- STARTUP_
TIMEOUT 🔒 - How long the runner is given to start listening.
- TARGET 🔒
- The target the tests are built for.
- WASM_
TEST_ 🔒ENV - The environment variable that puts a test binary in proxy mode.
- WEB 🔒
- The page the runner serves, copied into
DISTas-is.
Functions§
- build_
wasm_ 🔒tests - Build every wasm test binary, bindgen it, and return the module names.
- build_
workspace 🔒 - Build every wasm target in the workspace, not just the test binaries.
- check_
example 🔒 - Ask the runner to load one example and confirm it drew something.
- check_
examples 🔒 - Ask the runner to load each example and confirm it drew something.
- check_
wasm_ 🔒bindgen - Reject a
wasm-bindgenwhose version differs from the library’s. - copy_
example 🔒 - Copy one built example into the runner’s tree.
- copy_
examples 🔒 - Build every example the site shows and copy it where the runner serves it.
- install_
runner 🔒 - Install the runner’s JS dependencies, and a browser to drive.
- parse_
binaries 🔒 - The module name and wasm path of each test binary, from nextest’s JSON.
- pnpm 🔒
- The
pnpmto run, which ispnpm.cmdon Windows. - print_
browser_ 🔒gpu - Print the device the browser draws with, as the page describes it.
- resolved_
wasm_ 🔒bindgen - The
wasm-bindgenversion the workspace resolves, fromcargo metadata. - run
- Run the GPU tests in a browser.
- run_
through_ 🔒nextest - Run the tests through the proxy, so nextest reports the browser’s results.
- write_
page 🔒 - Copy the page into the served directory and write the module map.