Skip to content

Commit

Permalink
build: ensure JS tests fail when the Karma Webpack build fails
Browse files Browse the repository at this point in the history
Adds a "DieHardPlugin" to the Webpack build. See enclosed code comment
for more details.
  • Loading branch information
kdmccormick committed Dec 4, 2024
1 parent 9e47055 commit 50298f9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions webpack.common.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ var defineFooter = new RegExp('(' + defineCallFooter.source + ')|('
var staticRootLms = process.env.STATIC_ROOT_LMS || './test_root/staticfiles';
var staticRootCms = process.env.STATIC_ROOT_CMS || (staticRootLms + '/studio');

class DieHardPlugin {
/* A small plugin which ensures that if Webpack fails, it causes the surrounding process to fail
* as well. This helps us prevent JavaScript CI from "false passing" upon build failures--that is,
* we want to avoid having another situation where the Webpack build breaks under Karma (our
* test runner) but Karma just lets it slide and moves on to the next test suite.
*
* One would imagine that this would be Webpack's default behavior (and maybe it is?) but,
* regardless, karma-webpack does not seem to consider Webpack build failures to be fatal errors
* without this plugin. We don't fully understand it, but this is good enough given that we plan
* to remove all JS in this repo soon (https://github.com/openedx/edx-platform/issues/31620).
*
* Inpsired by: https://github.com/codymikol/karma-webpack/issues/49#issuecomment-842682050
*/
apply(compiler) {
compiler.hooks.failed.tap('DieHardPlugin', (error) => {
console.error(error);
process.exit(1);
});
}
}

var workerConfig = function() {
try {
return {
Expand Down Expand Up @@ -153,6 +174,7 @@ module.exports = Merge.smart({
// any other way to declare that dependency.
$script: 'scriptjs'
}),
new DieHardPlugin(),
],

module: {
Expand Down

0 comments on commit 50298f9

Please sign in to comment.