示例

SwiftUI waitlist

A SwiftUI app on the iOS Simulator joins a waitlist through a Hono API on Postgres, which sends a welcome email through Resend.

本页还没有中文版,下面是英文原文。

A SwiftUI app on the iOS Simulator joins a waitlist through a Hono API on Postgres, which sends a welcome email through Resend. See it on GitHub.

What it shows

  • danwo build-ios building a plain Xcode project for the simulator, unsigned, kept until its sources change
  • The app's HTTPS calls to its production host reaching a local API through danwo's proxy, with no change to the app
  • Locators on native SwiftUI views: accessibilityLabel for getByLabel, accessibilityIdentifier for getByTestId
  • An invariant that reads both sides: exactly one row in Postgres and exactly one welcome email
  • danwo matrix faulting the app's own API, Resend and the API's SQL

Stack

SwiftUIiOS SimulatorHonoPostgres

Emulates: Resend. Runs on: A native SwiftUI app on an iOS Simulator, with Postgres in Docker.

Run it

Copy examples/with-swiftui anywhere, then from its folder:

npm install
npm test

Its scripts:

npm run build:ios      # danwo build-ios ios
npm run api            # node api/server.ts
npm run typecheck      # tsc --noEmit
npm test               # danwo test
npm run test:agentic   # danwo test tests/agentic.danwo.ts
npm run matrix         # danwo matrix tests/deterministic.danwo.ts --grep "joins the waitlist"
npm run matrix:plan    # danwo matrix tests/deterministic.danwo.ts --grep "joins the waitlist" --plan
npm run serve          # danwo serve

Its README says what else it needs and what the last full matrix found.

Until the danwo version it pins is on npm, install it from a local build instead: from the repository's root, bun run release <version> --pack, then node examples/link.ts with-swiftui, which installs a copy and prints where it is.

Native iOS apps explains what this example leans on.

The test

tests/deterministic.danwo.ts
import { joinedOnce, test } from "./waitlist.ts"

const EMAIL = "[email protected]"

test("shows the waitlist form", async ({ screen, expect }) => {
  /* Every test starts the app afresh on the device; no `app.open` is needed. */
  await expect(screen.getByLabel("Work email")).toBeVisible()
  await expect(screen.getByRole("button", { name: "Join the waitlist" })).toBeVisible()
})

test("asks for a valid email", async ({ screen, expect }) => {
  await screen.getByLabel("Work email").fill("ada")
  await screen.getByRole("button", { name: "Join the waitlist" }).tap()

  /* The API refuses it; the app shows the message it answered. */
  await expect(screen.getByTestId("error")).toHaveText("Enter a valid email address.")
})

test("joins the waitlist", async ({ screen, expect }) => {
  await screen.getByLabel("Work email").fill(EMAIL)
  /* Joining saves the row and calls Resend; readiness waits for both before the next line. */
  await screen.getByTestId("join").tap()

  await expect(screen.getByTestId("status")).toHaveText("You're on the list")
  await expect(screen.getByTestId("waitlist-count")).toHaveText("1")
}).invariant((fixtures) => joinedOnce({ ...fixtures, email: EMAIL }))

本页内容

在每个 Pull Request 上运行

每个 Pull Request 一个 GitHub Check 和一条评论,并附上完整的运行记录。

配置 CI