From b3cd6ade9879585e1bed58eadb72908de64461c9 Mon Sep 17 00:00:00 2001 From: Eli Perelman Date: Thu, 1 Sep 2016 14:20:55 -0500 Subject: [PATCH] Allow running tests against one-off files or recursive based on cli --- packages/neutrino/commands/test/index.js | 4 ++-- packages/neutrino/package.json | 4 ++-- packages/neutrino/src/mocha.js | 16 ++++++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/neutrino/commands/test/index.js b/packages/neutrino/commands/test/index.js index 841a932..30da75c 100644 --- a/packages/neutrino/commands/test/index.js +++ b/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) => { diff --git a/packages/neutrino/package.json b/packages/neutrino/package.json index 42b9ddb..4f409a0 100644 --- a/packages/neutrino/package.json +++ b/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", diff --git a/packages/neutrino/src/mocha.js b/packages/neutrino/src/mocha.js index 3376d9f..dd0d484 100644 --- a/packages/neutrino/src/mocha.js +++ b/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'