dánwòdánwò

Examples

Shop with Playwright

The shop's purchase test written for Playwright Test, with danwo's emulators, invariant and fault matrix.

The shop's purchase test written for Playwright Test, with danwo's emulators, invariant and fault matrix. See it on GitHub.

What it shows

  • An existing Playwright test given danwo's emulators and flight record
  • The invariant declared with test.invariant
  • danwo-playwright matrix running the fault matrix over a Playwright test

Stack

Playwright TestNode.js

Emulates: Stripe. Runs on: Playwright Test in Chromium.

Run it

From examples/shop-playwright, after bun install at the repository's root:

bun run test:e2e   # playwright test
bun run matrix     # danwo-playwright matrix tests/buy-credits.spec.ts

Playwright Test explains what this example leans on.

The test

tests/buy-credits.spec.ts
import { expect, testWith } from "@danwo/playwright"
import type { StripeFixtures } from "@danwo/sdk"

import { grantedCredits, paidCredits } from "../../shop/src/ledger.ts"

const test = testWith<StripeFixtures>()

// Whichever way the purchase went, the shop grants exactly the credits Stripe was paid for.
test.invariant(async ({ danwo, baseURL }) => {
  expect(await grantedCredits(baseURL ?? "", "u1")).toBe(await paidCredits(danwo.stripe, "u1"))
})

test("buys 500 credits through Stripe Checkout", async ({ page, danwo }) => {
  await page.goto("/")
  await page.getByRole("button", { name: "Buy 500 credits" }).click()

  await expect(page.getByTestId("checkout-total")).toContainText("$5.00")
  await page.getByTestId("checkout-pay").click()

  await expect(page.getByRole("heading", { name: "Thank you for your purchase" })).toBeVisible()
  // Credits arrive by webhook; play the deliveries on the emulator's clock.
  await danwo.settle()
  await expect(page.getByText(/^Credits: /)).toHaveText("Credits: 500")
})

On this page

Run it on every pull request

A GitHub check and one comment per pull request, with the flight records attached.

Set up CI