From 50298f9dcb313ca9b6b24aab48039045e65fc230 Mon Sep 17 00:00:00 2001 From: "Kyle D. McCormick" Date: Tue, 3 Dec 2024 13:51:26 -0500 Subject: [PATCH] build: ensure JS tests fail when the Karma Webpack build fails Adds a "DieHardPlugin" to the Webpack build. See enclosed code comment for more details. --- webpack.common.config.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/webpack.common.config.js b/webpack.common.config.js index de8b545c978b..c9b69eef4292 100644 --- a/webpack.common.config.js +++ b/webpack.common.config.js @@ -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 { @@ -153,6 +174,7 @@ module.exports = Merge.smart({ // any other way to declare that dependency. $script: 'scriptjs' }), + new DieHardPlugin(), ], module: {