Skip to content

at-boundary/metatest-rest-typescript

Repository files navigation

MetaTester TS

A framework-agnostic fault simulation library for API testing in TypeScript. Inspired by mutation testing, MetaTester automatically injects faults into API responses to test the robustness of your test suite.

Features

  • Zero Code Changes - Just import and activate via environment variable
  • Framework Agnostic - Works with Jest, Mocha, and other test frameworks
  • HTTP Client Support - Axios, Fetch, and extensible to others
  • Comprehensive Reports - JSON reports with detailed fault simulation results
  • Plugin Architecture - Easy to extend with custom fault types and adapters

Installation

npm install @your-org/metatester-ts --save-dev

Quick Start

1. Import in your test setup

// In your test setup file or at the top of your test files
import '@your-org/metatester-ts';

2. Run tests with fault simulation

# Run normal tests
npm test

# Run tests with fault simulation  
METATESTER_ACTIVE=true npm test

3. Configuration

Create a config.yml file in your project root:

faults:
  null_field:
    enabled: true
  missing_field:
    enabled: true
  empty_string:
    enabled: true
  empty_list:
    enabled: true
  invalid_value:
    enabled: true

endpoints:
  exclude:
    - '*/demo*'
    
tests:
  exclude:
    - '*demo*'

report:
  format: json
  output_path: "./reports/simulator-report.json"

How It Works

  1. Test Interception: MetaTester intercepts your test functions using framework adapters
  2. HTTP Capture: Original API responses are captured during the first test run
  3. Fault Injection: Tests are re-run with mutated responses (null fields, missing data, etc.)
  4. Result Analysis: Each fault is classified as caught (test failed) or missed (test passed)
  5. Report Generation: Comprehensive JSON report with statistics and details

Example Report

{
  "metadata": {
    "generated_at": "2025-08-30T20:00:13.550Z",
    "total_endpoints": 2,
    "total_fields": 24, 
    "total_faults": 120,
    "total_tests": 315,
    "caught_faults": 38,
    "missed_faults": 277
  }
}

License

MIT

About

Metatest for Typescript REST API Test Frameworks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published