dánwòdánwò

Writing tests

TypeScript in tests

What test and config files may contain, since danwo runs them with Node's own type stripping.

danwo runs your test files and danwo.config.ts as TypeScript with no build step. Node removes the types as it loads each file. Nothing is compiled, so a few TypeScript features that need compiling don't load.

Most tests never meet this. You'll see it when you move a suite over from a tool that compiled your tests, or import a helper written for a bundler.

What works

Types, interfaces, generics, as casts, satisfies and type-only imports all load as they are:

tests/cart.danwo.ts
import { test } from "@danwo/sdk"

type Plan = "free" | "pro"

const PLANS = { free: 0, pro: 500 } as const satisfies Record<Plan, number>

test("shows the pro plan", async ({ app, screen, expect }) => {
  await app.open("/pricing")
  await expect(screen.getByText(`${PLANS.pro} credits`)).toBeVisible()
})

Imports

danwo resolves imports the way a TypeScript project expects, on top of what Node does:

ImportLoads
./helpers/cart.tsthe file, as Node does
./helpers/cart or ./helpers/cart.jscart.ts, or cart/index.ts
@/helpers/cartthe file your tsconfig.json paths map it to
@danwo/sdkan installed package, as Node does

Aliases come from the nearest tsconfig.json above the importing file, and from the configs it extends by a relative path. They apply to your own files, not to installed packages.

What does not load

These need compiling, so the file stops loading. Write the plain form instead:

Not supportedWrite instead
enum Plan { Free, Pro }const Plan = { Free: "free", Pro: "pro" } as const
constructor(private cart: Cart) {}declare cart in the class body and assign it in the constructor
namespace Shop { … }export the values from the module itself
<Cart>valuevalue as Cart
import x = require("x"), export =import and export
decoratorsa plain function call

The same applies to every file a test or the config imports, except installed packages.

When a file doesn't load

danwo names the file and line, what isn't supported, and what to write. The run exits with code 2 before any test starts:

danwo: tests/helpers/plans.ts:3: an `enum` cannot load in the test file tests/cart.danwo.ts or a
file it imports. danwo runs TypeScript with Node's type stripping, which removes types and
compiles nothing. Instead, use a plain object with `as const` …

Type errors never stop a run: types are removed, not checked. Run tsc --noEmit in CI to check your tests against danwo's types.

Next

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