@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?)
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.
.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:Backdoors
quiesco.backdoor(name, fn)
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.
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.
name as keyof Backdoors:
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, theonReset 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)
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 })
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.
RESET_FAILED at step storage:<name>.
Navigation on soft reset
With Expo Router, the soft reset also puts the navigation state back to the one the app started in (after theonReset 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()
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.
quiesco.workerIndex()
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.
({ workerIndex }) => ({ launchArgs: { … } }) (a config per worker).