Skip to content

Commit

Permalink
Make sure Karma exits with non-zero if Webpack fails to build test co…
Browse files Browse the repository at this point in the history
  • Loading branch information
trusktr committed Dec 1, 2020
1 parent 38fb0ce commit 8efb1af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand Down
16 changes: 16 additions & 0 deletions config/karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
})
}
})(),
],
},

Expand Down

0 comments on commit 8efb1af

Please sign in to comment.