Skip to main content
Most of Quiesco runs in the test, but a small part runs inside the app: the agent (@quiesco/agent). It finds elements, tracks when the app is idle and resets it between tests. Through it the app can also give tests shortcuts: backdoors for setup, hooks that clear its state, and the arguments it was launched with. The samples on this page are app code, not test code.

Setup

QuiescoRoot

The app imports the agent on the first line of its entry file and wraps its root in <QuiescoRoot>. npx quiesco init sets both up. Element queries only see what is inside <QuiescoRoot>, and a soft reset remounts everything under it.

withQuiesco(config, options?)

Types: WithQuiescoOptions Wraps the Metro config (from @quiesco/agent/metro). In builds without EXPO_PUBLIC_QUIESCO=1 it replaces the agent with a no-op stub, so this page’s code can stay in the app: production bundles get none of it.
It also keeps Metro from watching the artifacts directory. Metro sends the app an HMR update for every watched file that changes, and the dev client’s “Refreshing…” window would cover the app while another worker taps (parallel runs). .expo/devices.json is excluded too: Expo’s dev server rewrites it every time a dev client app starts.

Keeping test code out of production

Register backdoors and hooks in a module that only e2e builds import, so the test code is not even in production bundles:
Every registration below returns a function that removes it.

Backdoors

quiesco.backdoor(name, fn)

Types: Backdoor Registers a test-only function the test can call with app.backdoor(name, ...args), to set up state without going through the UI. fn may be async. Its arguments and result must be JSON. Registering the same name again replaces it.
In the test:

Typed backdoors

Declare the backdoors once, in a file both the app and the tests compile, and both sides are checked against it: quiesco.backdoor(name, fn) only takes declared names with a matching function (async or not), and app.backdoor(name, ...args) checks the name, the arguments and the result (null for a backdoor that returns nothing). Without a declaration, any name works and the arguments only need to be JSON-compatible.
A name that is only known at run time (e.g. from a feature file’s text) is narrowed with name as keyof Backdoors:
When the tests’ tsconfig does not include the file, bring it in with a type-only import:
A plain import '../../src/backdoors' fails when cucumber-js runs the steps: Node needs the file extension, and the file holds only types.

Reset

Before each test the app gets a soft reset: its storage is cleared, the onReset hooks run, the navigation goes back to the start, and everything under <QuiescoRoot> is remounted. A test tagged @hard-reset relaunches the app instead.

quiesco.onReset(hook)

Runs hook during every soft reset, after storage is cleared and before the app is remounted. Use it for state that lives in memory, outside React: caches, stores, a mock backend.

quiesco.registerStorage({ name, clear })

Types: StorageAdapter Adds a store for the soft reset to clear, next to the built-in ones: AsyncStorage’s default store on iOS / Android; localStorage, sessionStorage and IndexedDB on the web. clear may be async.
A store that fails to clear fails the reset with RESET_FAILED at step storage:<name>. With Expo Router, the soft reset also puts the navigation state back to the one the app started in (after the onReset hooks, before the remount). A test that ends on a pushed screen, in a tab or in a nested stack no longer hands that screen to the next one. There is nothing to set up. The reset then checks that the app is on the route the first reset of the run ended on. When it is not (the app navigated away on mount, from state the reset did not clear), the reset fails with RESET_FAILED naming both routes. Clear that state in onReset, or tag the test @hard-reset. For apps without Expo Router, reset.expectVisible in the config does the same check with an element.

Launch and worker

quiesco.launchArgs()

Types: JsonValue Returns the arguments of this launch: the config’s launchArgs merged with app.device.relaunch({ args }), with their JSON types. It is synchronous, so the app can read it at startup. It returns {} when there are none, in production, and in builds without @quiesco/native on iOS / Android.
In the test:

quiesco.workerIndex()

The index of the parallel test worker driving this app: 0 when tests run serially, null until the test host has connected (it connects before the first test command) and in production. Use it to talk to that worker’s own resources, such as a mock backend per worker.
It is not known yet while the app starts. For what the app needs at startup (an API URL), pass launch arguments instead: the config can be a function of the worker index, ({ workerIndex }) => ({ launchArgs: { … } }) (a config per worker).