Skip to content
Work in progress. These docs describe Spawnite at launch, and some parts are still being built.

The boot smoke

@spawnite/testing/e2e is a game’s one Playwright check: its built bundle boots in a real browser. A game’s playwright.config.ts names a preview port no other game uses:

import { defineGameConfig } from "@spawnite/testing/e2e";
export default defineGameConfig({ port: 4177 });

The config builds the game, serves the bundle with vite preview, and opens it in full Chromium in its headless mode, one browser at a time, with the report and traces under .work/. Chromium is asked for the GPU, so it draws WebGL on the card where one answers and on SwiftShader, the CPU, where none does. It returns a plain Playwright config, so a game overrides a field by spreading it.

To boot the dev server instead of the built bundle, set E2E_DEV: the config starts vite on the port a hundred above the preview’s. Where another checkout’s check already holds the port, the config takes a free one, so two checkouts run the same game’s check at once. E2E_PORT names the port for either server.

To boot the game in other browsers, set E2E_BROWSERS to a comma-separated list of chromium, firefox and webkit: the config adds a headless Playwright project for each, and --project <name> runs one of them.

test/e2e/boot.spec.ts calls bootSmoke, which opens the page, waits for a canvas to show, runs the game’s own steps, and fails on any uncaught error or console error the page reported meanwhile:

import { expect, test } from "@playwright/test";
import { bootSmoke } from "@spawnite/testing/e2e";
test("the app boots, Play starts the run, and the page reports no error", async ({
page,
}) => {
await bootSmoke(page, {
steps: async () => {
await page.getByRole("button", { name: "Play" }).click();
await expect(page.getByText("WASD walks")).toBeVisible();
},
});
});

path opens another address, such as /?quality=minimum, and timeout changes the canvas’s 30 seconds. A check that opens several pages, such as two players in one room, calls watchErrors(page) on each and asserts the list it returns is empty.

A room game’s page shows nothing to check until it joins a room, so its smoke starts one first. startRoom(gameFolder) starts the scene and the settings the game’s package.json names under spawnite.room, in the @spawnite/room the game installed. The room listens on a port the system picks, so two checkouts’ rooms never share one. Build the room before the run: startRoom refuses a room with no build and names the command.

The call resolves once the room listens. The page dials the url it returns, and stop ends the room once the run is over:

games/economy/test/e2e/boot.spec.ts
import * as path from "node:path";
import { expect as playwrightExpect, test } from "@playwright/test";
import {
bootSmoke,
startRoom,
type StartRoomResult,
} from "@spawnite/testing/e2e";
// The town's page joins its room, which gives the player their materials,
// and reports no error. A mount takes ten to twenty seconds where Chromium
// falls back to SwiftShader, on a machine with no GPU.
const expect = playwrightExpect.configure({ timeout: 60_000 });
const gameFolder = path.resolve(import.meta.dirname, "../..");
let room: StartRoomResult | undefined;
// The room's built entry, which the e2e target's dependencies build.
test.beforeAll(async () => {
room = await startRoom(gameFolder);
});
test.afterAll(() => room?.stop());
test("the page joins the town's room and shows the player's materials", async ({
page,
}) => {
test.setTimeout(180_000);
await bootSmoke(page, {
path: `/?room=${room?.url}&name=Ada&quality=minimum`,
timeout: 60_000,
steps: async () => {
// The player's record in the development room's saves, from
// any earlier run, or a new player's.
await expect(page.getByText(/^Wood \d+, seeds \d+/)).toBeVisible();
},
});
});

lines holds each line the room has logged, parsed, so a check reads what the room saw, such as a joined line for each player. A check that waits on the room or on another page waits on that state, never on a delay: a loaded machine draws a page’s frame seconds late, and a key held for a fixed time can go up before the page sends it.

@playwright/test is an optional peer, needed only for this entry. A game’s e2e run opens Playwright’s Chromium, so install it once with pnpm exec playwright install chromium, and firefox and webkit beside it for the other two.

spawnite play run makes the same check while you build, with no Playwright config: it opens the game’s dev page headless, with nothing holding its world, as a player opens it. Run it in the game’s folder, and name each control a player clicks to start:

Terminal window
pnpm spawnite play run --click Play --seconds 10

It waits until a canvas shows and the loading screen has lifted, --boot-seconds at most, 90 by default. It clicks each --click in turn, then lets the page run on its own frame loop for --seconds, 10 by default. It prints each uncaught error and console error with its seconds and the first lines of its stack, the engine’s frame loop as last read and as read before the first error, and a shot. --json carries the whole stack and the engine’s whole state.

The command exits 1 on any of the following:

  • An uncaught error or a console error, or the page’s crash.
  • A --press the page refuses.
  • A page that did not boot within --boot-seconds, or whose loading screen shows its failure.
  • A --click that found nothing, named with the controls the page shows.
  • A frame loop that stopped, or a reload after the page booted.
  • A page that stops answering for 5 s, or a read of it that fails.

Use it where spawnite play start cannot see a bug. A play start session opens the page held and steps its world on demand, so the world registers its parts in another order than a player’s page does, and a fault in that order shows only on a free page. A headless test steps the scene in Node, with no page at all.

A run also lists each task that held the page’s main thread past 50 ms from the first click on, longest first: a player feels a long one as a page that stops answering, such as a scene that mounts after a menu’s button. --cpu samples V8’s profiler from the first click and names what ran in each of the six longest, each line a function and the two that called it. --viewport 1920x1080 sizes the page as a desktop player’s screen. --build builds the game minified, as a player gets it, so its functions read as short names. To name source files instead, build without minifying and with source maps, serve that build, and give its address with --url:

Terminal window
pnpm exec vite build --minify false --sourcemap
pnpm exec vite preview --port 4173
pnpm spawnite play run --url http://localhost:4173/ --click Play --viewport 1920x1080 --cpu

Run the preview in a second terminal, and stop it after the run.

--press KeyW@0-2 holds a control from the last click, as play join takes it. --build builds the game and serves its build instead of its dev page. A built page exposes no engine state unless --query profile asks, which pins the seed and keeps no save. --url opens a page already served, and starts no server and no room. A room game’s own room starts on a free port, and the page dials it. Two runs at once take ports of their own.