lab-babel

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

A transform for the lab test framework that enables testing of ES6/JSX modules transpiled with Babel, including code coverage and proper source maps. Current version: 1.1.1 (stable, low activity). This package integrates with lab's -T option to automatically transpile .js, .jsx, .es, and .es6 files (excluding node_modules) using Babel, preserving source maps for accurate error line numbers. Key differentiator: legacy dependency on babel-core (>=4.x.x); not intended for Babel 6+ without manual preset configuration (babel-preset-es2015). Not actively maintained; consider modern alternatives like @babel/register or ts-node.

error Error: Cannot find module 'babel-core'
cause Missing peer dependency babel-core required by lab-babel.
fix
npm install --save-dev babel-core
error Error: Cannot find module 'babel-preset-es2015'
cause Missing Babel preset when using Babel 6+.
fix
npm install --save-dev babel-preset-es2015 and ensure .babelrc or package.json babel field includes 'presets': ['es2015']
error SyntaxError: Unexpected token import (or arrow functions) at runtime
cause lab-babel not applied because -T flag missing or incorrect path.
fix
Use: lab -T node_modules/lab-babel (full path). Ensure tests are .js, .jsx, .es, or .es6 files.
deprecated babel-core is deprecated in favor of @babel/core (Babel 7+). lab-babel only works with babel-core >=4.x.x and <7.x.x. For Babel 7+, use @babel/register or lab's built-in transform.
fix Use @babel/register: npm install --save-dev @babel/core @babel/register @babel/preset-env; lab -T node_modules/@babel/register
gotcha lab-babel requires babel-core as a peer dependency. If babel-core is not installed, lab will silently skip transpilation without error.
fix Install babel-core: npm install --save-dev babel-core
gotcha Only modules outside node_modules with extensions .js, .jsx, .es, .es6 are transpiled. Files in node_modules or with other extensions are ignored.
fix Ensure your test files are in the project root directory (not in node_modules) and use one of the supported extensions.
deprecated Babel 6 requires explicit preset configuration (e.g., babel-preset-es2015). Without .babelrc or package.json babel section, transpilation fails silently.
fix Create a .babelrc file with: { "presets": ["es2015"] } or install and configure babel-preset-env.
npm install lab-babel
yarn add lab-babel
pnpm add lab-babel

Install lab-babel with babel-core and es2015 preset, configure .babelrc, write a trivial ES6 test using arrow functions, and run with lab's transform option.

npm install --save-dev lab babel-core babel-preset-es2015 lab-babel
echo '{"presets":["es2015"]}' > .babelrc
# test file: test/example.js
const Lab = require('lab');
const lab = exports.lab = Lab.script();
const Code = require('code');
lab.test('transpiled ES6', (done) => {
  const fn = (x) => x * 2;
  Code.expect(fn(5)).to.equal(10);
  done();
});
# run with: npx lab -T node_modules/lab-babel -t 100 -S