Testing
Four layers, each optional:
| Layer | Tool | Covers |
|---|---|---|
| Static checks | tynd validate, tsc, your linter |
Config, build inputs, types |
| Unit tests | bun test |
Backend logic kept free of host side effects |
| Frontend unit tests | bun test + installTyndMock from @tynd/core/testing |
Frontend code that calls the backend or plugins, without a host |
| End-to-end | @tynd/test + tynd test |
The real app: windows, DOM, IPC, screenshots |
Tynd checks
Section titled “Tynd checks”tynd infotynd validatetynd validate --citynd doctortynd buildvalidate: config/backend/frontend/package presence.validate --ci: also requires Bun pin and resolves Bun, native host, and bundler.doctor: focused project/native binary checks with optional repair/state reporting.build: authoritative frontend/backend/host/packaging execution.
These commands do not run your TypeScript typechecker, linter, or application tests. Add bunx tsc --noEmit and your own linter as you would in any project.
Unit tests for backend logic
Section titled “Unit tests for backend logic”Backend RPC functions are normal typed functions. Keep business logic outside host and window side effects and test it with bun test:
import { expect, test } from "bun:test";import { total } from "./pricing";
test("applies the discount", () => { expect(total([10, 20], 0.1)).toBe(27);});Test the RPC boundary (serialization, thrown errors) as plain function calls rather than reproducing Tynd internals.
Unit tests for frontend code
Section titled “Unit tests for frontend code”installTyndMock() from @tynd/core/testing replaces the IPC bridge with an in-memory one, so frontend modules that use createBackend or plugin clients run under bun test without a host:
import { afterEach, expect, test } from "bun:test";import { installTyndMock, type TyndMock } from "@tynd/core/testing";import { createBackend } from "@tynd/core/client";import { dialog } from "@tynd/plugin-dialog/client";import type * as backend from "../backend/main";
let mock: TyndMock;afterEach(() => mock.restore());
test("opens the picked file", async () => { mock = installTyndMock({ backend: { greet: (name) => `Hello ${name}` }, os: { "dialog.openFile": () => "/tmp/a.txt" }, }); const api = createBackend<typeof backend>(); expect(await api.greet("Ada")).toBe("Hello Ada"); expect(await dialog.openFile()).toBe("/tmp/a.txt"); expect(mock.calls.map((c) => c.kind)).toEqual(["backend", "os"]);});backendhandlers are keyed by function name;oshandlers by"api.method". An OS call with no handler rejects unlessosFallbackanswers it (for exampleosFallback: () => nullto accept every call and assert oncallsonly).binaryhandlestynd-bin://requests;windowLabelsets the current window label.- The returned mock records every call in
callsand offersemit/emitOs(fire backend or OS events),setBackend/setOs,clear()andrestore(). Callrestore()after each test.
End-to-end tests with @tynd/test
Section titled “End-to-end tests with @tynd/test”@tynd/test launches your app with tynd dev (debug socket on), drives the webview over the Tynd debug protocol, and plugs into bun test. It has no runtime dependencies and needs Bun.
bun add -d @tynd/testimport { afterAll, beforeAll, expect, test } from "bun:test";import { launchApp, type TyndApp } from "@tynd/test";
let app: TyndApp;beforeAll(async () => { app = await launchApp(); // cwd: TYND_TEST_PROJECT, then process.cwd()});afterAll(() => app.close());
test("greets the user", async () => { await app.fill([{ selector: "#name", value: "Ada" }]); await app.click("button[type=submit]"); await app.waitFor(async () => (await app.eval<string>("document.title")) === "Hello Ada");});Run it with the CLI, which finds the project root and prepares the environment:
tynd test # all tests, 180 s per testtynd test e2e/greeting.test.ts # a file filter, forwarded to bun testSee tynd test for the flags and the variables it sets. Plain bun test also works; set TYND_TEST_CLI or put tynd on PATH so launchApp can start the app.
How launchApp starts the app
Section titled “How launchApp starts the app”- Runs
tynd dev(or thecommandyou give) with the debug socket enabled. - Waits for the host’s discovery file:
%LOCALAPPDATA%\tynd\debug\<pid>.jsonon Windows,~/Library/Application Support/tynd/debugon macOS,$XDG_RUNTIME_DIR/tyndon Linux. - Connects (named pipe, unix socket, or loopback TCP), authenticates with the file’s token, and waits for a loaded window.
Unless env.TYND_DEBUG_SOCKET is set, launchApp picks the debug endpoint itself: on Linux and macOS a socket in a fresh private (mode 0700) directory under the system temp directory (tynd-test-*), on Windows a named pipe with a random name (tynd-test-<pid>-<random>). The directory is removed on close() and when the launch fails; if removal fails, a leftover empty tynd-test-* directory is harmless and can be deleted.
launchApp({ cwd, // project root args, // extra args for the launch command env, // extra env vars for the app process command, // replaces `tynd dev`, e.g. a packaged binary built with `tynd build --debug-protocol` timeout, // default 120000 ms: the first run compiles the host appId, // attach only to this app id when several run waitForReady, // default true: wait for a loaded window discoveryDir, // override the discovery directory});Driving the app
Section titled “Driving the app”launchApp resolves to a TyndApp. Selectors are CSS selectors, resolved to element refs with webview.find_element; every window method takes an optional { label } to target a window other than the default.
| Method | Purpose |
|---|---|
windowList() |
Open windows |
eval(script, { label, raw }) |
Run JS in the page; the JSON result is parsed unless raw |
findElement(selector) |
Element ref, or null |
click(selector | { ref } | { x, y }) |
Click |
type(text, target?) |
Type into the target or the focused element |
fill([{ selector | ref, value }]) |
Replace field values |
pressKey("ctrl+k") |
Key combination |
snapshot({ mode }) |
map (default), html or state |
consoleLogs() |
Page console output |
screenshot() |
PNG of a window |
ipcRecent(n) |
Last IPC frames seen by the host |
appInfo() |
App identity |
call(method, params) |
Any other debug-protocol method |
waitFor(predicate, { timeout, interval }) |
Poll until truthy (5 s, 50 ms by default) |
waitForSelector(selector) |
Poll until the element exists |
expectScreenshot(path, opts) |
Compare with a baseline PNG |
output() |
Captured app stdout/stderr |
close() |
Ask the app to quit, then kill the process tree |
Actions throw ActionError when the helper reports ok: false or the selector matches nothing.
waitFor and waitForSelector throw WaitForTimeoutError when the deadline passes. Its message says how long it waited; lastError holds the last error the predicate threw, if any. waitFor(predicate, options) is also exported on its own, with an optional message for the error.
Besides launchApp, the package exports lower-level pieces: DebugClient, discovery helpers (readDiscoveryEntries, selectEntry, defaultDiscoveryDir), transports (connectTransport, socketTransport), diffImages / diffPng and ScreenshotMismatchError. Two subpaths need nothing else from the package:
| Import | Exports |
|---|---|
@tynd/test/png |
decodePng(bytes), encodePng(image), RawImage ({ width, height, data }, RGBA, 4 bytes per pixel). A minimal codec for 8-bit non-interlaced PNGs such as host screenshots |
@tynd/test/protocol |
Debug-protocol framing: encodeFrame, encodeRequest, FrameDecoder, decodeMessage, RpcError, MAX_FRAME_BYTES (16 MiB) |
Screenshot baselines
Section titled “Screenshot baselines”await app.expectScreenshot("e2e/__screenshots__/home.png", { maxDiffRatio: 0.001 });- A missing baseline is created and the test passes.
- On a mismatch,
<name>.actual.pngand<name>.diff.pngare written next to the baseline and the call throws. tynd test --update-snapshots(orTYND_UPDATE_SNAPSHOTS=1) rewrites baselines.- Options:
threshold(per-pixel color sensitivity, default0.1),maxDiffPixels,maxDiffRatio,update. - Capturing needs a host built with the
debug-screenshotfeature (dev-only, seetynd.config.ts). Without itscreenshot()fails.
Rendering differs across OSes and font stacks, so keep baselines per platform and prefer small regions or a tolerance over full-window pixel equality.
Constraints and pitfalls
Section titled “Constraints and pitfalls”- One client at a time. The debug server accepts a single client; a second gets
already_attached. Run E2E files with one app at a time (tynd test --max-concurrency 1, or onelaunchAppper file in sequence). - Packaged binaries need
--debug-protocol. By default@tynd/testlaunchestynd dev. To drive a packaged binary through a customcommand, build it withtynd build --debug-protocol; otherwise the app refuses to start the debug server andlaunchAppcannot attach. - Always close. Call
app.close()inafterAll, or the app process may outlive the run. - Slow first run. The 120 s default launch timeout allows the first host compile; raise the bun
--timeoutwith--timeout-msfor long tests. - Attach ambiguity. If several apps start at the same instant, pass
appIdsolaunchAppattaches to the right one. - No WebDriver. There is no WebDriver or Playwright adapter;
@tynd/testtalks the debug protocol directly. - The same protocol backs the
tynd-mcpinspection tools below.
Native development inspection
Section titled “Native development inspection”tynd dev exposes a local authenticated debug endpoint unless --no-debug is used. Native tynd-mcp can inspect a running app:
bunx @tynd/mcp servebunx @tynd/mcp call app.infobunx @tynd/mcp call webview.snapshotbunx @tynd/mcp call ipc.failedUse screenshots, element snapshots/interactions, console/network records, IPC traces, plugin metadata, and capability checks only for flows your product needs. Evaluation/launch tools remain explicit opt-ins.
Release QA
Section titled “Release QA”Validate on every shipped OS/architecture:
- application launch and shutdown;
- window/navigation/menu/tray/dialog/shortcut flows actually used;
- frontend to Bun RPC success and failure paths;
- offline startup;
- installer install/upgrade/uninstall;
- platform signing/notarization;
- signed updater N-1 to N, including full fallback and patches when enabled.
Built output lives under release/<platform>-<arch>/. The CLI does not launch a WebView during info, validate, or doctor; GUI proof requires an explicit app launch, an @tynd/test run, or an MCP-driven development session.
CI shape
Section titled “CI shape”A lean non-interactive job can run:
env: TYND_CACHE_DIR: ${{ github.workspace }}/.tynd-cachesteps:- uses: actions/cache@v4 with: path: .tynd-cache key: tynd-host-${{ runner.os }}-${{ hashFiles('bun.lock') }}- run: bun install --frozen-lockfile- run: bunx tsc --noEmit- run: bunx @tynd/cli validate --ci- run: bunx @tynd/cli buildThe runner needs Bun 1.3+, Rust 1.95+ (rustup update upgrades an older toolchain), and the platform build tools. Set TYND_CACHE_DIR on the job and cache that directory (the shared host build cache) to avoid recompiling the host from scratch on every job. Add bun test for unit tests. Run tynd test only on runners that can display the app (a desktop session or a virtual display on Linux), and build installer/signing targets on their native host.