Assertions (q)
@quameleon/qa-host connects to an app in QA mode and exposes q, a set of assertions over the signal stream.
npm i -D @quameleon/qa-hostimport { QuameleonHost, android } from "@quameleon/qa-host";
await android.forward(serial, 47321, 47321); // iOS simulator: not neededconst host = await QuameleonHost.connect({ port: 47321, token });const { q } = host;
await q.action("place-order", () => tap("checkout.place")); // stamps every signal with this stepawait q.network("POST /api/order").toSucceed();await q.event("order.confirmed", { items: 1 }).toHaveOccurred({ action: "place-order" });await q.screen("order.confirmed").toBeCurrent();await q.probe("cart.count").toEqual(0);await q.ui("order.banner").toBeVisible(); // from the live view hierarchyawait q.idle(); // no frames, main-thread work or requests in flightawait q.action("place-order").settledWithin(1000);q.noCrash(); q.noHangs(); q.noErrors(); q.noLeaks(); q.noBlankScreens();token is the per-run token you launched the app with. quameleon-qa record and QualGent runners generate it for
you; in your own harness, generate at least 16 random characters per run.
| Call | What it does |
|---|---|
q.action(id, fn) |
sends action.begin, runs fn, sends action.end, waits for a barrier, and returns the signals stamped with id |
q.action(id).settledWithin(ms) |
waits for that step’s action_latency and checks settled_ms ≤ ms |
q.idle({ timeoutMs }) |
waits until the app is idle: main thread responsive, no frame in 300 ms, no request in flight. On timeout the error names the blocker, for example animating: UISDFElementView or 2 request(s) in flight |
Waiting matchers
Section titled “Waiting matchers”All take { timeoutMs, afterSeq } and resolve with the matching signal.
| Matcher | Passes when |
|---|---|
q.event(name, where?).toHaveOccurred({ action? }) |
an event with that name (and props) arrives, optionally stamped with action |
q.network(matcher).toSucceed() |
a matching request completes with status 200 to 399. matcher is "POST /path", a RegExp or { method, path } |
q.network(matcher).toHaveStatus(code) |
a matching request completes with that status |
q.screen(name).toBeCurrent() |
the current screen is name |
q.probe(name).toEqual(value) |
the probe returns value (retried until the timeout) |
q.ui(target).toBeVisible() |
a node with that test id or label is visible in the hierarchy |
q.ui(target).toHaveLabel(text) |
the node’s label is text |
q.launch("cold" | "hot").toBeUnder(ms) |
the launch signal’s duration_ms is under ms |
q.span(name).toHaveCompleted({ status? }) |
a span with that name ends, optionally with ok or error |
q.hang().toHaveOccurred() |
a main-thread hang is reported |
q.push(name?).toHaveOccurred() |
a push received or opened signal arrives |
Checks over what was recorded
Section titled “Checks over what was recorded”These are synchronous and take { since } (a seq):
| Check | Fails on |
|---|---|
q.noErrors() |
any error signal |
q.noCrash() |
any crash signal |
q.noHangs() |
any hang signal |
q.noExits({ ignore }) |
an abnormal previous-run exit (by default user_requested and exit_self are ignored) |
q.noLeaks() |
a leak signal (Android) |
q.noBlankScreens() |
a blank_screen finding (enable with blankScreenMs on connect) |
q.sdkHealthy() |
an sdk_error signal |
q.vitals() |
returns a summary (CPU, memory, slow and frozen frames) to assert on |
q.snapshot(name) |
the normalized signal stream differs from __qa_snapshots__/<name>.ndjson (QUAMELEON_UPDATE_SNAPSHOTS=1 accepts) |
Failure messages
Section titled “Failure messages”Every failure says what was expected and what was seen instead, for example the ids and labels on screen when a
q.ui lookup fails, or what the app was busy with when q.idle() times out, so a CI log is usually enough to tell a
real bug from a flaky test.