From 574d5dd09b9e6020bc3dcc1698600cfd0315c24c Mon Sep 17 00:00:00 2001 From: "Lukas Theis (MuwuM)" Date: Wed, 9 Aug 2023 20:37:12 +0200 Subject: [PATCH] feat(karma-ui5-transpile): Apply `instrumenterOptions` for Istanbul from `coverageReporter` in `karma.config` (#788) * feat: apply istanbul config from coverageReporter in karma.config Signed-off-by: D056969 * fix(typo): fix spelling of the variable name Signed-off-by: D056969 * fix(karma-ui5-transpile): apply review feedback avoid useless check, reuse created variable Signed-off-by: D056969 --------- Signed-off-by: D056969 --- packages/karma-ui5-transpile/lib/index.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/karma-ui5-transpile/lib/index.js b/packages/karma-ui5-transpile/lib/index.js index b49623e51..8078c044d 100644 --- a/packages/karma-ui5-transpile/lib/index.js +++ b/packages/karma-ui5-transpile/lib/index.js @@ -9,7 +9,6 @@ const yaml = require("js-yaml"); * * Kudos goes to: https://github.com/babel/karma-babel-preprocessor * which inspired the creation of this Karma preprocessor. - * * @param {object} config Config object of UI5. * @param {object} logger Karma's logger. * @returns {Function} The preprocess function. @@ -75,21 +74,23 @@ function createPreprocessor(config, logger) { return plugin.file.request === "istanbul"; }) ) { + const istanbulConfig = { + include: ["**/*"], + exclude: [] + }; + // apply the `instrumenterOptions` for istanbul from `coverageReporter` in the `karma.config` + const instrumenterOptionsIstanbul = config.coverageReporter?.instrumenterOptions?.istanbul; + if (typeof instrumenterOptionsIstanbul === "object") { + Object.assign(istanbulConfig, instrumenterOptionsIstanbul); + } // add istanbul as first plugin into the plugins chain - babelOptions.plugins.unshift([ - "istanbul", - { - include: ["**/*"], - exclude: [] - } - ]); + babelOptions.plugins.unshift(["istanbul", istanbulConfig]); } return babelOptions; }); /** * preprocess function for the individual files to transpile - * * @param {string} content file content * @param {object} file file info * @param {Function} done callback function when done