Registry / testing / trapit

trapit

JSON →
library1.0.24jsnpmunverified

Trapit (v1.0.24) is a JavaScript module implementing The Math Function Unit Testing Design Pattern. It provides a data-driven approach to unit testing where test inputs and expected outputs are specified in JSON, leading to reusable scenarios. Key features include: multi-scenario testing, formatted output as plain text or HTML, support for external programs via JSON results file, and avoidance of microtesting. It is designed for transactional units and supports refactoring. The module has a stable release cadence (last update years ago) and differs from traditional frameworks like Jest or Mocha by emphasizing declarative test data and full scenario coverage according to the SCAN method.

npm install trapit
INSTALL
IMPORT
SIG · TRAPIT
T
trapit
testingjavascriptv1.0.24
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Trapit
import { Trapit } from 'trapit'
const Trapit = require('trapit').Trapit
ESM named import is correct since v1; CommonJS destructuring also works.
runTest
import { runTest } from 'trapit'
const runTest = require('trapit')
runTest is a named export, not default.
formatResults
import { formatResults } from 'trapit'
import formatResults from 'trapit'
formatResults is a named export; default export is not available.

Demonstrates using Trapit to run data-driven tests from a JSON scenarios file and format results as text and HTML.

import { runTest, formatResults } from 'trapit'; import { readFileSync } from 'fs'; // Define test scenarios as JSON (in a file or inline) const scenarios = JSON.parse(readFileSync('test-scenarios.json', 'utf8')); // Run tests const results = runTest(scenarios, { // your test function that takes input and returns output testFunction: (input) => { // e.g., return Math.abs(input); return input * 2; } }); // Format results as text const textOutput = formatResults(results, 'text'); console.log(textOutput); // Or as HTML const htmlOutput = formatResults(results, 'html'); // Write HTML to file for viewing writeFileSync('test-results.html', htmlOutput);
Debug
Known issues
gotchaThe test function must be synchronous; promises or callbacks are not supported.
fix
Wrap async functions to return promises synchronously or restructure to use callbacks.
affects: >=1.0.0
deprecatedformatResults with 'html' output uses inline CSS that may not render in modern strict CSP environments.
fix
Consider using 'text' output or custom formatting; HTML output is deprecated.
affects: >=1.0.0
gotchaRunTest expects input and expected output to be JSON-serializable; objects must be deeply cloneable.
fix
Ensure all test inputs/outputs are plain objects/arrays; avoid functions, Symbols, or circular references.
affects: >=1.0.0
gotchaTrapit does not include an assertion library; strict equality is used for comparing outputs.
fix
Use precise expected values; for complex comparisons, pre-process outputs in test function.
affects: >=1.0.0
gotchaThe module is not maintained actively; no updates since 2021.
fix
Consider other testing frameworks like Jest, Mocha, or Vitest for active support.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'trapit'
Package not installed or import path incorrect.
fix
npm install trapit --save-dev
TypeError: runTest is not a function
Importing default instead of named export.
fix
import { runTest } from 'trapit';
AssertionError [ERR_ASSERTION]: Expected [object Object] to equal [object Object]
Date objects or custom classes not supported.
fix
Convert expected and actual values to JSON-serializable formats.
Upgrade
Version history
1.0.24latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
packagetrapit
trapit — npm install trapit · libregistry