Skip to content

Repository files navigation

TypeFuzz

CI npm version License

TypeFuzz

Property-based testing for TypeScript that drops straight into your existing test runner. No wrappers, no config — write fuzz tests like you write unit tests.

Why TypeFuzz?

  • Test runner integrationfuzzIt works like it/test inside Vitest and Jest. No separate CLI.
  • Zero dependencies — ships nothing you don't need. Vitest, Jest, and Zod are optional peer deps.
  • TypeScript-first — full type inference from generators to predicates. No casting.
  • Deterministic — seeded RNG means every failure is reproducible with a single seed value.
  • Built-in shrinking — automatic counterexample minimisation using binary search, length reduction, and delta debugging.

Install

npm install -D typefuzz
Other package managers
pnpm add -D typefuzz
yarn add -D typefuzz
bun add -D typefuzz

Quick example

import { fuzzIt } from 'typefuzz/vitest';
import { gen } from 'typefuzz';

fuzzIt('sort is idempotent', gen.array(gen.int(-100, 100), { minLength: 0, maxLength: 50 }), (arr) => {
  const sorted = [...arr].sort((a, b) => a - b);
  const sortedTwice = [...sorted].sort((a, b) => a - b);
  return JSON.stringify(sorted) === JSON.stringify(sortedTwice);
});

If the property fails, TypeFuzz shrinks the input to the smallest counterexample and prints the seed for replay.

TypeFuzz vs fast-check

TypeFuzz fast-check
Test runner integration fuzzIt — one function, same signature as it @fast-check/vitest with test.prop
API surface Small, opinionated Large, highly configurable
Shrinking Binary search + delta debugging Shrink-on-generate
Model-based testing Built-in Built-in
Zod integration typefuzz/zod adapter Community zod-fast-check
Async support Native Native

Features

Model-based testing

Test stateful systems against a simplified model. TypeFuzz generates random command sequences, runs them against both your system and the model, and shrinks failing sequences to the shortest reproduction. Read more →

Zod adapter

Already have Zod schemas? Generate test data directly from them with zodArbitrary. Supports objects, arrays, unions, discriminated unions, transforms, and more. Read more →

Shrinking

When a property fails, TypeFuzz automatically minimises the counterexample — binary search for numbers, length halving for strings and arrays, delta debugging for model-based command sequences. Read more →

Documentation

Development

bun install
bun run lint
bun run typecheck
bun run test

Licence

MIT

About

TypeScript fuzz testing that finds the bugs you didn't write tests for

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages