mocha-traceur

raw JSON →
2.1.0 verified Fri May 01 auth: no javascript maintenance

A Mocha plugin that compiles JavaScript files through the Traceur transpiler, enabling ES6 (ES2015) features for test files. Version 2.1.0 is the current stable release, depending on 'traceur-runner' for stack traces and optional dependency compilation. It operates via Mocha's --compilers flag. Key differentiator vs alternatives like babel-register: focused solely on Traceur, with no dependency compilation by default, making it lightweight but restrictive. The package is maintained infrequently; latest release 2.1.0 is several years old. Does not bundle Traceur itself, requiring a separate install.

error Error: Cannot find module 'traceur'
cause The package does not bundle Traceur; it must be installed separately.
fix
Run: npm install --save-dev traceur
error Error: Unexpected token import
cause Mocha does not natively support ES6 modules. The --compilers flag may not be applied correctly, or the plugin isn't loading.
fix
Use command: mocha --compilers js:mocha-traceur test/*.js (ensure the flag uses the correct path to mocha-traceur).
error SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
cause Traceur may not be transpiling because the file is not passed through the plugin (e.g., due to incorrect file extension or missing --compilers flag).
fix
Ensure --compilers is set correctly and that your test files match the pattern (e.g., .js). Add 'use strict' if needed.
breaking Dependencies under node_modules are NOT compiled with Traceur. If your code imports from an ES6-only package not transpiled, it will fail at runtime.
fix Use only transpiled dependencies, or switch to babel-register which can transpile node_modules via ignore patterns.
deprecated Traceur Compiler is no longer actively maintained. Prefer Babel or TypeScript for ES6+ transpilation.
fix Migrate to a modern transpiler like Babel with @babel/register.
gotcha The package does not include Traceur itself. You must install traceur separately, or use traceur-runner (optional) to add stack trace support.
fix Run: npm install --save-dev traceur or traceur-runner
breaking In v2, dependencies are no longer compiled. If you relied on dependency transpilation in v1, tests may break after upgrading.
fix Ensure all dependencies are pre-transpiled, or pin to v1.x if dependency transpilation is required.
npm install mocha-traceur
yarn add mocha-traceur
pnpm add mocha-traceur

Setup and run Mocha tests with Traceur transpilation via --compilers flag, demonstrating ES6 arrow functions and template literals.

// Install dependencies
npm install --save-dev mocha mocha-traceur traceur

// Create a test file 'test/test.js' with ES6 features
import { strictEqual } from 'assert';

const greet = (name) => `Hello, ${name}!`;
describe('greet', () => {
  it('should greet a person', () => {
    strictEqual(greet('World'), 'Hello, World!');
  });
});

// Run tests from command line
mocha --compilers js:mocha-traceur test/*.js