Browse Source

Allow running tests against one-off files or recursive based on cli

plugin-mode
Eli Perelman 8 years ago
parent
commit
b3cd6ade98
  1. 4
      packages/neutrino/commands/test/index.js
  2. 4
      packages/neutrino/package.json
  3. 16
      packages/neutrino/src/mocha.js

4
packages/neutrino/commands/test/index.js

@ -19,8 +19,8 @@ const browser = (config, args, done) => {
const node = (config, args, done) => {
args.options.watch ?
builder.watch(config, () => mocha(config), done) :
builder.build(config, () => mocha(config, done));
builder.watch(config, () => mocha(config, args), done) :
builder.build(config, () => mocha(config, args, done));
};
module.exports = (args, done) => {

4
packages/neutrino/package.json

@ -31,8 +31,8 @@
}
},
{
"command": "test",
"description": "Run a set of test suites",
"command": "test [files...]",
"description": "Run a set of test suites against the configured test directory or specifid files",
"environment": "test",
"options": {
"-p, --preset [nameOrFile]": "Specify a configuration preset for running tests",

16
packages/neutrino/src/mocha.js

@ -3,7 +3,7 @@ const toParam = require('change-case').paramCase;
let proc;
module.exports = (config, done) => {
module.exports = (config, args, done) => {
if (proc) {
proc.kill();
}
@ -11,19 +11,23 @@ module.exports = (config, done) => {
const babelLoader = config.module.loaders.find(loader => loader.loader.includes('babel'));
const mocha = config.mocha;
if (args.files) {
mocha.recursive = true;
}
process.env.NEUTRINO_BABEL_CONFIG = JSON.stringify(babelLoader ? babelLoader.query : {});
const args = Object
const argv = Object
.keys(mocha)
.reduce((args, key) => {
.reduce((argv, key) => {
const value = mocha[key];
return value === true ?
args.concat(`--${toParam(key)}`) :
args.concat(`--${toParam(key)}`, mocha[key]);
argv.concat(`--${toParam(key)}`) :
argv.concat(`--${toParam(key)}`, mocha[key]);
}, ['--require', require.resolve('./register')]);
proc = spawn('node_modules/.bin/mocha', args, {
proc = spawn('node_modules/.bin/mocha', args.files ? argv.concat(args.files) : argv, {
cwd: process.cwd(),
env: process.env,
stdio: 'inherit'

Loading…
Cancel
Save