Render and test

The CLI runs a project with no device and no window, and tells you what is on the screen. That is the base of automated checks — and of working with a coding agent, which edits the code, renders it and reads the result itself.

See what the app shows: lecodes render

bash
lecodes render                       # the interface as JSON: structure, text, names, values
lecodes render --png shot.png        # the same frame as a picture
lecodes render src/screens/cart.ts   # one screen module, without starting the app

The JSON answers "is the button there, what does it say, is it disabled" without a picture. Name the elements you will look for:

TypeScript
const total = UIText('0 ₽').named('total')
UIScreen(total).named('cart').open()

Useful flags:

  • --clip <name> crops the PNG to one named element — a picture of one component.
  • --device iphone or --device android sets the safe areas; --width and --height set the viewport (390 × 844 by default).
  • --logs forwards the app's console.log lines.
  • --fixtures <file> answers the app's fetch calls from a file, so a screen behind a backend can be reached. Without --wait-network, a request gets an empty response.

UI and 2D are drawn. A 3D scene comes back as JSON with no pixels; for pixels use the desktop host, below.

Drive the app through steps: render --script

bash
lecodes render --script demo.flow.json --out-dir shots

A script is a JSON list of steps — tap, type, scroll, wait, press a key, run frames, take a screenshot — with the snapshot taken after them. It is the same format as a flow test, without the verdict.

Write a flow test

A flow test is a file tests/<name>.flow.json: steps, and what must be true after each.

JSON
{
  "name": "counter",
  "steps": [
    { "expect": { "screen": "home", "text": "Taps: 0" } },
    { "tap": "tap", "expect": { "text": "Taps: 1" } },
    { "tap": "tap", "expect": { "text": "Taps: 2" } }
  ]
}
  • A target ("tap": "tap") is the name of an element, given with .named(…).
  • expect.screen is the name of the screen on top; expect.text is a text on it; expect.log is a line the app printed with console.log — how a game checks what happened.
  • An expectation waits until it holds, up to its timeout (5 seconds by default).

lecodes init writes this test with the starter project, so there is a passing example from the first minute.

Run the tests: lecodes test

bash
lecodes test                 # every tests/*.flow.json, plus the flows derived from the design
lecodes test counter --logs  # one test, with the app's console output
lecodes test --json          # a machine-readable report, for CI

Time in a headless test is not the wall clock: timers, animations, 2D physics and the frame loop advance in fixed steps of 1/60 s that the test drives. A test that passes once passes every time.

A failing step saves the frame as JSON and PNG under tests/.artifacts/<test>/.

A project with server code gets its backend for the tests, on a database of its own that is emptied before every case. A flow file can also run several clients against it, call server functions directly and move the clock — lecodes test --help lists the step kinds.

When the project has a design board, test also derives flows from the board's screen-to-screen arrows and checks the built app against the designed navigation (le.codes Design).

Run the same tests on a real host

Headless is fast and has no pixels for 3D. The same test files run on the hosts that have them:

bash
lecodes test --desktop     # the native desktop host: the full engine
lecodes test --sim         # the same engine without a window or a GPU — for CI and containers
lecodes test --lite        # the project as a web page, in a browser
lecodes test --web         # the web player, in a browser
lecodes test --android     # the le.codes app on a phone over USB
lecodes test --ios         # the le.codes app on a booted iOS simulator

--lite and --web need Playwright. On a browser or a phone the clock is the device's own, so a step that expects a log line waits for it.

lecodes render --desktop --png shot.png is the picture of a 3D scene; --view iso (or top, front, side, back) looks at the whole scene from an inspection camera without touching the app's own.

One action on a running device: lecodes drive

While lecodes dev --android or lecodes dev --ios has the app open, drive does one step in it, and the app keeps its state between two of them:

bash
lecodes drive names                          # what is on the screen: named elements, text, boxes
lecodes drive tap login
lecodes drive type email user@example.com
lecodes drive scroll 400 feed
lecodes drive shot screen.png

Next