In-app SDK
The SDK is an optional library inside the app under test. toets works black-box without it; with it, tests get a uniform element tree, idle sync (no polling sleeps), media state, app state launch and app logs. Apps with a JS focus engine need it: their focus lives in app state, and only the app can report it (focus.md).
@toets/sdk: the framework-neutral runtime and the app-facing API below.@toets/sdk/web: web adapter (web.md).@toets/sdk-react-native: React Native adapter (its own docs).
The SDK packages, and @toets/protocol they depend on, are app dependencies: they install with Node 18 and later (engines), so apps whose toolchain is pinned to an older Node than the test runner's can depend on them. @toets/test and the drivers need Node 24.
Lifecycle
The adapter's startToets() looks for the launch payload. Without one (a normal run, production) the SDK is inert: no hooks, no connection. With one it instruments the app (network, timers, console), connects to the host at sdkUrl and announces its domains. When the session ends every hook is removed.
App-facing API
Safe to call unconditionally, before or without the SDK running:
import { getLaunchPayload, markBusy, onState } from '@toets/sdk';
onState(async (state, flags) => {
if (state === 'logged-in') await session.loginAsTestUser();
});
const done = markBusy('hero video decode');
await player.ready();
done();
const mockUrl = getLaunchPayload()?.mockUrl; // route API calls through it, see @toets/mock app-integration| Function | Purpose |
|---|---|
onState(handler) | Launch into a named state, apply flags (state.md). |
markBusy(description) | Work the SDK cannot see (idle.md). |
registerMedia / createMediaReporter | Players (media.md). |
reportFocus(element) | JS focus engines: what holds focus (focus.md). |
getLaunchPayload() | The launch payload (mockUrl, state, flags) or null. |
getToets() | The running runtime (status, domains) or null. |
getToets() is null in black-box runs (toets launched the app without the SDK session), while getLaunchPayload() still carries the mockUrl: route API traffic with it so mocking works with and without the SDK.
Related: production.md (excluding the SDK), adapters.md (new frameworks), traps.md.