Supported technologies: Babel

Wallaby.js supports continuous testing and real-time code coverage for ES6, ES7, ES.Next and Flow code with Babel compiler.

module.exports = function (wallaby) {
  return {
    files: [
      'src/**/*.js'
    ],

    tests: [
      'test/**/*Spec.js'
    ],

    compilers: {
      '**/*.js': wallaby.compilers.babel()
    }
  };
};

All files that satisfy files and tests patterns will be tested against the compilers pattern, and those that match will be compiled.

You may find the working sample of wallaby.js configuration for ES6 and ES7 in this repository.

es.next

Babel compiler options

If you have a .babelrc configuration file (or a "babel": {} section in your package.json file), then it will be automatically used by wallaby babel compiler (unless you are passing any settings to wallaby.compilers.babel).

If you don’t have the file or you would like to override ALL of its settings, you may just pass them to the wallaby.compilers.babel function argument in your wallaby config.

module.exports = function (wallaby) {
  return {
    files: [
      'src/**/*.js'
    ],

    tests: [
      'test/**/*Spec.js'
    ],

    compilers: {
      '**/*.js': wallaby.compilers.babel({
        /* babel options
         * like `stage: n` for Babel 5.x or `presets: [...]` for Babel 6
         * (no need to duplicate .babelrc, if you have it, it'll be automatically loaded) */
        presets: ['es2015']
      })
    }
  };
};

Please note, that if you are passing ANY babel settings to the wallaby.compilers.babel in your wallaby config file, then .babelrc/package.json settings will not be used. If you would like to use both, then you will need to pass babelrc: true flag. Note that in this case, if some presets, transforms or plugins are defined in both wallaby config and .babelrc, they may be applied twice.

module.exports = function (wallaby) {
  return {
    ...
    compilers: {
      '**/*.js': wallaby.compilers.babel({
        babelrc: true,
        presets: ['es2015']
      })
    }
  };
};

Babel 6

If you’re using Babel 6, you must add presets: ['...'] instead of stage: n to your .babelrc file (or wallaby babel compiler/preprocessor options).

For example, if you are using babel for ES6/JSX and don’t have a .babelrc file (or a "babel": {} section in your package.json file), then your compiler configuration may look like:

    compilers: {
      '**/*.js': wallaby.compilers.babel({
        // babel options (if you don't have .babelrc file)
        presets: ['es2015', 'react']
      })
    }

Don’t forget to install the presets first:

npm install babel-preset-es2015 babel-preset-react

Babel environment

If you are using different environment settings in your babel configuration and need to pass some process.env settings to Babel compiler, you may do it by setting the properties right in wallaby.js configuration file. For example:

 // whenever wallaby loads the config file (and later uses babel),
 // babel will know that we are in the `test` env
 process.env.BABEL_ENV = 'test';

 module.exports = function (wallaby) {
   return {
     files: [...],
     tests: [...],
     compilers: {...}
     ...
   };
 };

Babel compiler version

By default, wallaby.js is using your project’s latest local Babel version (from the project node_modules/@babel/core, or node_modules/babel-core, or node_modules/babel).

If you want to use a different version, you may pass babel compiler reference via babel options property. For example, the following config will make wallaby.js use babel compiler from your installed node modules (which is the default option when you don’t specify the setting at all):

module.exports = function (wallaby) {
  return {
    files: [
      'src/**/*.js'
    ],

    tests: [
      'test/**/*Spec.js'
    ],

    compilers: {
      '**/*.js': wallaby.compilers.babel({
        babel: require('babel-core'),
        presets: ['es2015']
      })
    }
  };
};