Testing & benching

Tests

Use kdts test to compile matching test files and then run them with Bun's test runner, which has a jest-like interface. See https://bun.com/docs/testarrow-up-right for Bun's test API.

kdts test # --fast param available in all variants
kdts test crypto
kdts test path/some.test.ts

With no target, kdts test discovers **/*.test.{js,ts}. If the target is a directory, it runs matching test files under that directory.

Because the files are compiled first, kdts test is the right command when you want to validate kdts-specific transforms or the same compiled path you ship.

If you only want to run a test directly under Bun, without kdts compilation, use:

bun test path/some.test.ts

This is useful for quick iteration, but it does not validate kdts's compiled output.

Benchmarks

Use kdts bench to compile matching benchmark files and then run the compiled output.

kdts bench # --fast param avilable in all variants
kdts bench util/hex
kdts bench exp.bench.ts

With no target, kdts bench discovers **/*.bech.{js,ts}.

For benchmarks, kdts also provides a correctness-checked harness:

It can be run with

It prints an output like:

The benchmark harness has the following signature:

In particular, the bench() harness takes a description, a record of functions to benchmark (each with the same signature), a repeat count and a dataset of input-output pairs.

Each candidate is run repeat times for every dataset item. Its result is checked against the expected output, and candidate order is shuffled per dataset item to reduce order bias.

Useful options: --fast, --filter, --buildConcurrency, and --runConcurrency. Run kdts --help for the full CLI reference.

Last updated