npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@criterionx/testing

v0.3.5

Published

Testing utilities for Criterion decisions

Readme

@criterionx/testing

Testing utilities for Criterion decisions. Provides property-based testing, fuzzing, and coverage analysis.

Installation

npm install @criterionx/testing
# or
pnpm add @criterionx/testing

Features

  • testDecision - Test decisions with expected outcomes
  • fuzz - Fuzz testing with random inputs
  • checkProperty - Property-based testing with fast-check
  • coverage - Rule coverage analysis
  • detectDeadRules - Dead code detection

Usage

Testing Decisions

import { testDecision } from "@criterionx/testing";
import { riskDecision } from "./decisions";

const result = testDecision(riskDecision, {
  profile: defaultProfile,
  cases: [
    {
      name: "high risk transaction",
      input: { amount: 50000, country: "US" },
      expected: { status: "OK", ruleId: "high-amount" },
    },
    {
      name: "blocked country",
      input: { amount: 100, country: "NK" },
      expected: { status: "OK", ruleId: "blocked-country" },
    },
  ],
  expect: {
    noUnreachableRules: true,
  },
});

console.log(result.passed); // true or false
console.log(result.failures); // Array of test failures
console.log(result.rulesCovered); // Rules that were exercised

Fuzz Testing

import { fuzz, fc } from "@criterionx/testing";

const result = fuzz(riskDecision, {
  profile: defaultProfile,
  iterations: 1000,
  inputArbitrary: fc.record({
    amount: fc.integer({ min: 0, max: 100000 }),
    country: fc.constantFrom("US", "UK", "NK", "DE"),
  }),
});

console.log(result.totalRuns); // 1000
console.log(result.failed); // Number of failures
console.log(result.ruleDistribution); // Hits per rule

Property-Based Testing

import { checkProperty, fc } from "@criterionx/testing";

const result = checkProperty(riskDecision, {
  profile: defaultProfile,
  inputArbitrary: fc.record({
    amount: fc.integer({ min: 0, max: 100000 }),
    country: fc.constantFrom("US", "UK"),
  }),
  property: (input, result) => {
    // Property: valid inputs should never return INVALID_OUTPUT
    return result.status !== "INVALID_OUTPUT";
  },
  numRuns: 100,
});

if (!result.passed) {
  console.log("Property violated with:", result.counterExample);
}

Coverage Analysis

import { coverage, formatCoverageReport, meetsCoverageThreshold } from "@criterionx/testing";

const report = coverage(riskDecision, {
  profile: defaultProfile,
  testCases: [
    { input: { amount: 100, country: "NK" } },
    { input: { amount: 50000, country: "US" } },
    { input: { amount: 100, country: "US" } },
  ],
});

console.log(formatCoverageReport(report));
// === Rule Coverage Report ===
// Coverage: 3/3 rules (100.0%)
// Covered rules:
//   ✓ blocked-country (1 hits)
//   ✓ high-amount (1 hits)
//   ✓ default (1 hits)

if (!meetsCoverageThreshold(report, 80)) {
  throw new Error("Coverage below 80%");
}

Dead Code Detection

import { detectDeadRules } from "@criterionx/testing";

const deadRules = detectDeadRules(myDecision);
if (deadRules.length > 0) {
  console.warn("Dead rules detected:", deadRules);
}

API Reference

testDecision(decision, options)

Test a decision with provided test cases.

Options:

  • profile - Profile to use for evaluation
  • cases - Array of test cases with input, profile, and expected outcomes
  • expect.noUnreachableRules - Fail if any rules aren't covered

Returns: TestDecisionResult with passed, failures, rulesCovered, rulesUncovered

fuzz(decision, options)

Run fuzz tests on a decision.

Options:

  • profile - Profile to use
  • iterations - Number of random inputs (default: 100)
  • inputArbitrary - fast-check arbitrary for generating inputs
  • seed - Seed for reproducibility

Returns: FuzzResult with totalRuns, passed, failed, errors, ruleDistribution

checkProperty(decision, options)

Run property-based tests.

Options:

  • profile - Profile to use
  • inputArbitrary - fast-check arbitrary for inputs
  • property - Function that returns true if property holds
  • numRuns - Number of test runs (default: 100)
  • seed - Seed for reproducibility

Returns: { passed, counterExample?, error? }

coverage(decision, options)

Analyze rule coverage.

Options:

  • profile - Profile to use
  • testCases - Array of inputs to test

Returns: CoverageReport with coverage percentage and rule hit counts

detectDeadRules(decision)

Detect potentially unreachable rules.

Returns: Array of rule IDs that appear after catch-all rules

License

MIT