diff --git a/bin/commands.js b/bin/commands.js index cf929dd..d647f72 100644 --- a/bin/commands.js +++ b/bin/commands.js @@ -260,7 +260,7 @@ async function spawnWithEnv(cmd, env) { }) child.on('close', exitCode => { - if (exitCode > 0) process.exit(exitCode) + if (exitCode !== 0) process.exit(exitCode) resolve() }) diff --git a/config/karma.config.js b/config/karma.config.js index 5f64926..e6e5d4c 100644 --- a/config/karma.config.js +++ b/config/karma.config.js @@ -158,6 +158,22 @@ module.exports = function (config) { } : {}), }), + + // This is needed because if Webpack fails to build test code, + // Karma still keeps running, and exits with code 0 instead of + // non-zero, making it seem that everything passed. + // https://github.com/ryanclark/karma-webpack/issues/66 + new (class ExitOnErrorWebpackPlugin { + apply(compiler) { + compiler.hooks.done.tap('ExitOnErrorWebpackPlugin', stats => { + if (stats && stats.hasErrors()) { + // Exit in the next microtask, so that Webpack + // has a chance to write error output to stderr. + Promise.resolve().then(() => process.exit(1)) + } + }) + } + })(), ], },