Eli Perelman
9 years ago
7 changed files with 94 additions and 8 deletions
@ -0,0 +1,35 @@ |
|||
const spawn = require('child_process').spawn; |
|||
const toParam = require('change-case').paramCase; |
|||
|
|||
let proc; |
|||
|
|||
module.exports = (config, done) => { |
|||
if (proc) { |
|||
proc.kill(); |
|||
} |
|||
|
|||
const babelLoader = config.module.loaders.find(loader => loader.loader.includes('babel')); |
|||
const mocha = config.mocha; |
|||
|
|||
process.env.NEUTRINO_BABEL_CONFIG = JSON.stringify(babelLoader ? babelLoader.query : {}); |
|||
|
|||
const args = Object |
|||
.keys(mocha) |
|||
.reduce((args, key) => { |
|||
const value = mocha[key]; |
|||
|
|||
return value === true ? |
|||
args.concat(`--${toParam(key)}`) : |
|||
args.concat(`--${toParam(key)}`, mocha[key]); |
|||
}, ['--require', require.resolve('./register')]); |
|||
|
|||
proc = spawn('node_modules/.bin/mocha', args, { |
|||
cwd: process.cwd(), |
|||
env: process.env, |
|||
stdio: 'inherit' |
|||
}); |
|||
|
|||
if (done) { |
|||
proc.on('close', done); |
|||
} |
|||
}; |
@ -0,0 +1,4 @@ |
|||
// This registration runs in a separate process along with Mocha.
|
|||
// This ensures that Mocha runs the test files with the same Babel
|
|||
// configuration as the other webpack files
|
|||
require('babel-register')(JSON.parse(process.env.NEUTRINO_BABEL_CONFIG)); |
@ -0,0 +1,5 @@ |
|||
const crypto = require('crypto'); |
|||
const os = require('os'); |
|||
const path = require('path'); |
|||
|
|||
module.exports = () => path.join(os.tmpdir(), crypto.randomBytes(8).toString('hex')); |
Loading…
Reference in new issue