npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

test-runner-config

v1.0.0

Published

Utility to create a shared files config for Wallaby, Karma and Mocha

Downloads

16

Readme

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.