Utility to create a shared files config for Wallaby and Karma
JavaScript
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
.babelrc
.editorconfig
.gitignore
.jscsrc
.jshintrc
.travis.yml
Gruntfile.js
LICENSE
README.md
package.json
wallaby.conf.js

README.md

Test Runner Config

Build Status Test Coverage Code Climate devDependency Status

When you run your unit tests using either Wallaby, Karma and Mocha, a lot of configuration such as the files list is duplicated. We like DRY, so put the files in a separate file list and load them into your Wallaby, Karma and/or Mocha config using this script!

Usage

Install this node module into your project.

npm i test-runner-config --save-dev

Require testRunnerConfig in your karma.conf.js or wallaby.conf.js file and pass a structured file list to a testRunnerConfig method to get your configuration. Mocha is not supported because it passes the files as argument to the mocha command, but you can get a files list for the Grunt or Gulp task that runs Mocha.

The file list should have the following format. You can use glob patterns, but note that Wallaby does not support them all. See Wallaby issue 69. You can use any type, however 'specs' and 'ignore' are special types that are mapped onto the correct output properties.

[{
  "type": "lib",
  "files": ["node_modules/angular/angular.js"]
},
{
  "type": "src",
  "files": ["src/*.js"]
},
{
  "type": "specs",
  "files": ["test/specs/*.js"]
}]
var testRunnerConfig = require('test-runner-config');
var config = testRunnerConfig.getWallabyFiles(files); // For Karma config call getKarmaFiles() and for Mocha call getMochaFiles()

config contains the part of your Wallaby config with the files and specs, which you can merge into your Wallaby config object. To get the files array for the Mocha grunt or Gulp task, call testRunnerConfig.getMochaFiles(require('./test/testFiles.js')).

This is now in the config variable.

{
  files: [
    { pattern: 'node_modules/angular/angular.js', load: true, instrument: false, ignore: false },
    { pattern: 'src/*.js', load: true, instrument: true, ignore: false }
  ],
  tests: [
    { pattern: 'test/specs/*.js', load: true, instrument: true, ignore: false }
  ]
}

The arrays with file patterns will be mapped onto the new data structure using default mappings. You can override the mapping per type by passing a mapping object as second argument. The following example shows you the default mappings passed explicitely.

var config = testRunnerConfig.getWallabyFiles(files, {
  config: function (file) { return { pattern: file, instrument: false, load: true, ignore: false }; },
  ignore: function (file) { return { pattern: file, instrument: false, load: false, ignore: true }; },
  lib: function (file) { return { pattern: file, instrument: false, load: true, ignore: false }; },
  mock: function (file) { return { pattern: file, instrument: false, load: false, ignore: false }; },
  specs: function (file) { return { pattern: file, instrument: true, load: true, ignore: false }; },
  src: function (file) { return { pattern: file, instrument: true, load: true, ignore: false }; },
});

Note that if you have set defaults in your Wallaby config file, these will be overridden by the default mappings.