Imhotap Test Runner
raw JSON →Imhotap is a lightweight, 'meta-test-framework' designed to run test files as independent processes and aggregate their results. It operates on the principle that each test file should be executable and indicate success or failure via its exit code. The tool automatically detects and parses Test Anything Protocol (TAP) output from test files, but is agnostic to the specific underlying test framework used, supporting any TAP producer like `tape`, `node-tap`, or `pitesti`. Key differentiators include its parallel execution model (defaulting to CPU cores - 1 concurrency), support for custom runners (e.g., `ts-node` for TypeScript files), and flexible glob-based file selection. The current stable version is 2.2.0, with a focus on stability and compatibility rather than frequent breaking changes.
Common errors
error Error: Command failed: <reporter_command> ↓
npx can find it or add it to your PATH. error Error: Command failed: chmod EACCES ↓
chmod +x <file> on the test file. Alternatively, specify a runner using -R (e.g., -R bash for a shell script). error No files found matching glob pattern: 'test/**/*.spec.js' ↓
imhotap is run. Warnings
gotcha Imhotap runs test files in parallel as separate processes. If your tests are not isolated and share resources (e.g., databases, global state, specific ports), you may encounter race conditions or unexpected failures. Adjust concurrency (`-c`) to 1 if tests require serial execution. ↓
gotcha When using a custom runner (`-R/--runner`), ensure the runner is installed and accessible in the system's PATH, or within the project's `node_modules/.bin`. If not found, `imhotap` will attempt to use `npx`, but this might fail or be slower. ↓
gotcha Imhotap expects JavaScript files (`.js`) to be executable by Node.js by default. For other file types (e.g., `.ts`, `.sh`, Python scripts), you must explicitly provide a `--runner` option, or ensure the files are marked as executable (e.g., `chmod +x file.sh`) and have a shebang. ↓
gotcha Imhotap expects TAP output from test files. If a test file's `stdout` or `stderr` does not contain valid TAP data, `imhotap` will display both streams inside a YAML block, which may be less parseable by TAP reporters. It prioritizes `stdout` over `stderr` for TAP detection by default. ↓
Install
npm install imhotap yarn add imhotap pnpm add imhotap Imports
- cli wrong
const cli = require('imhotap').cli;correctimport { cli } from 'imhotap'; // Programmatic CLI execution - TapRunner wrong
const TapRunner = require('imhotap').TapRunner;correctimport { TapRunner } from 'imhotap'; // Programmatic runner class - Running Imhotap via CLI wrong
node imhotap --files 'test/**/*.js'correctimhotap --files 'test/**/*.js'
Quickstart
mkdir -p my-project/test
echo 'console.log("TAP version 13")' > my-project/test/basic.js
echo 'console.log("ok 1 - basic test")' >> my-project/test/basic.js
echo 'console.log("TAP version 13")' > my-project/test/failing.js
echo 'console.log("not ok 1 - failing test")' >> my-project/test/failing.js
echo 'process.exit(1)' >> my-project/test/failing.js
cd my-project
npx imhotap --files 'test/**/*.js'