Examples
Examples
Section titled “Examples”Test a cartridge headlessly
Section titled “Test a cartridge headlessly”vishnu test runs files like this one against the pinned kernel. Inside a
project, import from vishnu/testing and vishnu/library.
import test from "node:test";import { testWorld } from "@fungi.computer/vishnu/testing";import { tree } from "@fungi.computer/vishnu/library";import type { Cartridge } from "@fungi.computer/vishnu";
declare const game: Cartridge;
test("the first tree stands at the origin", () => { const world = testWorld(game); try { world.step(1); const trees = world.find(tree); if (!trees.some((at) => at.x === 0 && at.z === 0)) throw new Error("no tree at the origin"); } finally { world.dispose(); }});A test world runs player commands through the same boundary as the page
(world.command), steps simulated time at 30 Hz (world.step), waits for a
condition with a clear failure message (world.until), and can save and reopen
a world (world.save, testWorld(cartridge, { snapshot })).
Play a build
Section titled “Play a build”vishnu buildnpx --yes http-server@14.1.1 dist -p 8080Open http://127.0.0.1:8080/ and click the world once so it has keyboard focus.
The build is a static site: index.html, the bundled cartridge, its metadata
and the kernel. Host it on any static file server.