babel-tape-runner

raw JSON →
3.0.0 verified Sat Apr 25 auth: no javascript maintenance

A test runner that combines Babel and Tape to transpile and execute test suites containing ESNext/Harmony features. Current stable version is 3.0.0, supporting Babel 7. It serves as a drop-in replacement for Tape's bundled runner, reading Babel configuration from .babelrc. The package follows a semver-aligned versioning scheme with major versions tied to Babel major releases (v1 for Babel 5, v2 for Babel 6, v3 for Babel 7). Key differentiator is the seamless integration of Babel transpilation with Tape's simple test framework, enabling modern JavaScript syntax in tests without manual setup.

error Error: Couldn't find preset "@babel/preset-env" relative to directory ...
cause Babel presets not installed or .babelrc misconfigured.
fix
Run 'npm install --save-dev @babel/preset-env' and ensure .babelrc contains '{"presets": ["@babel/preset-env"]}'.
error SyntaxError: Unexpected token import
cause Using ESM imports without proper Babel preset, or using too old Babel version.
fix
Install and configure @babel/preset-env in .babelrc and use babel-tape-runner v3 (for Babel 7).
error babel-tape-runner is not recognized as an internal or external command
cause babel-tape-runner not installed or not in PATH.
fix
Install globally with 'npm install -g babel-tape-runner' or use npx: 'npx babel-tape-runner test.js'. Alternatively, add to package.json scripts.
breaking Babel 7: Use babel-tape-runner ^3.0.0. Babel 6: Use babel-tape-runner ^2.0.0. Babel 5: Use babel-tape-runner ^1.0.0. Breaking changes between major versions due to Babel API changes.
fix Ensure babel-tape-runner version matches your Babel version. Update .babelrc and Babel presets accordingly.
gotcha babel-tape-runner is a CLI tool and does not export any JavaScript functions. Do not attempt to import or require it in your code.
fix Use babel-tape-runner only from command line or npm scripts. Use tape directly for test API.
deprecated The package has not been updated since September 2019. It may not support Babel 8 or newer tape versions.
fix Consider migrating to modern alternatives like '@babel/register' with tape or use a test framework with built-in transpilation (e.g., jest, mocha with @babel/register).
gotcha Glob patterns for test files may need quoting in package.json scripts to avoid shell expansion issues.
fix Always quote glob patterns in npm scripts: "test": "babel-tape-runner \"lib/**/__tests__/*-test.js\""
npm install babel-tape-runner
yarn add babel-tape-runner
pnpm add babel-tape-runner

Demonstrates setting up babel-tape-runner with Babel 7 and tape, including installation, .babelrc configuration, writing a test with ESNext arrow functions, and running it.

// Install dependencies
npm install --save-dev tape babel-tape-runner @babel/core @babel/preset-env

// Create .babelrc
{
  "presets": ["@babel/preset-env"]
}

// Create test file: test.js
import test from 'tape';

test('basic math', (t) => {
  const sum = (a, b) => a + b;
  t.equal(sum(1, 2), 3, '1 + 2 = 3');
  t.end();
});

// Run tests
npx babel-tape-runner test.js

// Output: TAP version 13
// # basic math
// ok 1 1 + 2 = 3
//
// 1..1
// # tests 1
// # pass  1
// # ok