From c0b31766b38c3e370473370916e16207e28fc1b5 Mon Sep 17 00:00:00 2001 From: PVermeer Date: Mon, 3 Feb 2020 19:42:55 +0100 Subject: [PATCH] Added options object to be able to overwrite logging (#36) * feat(config): disable specFailure logging * docs(readme): added config to readme * docs: separate config with options --- README.md | 20 ++++++++++++++++++++ src/index.js | 13 +++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 001a81e..8bddb42 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,26 @@ module.exports = function(config) { }); }; ``` +#### With options +In combination with multiple reporters you may want to disable failed messages because it's already handled by another reporter. + +*Example when using the 'karma-mocha-reporter' plugin*: +```js +// karma.conf.js +module.exports = function(config) { + config.set({ + + // Combine multiple reporters + reporters: ['kjhtml', 'mocha'], + + jasmineHtmlReporter: { + // Suppress failed messages + suppressFailed: true + } + + }); +}; +``` You can pass a list of reporters as a CLI argument too: ```bash diff --git a/src/index.js b/src/index.js index 776583e..c26b657 100644 --- a/src/index.js +++ b/src/index.js @@ -3,11 +3,20 @@ var createPattern = function (path) { return { pattern: path, included: true, served: true, watched: false }; }; -var initReporter = function (files, baseReporterDecorator) { +var initReporter = function (karmaConfig, baseReporterDecorator) { var jasmineCoreIndex = 0; + const files = karmaConfig.files; + baseReporterDecorator(this); + if (karmaConfig.jasmineHtmlReporter) { + const config = karmaConfig.jasmineHtmlReporter; + if (config.suppressFailed) { + this.specFailure = () => void 0; + } + } + files.forEach(function (file, index) { if (JASMINE_CORE_PATTERN.test(file.pattern)) { jasmineCoreIndex = index; @@ -19,7 +28,7 @@ var initReporter = function (files, baseReporterDecorator) { files.splice(++jasmineCoreIndex, 0, createPattern(__dirname + '/lib/adapter.js')); }; -initReporter.$inject = ['config.files', 'baseReporterDecorator']; +initReporter.$inject = ['config', 'baseReporterDecorator']; module.exports = { 'reporter:kjhtml': ['type', initReporter]