Skip to main content

Module test_wasm

Module test_wasm 

Source
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:

  1. The wasm test binaries, built by cargo nextest list so that the same target list, features and names are used as natively.
  2. wasm-bindgen, which turns each into a JS module exporting run_test.
  3. The test page, which loads one module and calls that export.
  4. A Playwright runner, which opens the page once per test.
  5. The same native test binaries, with UNLIT3D_WASM_TEST set, which turns them into a proxy: cargo nextest drives 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.json are 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 DIST and 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 DIST as-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-bindgen whose 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 pnpm to run, which is pnpm.cmd on Windows.
print_browser_gpu 🔒
Print the device the browser draws with, as the page describes it.
resolved_wasm_bindgen 🔒
The wasm-bindgen version the workspace resolves, from cargo 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.