From 55c6c1b50b1b111018153e4c38e7de7f76c6f656 Mon Sep 17 00:00:00 2001 From: davimarinho Date: Mon, 6 Nov 2023 15:25:15 -0300 Subject: [PATCH] Fix karma.conf Signed-off-by: davimarinho --- karma.conf.js | 83 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 69 insertions(+), 14 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 03273616..2eea6e9f 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,16 +1,71 @@ -module.exports = function(config) { - config.set({ - basePath: '../..', - frameworks: ['jasmine'], - browsers: [ - 'Chrome', - 'ChromeHeadlessCI' +module.exports = (config) => { + const coverage = config.singleRun ? ["coverage"] : []; + + config.set({ + frameworks: ["jasmine"], + plugins: [ + "karma-jasmine", + "karma-webpack", + "karma-coverage", + "karma-remap-istanbul", + "karma-chrome-launcher", ], - customLaunchers: { - ChromeHeadlessCI: { - base: 'ChromeHeadless', - flags: ['--no-sandbox'] - } + files: [ + "./src/tests.entry.ts", + { + pattern: "**/*.map", + served: true, + included: false, + watched: true, + }, + ], + preprocessors: { + "./src/tests.entry.ts": ["webpack", "sourcemap"], + "./src/**/!(*.test|tests.*).(ts|js)": ["sourcemap"], + }, + + webpack: { + plugins, + entry: "./src/tests.entry.ts", + devtool: "inline-source-map", + resolve: { + extensions: [".webpack.js", ".web.js", ".ts", ".js"], + }, + module: { + rules: combinedLoaders().concat( + config.singleRun ? [loaders.istanbulInstrumenter] : [] + ), + }, + stats: { colors: true, reasons: true }, + }, + webpackServer: { + noInfo: true, // prevent console spamming when running in Karma! + }, + + reporters: ["spec"] + .concat(coverage) + .concat(coverage.length > 0 ? ["karma-remap-istanbul"] : []), + + remapIstanbulReporter: { + src: "coverage/chrome/coverage-final.json", + reports: { + html: "coverage", + }, + }, + + coverageReporter: { + reporters: [{ type: "json" }], + dir: "./coverage/", + subdir: (browser) => { + return browser.toLowerCase().split(/[ /-]/)[0]; // returns 'chrome' + }, }, - }) - }; \ No newline at end of file + + port: 9876, + browsers: ["Chrome"], // Alternatively: 'PhantomJS' + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + captureTimeout: 6000, + }); +};