diff --git a/CHANGELOG.md b/CHANGELOG.md index 71493610..1d335275 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 2.2.2 + +## Bugfix + +* Fixes All specs displayed when using `fdescribe` and `fit`. [#37](https://github.com/bcaudan/jasmine-spec-reporter/issues/37) + # 2.2.1 ## Bugfix diff --git a/spec/default-display.spec.coffee b/spec/default-display.spec.coffee index ee261014..c3125b46 100644 --- a/spec/default-display.spec.coffee +++ b/spec/default-display.spec.coffee @@ -166,6 +166,19 @@ describe 'with default display', -> '' ] + it 'should not display empty suite', -> + outputs = new Test(@reporter, -> + @describe 'suite 1', => + @it 'spec 1', => + @passed() + @describe 'empty suite', => + ).outputs + expect(outputs).contains [ + ' suite 1' + ' ✓ spec 1' + '' + ] + expect(outputs).not.contains /empty suite/ describe 'summary', -> it 'should report success', -> diff --git a/spec/display-failed-spec.spec.coffee b/spec/display-failed-spec.spec.coffee index c2af6d2b..5fb6e5c0 100644 --- a/spec/display-failed-spec.spec.coffee +++ b/spec/display-failed-spec.spec.coffee @@ -13,14 +13,14 @@ describe 'with failed spec disabled', -> describe 'when suite', -> - it 'should display fully failed suite', -> + it 'should not display fully failed suite', -> expect(new Test(@reporter, -> @describe 'failed suite', => @it 'spec 1', => @failed() @it 'spec 2', => @failed() - ).outputs).contains /failed suite/ + ).outputs).not.contains /failed suite/ it 'should display not fully failed suite', -> diff --git a/spec/display-successful-spec.spec.coffee b/spec/display-successful-spec.spec.coffee index ad24a5ce..121af80b 100644 --- a/spec/display-successful-spec.spec.coffee +++ b/spec/display-successful-spec.spec.coffee @@ -13,7 +13,7 @@ describe 'with successful spec disabled', -> describe 'when suite', -> - it 'should display successful suite', -> + it 'should not display fully successful suite', -> outputs = new Test(@reporter, -> @describe 'suite', => @it 'spec 1', => @@ -22,7 +22,7 @@ describe 'with successful spec disabled', -> @passed() ).outputs - expect(outputs).contains /suite/ + expect(outputs).not.contains /suite/ it 'should display failed suite', -> diff --git a/src/jasmine-spec-reporter.js b/src/jasmine-spec-reporter.js index 6182ead7..6f4dfa0a 100644 --- a/src/jasmine-spec-reporter.js +++ b/src/jasmine-spec-reporter.js @@ -14,8 +14,10 @@ var SpecReporter = function (options) { this.finished = false; this.options = options || {}; initColors(this.options); + var displayProcessors = initProcessors(this.options); + this.options.hasCustomDisplaySpecStarted = hasCustomDisplaySpecStarted(displayProcessors); - this.display = new SpecDisplay(this.options, initProcessors(this.options)); + this.display = new SpecDisplay(this.options, displayProcessors); this.metrics = new SpecMetrics(); }; @@ -51,6 +53,16 @@ function initProcessors(options) { return displayProcessors; } +function hasCustomDisplaySpecStarted(processors) { + var hasCustomDisplaySpecStarted = false; + processors.forEach(function (processor) { + var log = 'foo'; + var result = processor.displaySpecStarted({id: 'bar', description: 'bar', fullName: 'bar'}, log); + hasCustomDisplaySpecStarted |= result !== log; + }); + return hasCustomDisplaySpecStarted; +} + SpecReporter.prototype = { jasmineStarted: function (info) { this.started = true; @@ -65,11 +77,11 @@ SpecReporter.prototype = { }, suiteStarted: function (suite) { - this.display.suite(suite); + this.display.suiteStarted(suite); }, suiteDone: function (suite) { - this.display.suiteResults(suite); + this.display.suiteDone(suite); }, specStarted: function (spec) { diff --git a/src/spec-display.js b/src/spec-display.js index dbb001ea..91e40d43 100644 --- a/src/spec-display.js +++ b/src/spec-display.js @@ -2,6 +2,7 @@ var SpecDisplay = function (options, displayProcessors) { this.indent = ' '; this.currentIndent = ''; this.suiteHierarchy = []; + this.suiteHierarchyDisplayed = []; this.failedSpecs = []; this.lastWasNewLine = false; this.displayFailuresSummary = options.displayFailuresSummary !== false; @@ -9,6 +10,7 @@ var SpecDisplay = function (options, displayProcessors) { this.displayFailedSpec = options.displayFailedSpec !== false; this.displayPendingSpec = options.displayPendingSpec || false; this.displayWithoutColors = options.colors === false; + this.hasCustomDisplaySpecStarted = options.hasCustomDisplaySpecStarted; this.displayProcessors = displayProcessors; var displayStacktrace = options.displayStacktrace || 'none'; @@ -60,11 +62,14 @@ SpecDisplay.prototype = { }, specStarted: function (spec) { - var log = null; - this.displayProcessors.forEach(function (displayProcessor) { - log = displayProcessor.displaySpecStarted(spec, log); - }); - this.log(log); + if (this.hasCustomDisplaySpecStarted) { + this.ensureSuiteDisplayed(); + var log = null; + this.displayProcessors.forEach(function (displayProcessor) { + log = displayProcessor.displaySpecStarted(spec, log); + }); + this.log(log); + } }, successful: function (spec) { @@ -124,17 +129,36 @@ SpecDisplay.prototype = { return filtered.join('\n' + this.currentIndent); }, + suiteStarted: function (suite) { + this.suiteHierarchy.push(suite); + }, + + suiteDone: function () { + var suite = this.suiteHierarchy.pop(); + if (this.suiteHierarchyDisplayed[this.suiteHierarchyDisplayed.length - 1] === suite) { + this.suiteHierarchyDisplayed.pop(); + } + this.newLine(); + this.decreaseIndent(); + }, + ensureSuiteDisplayed: function () { - if (this.suiteHierarchy.length == 0) { - var suiteName = 'Top level suite'; - this.suite({fullName: suiteName, description: suiteName}); + if (this.suiteHierarchy.length !== 0) { + for (var i = this.suiteHierarchyDisplayed.length ; i < this.suiteHierarchy.length; i++) { + this.suiteHierarchyDisplayed.push(this.suiteHierarchy[i]); + this.displaySuite(this.suiteHierarchy[i]); + } + } else { + var topLevelSuite = { description: 'Top level suite' }; + this.suiteHierarchy.push(topLevelSuite); + this.suiteHierarchyDisplayed.push(topLevelSuite); + this.displaySuite(topLevelSuite) } }, - suite: function (suite) { + displaySuite: function (suite) { this.newLine(); - this.computeSuiteHierarchy(suite); - this.computeSuiteIndent(); + this.computeSuiteIndent(suite); var log = null; this.displayProcessors.forEach(function (displayProcessor) { log = displayProcessor.displaySuite(suite, log); @@ -143,9 +167,11 @@ SpecDisplay.prototype = { this.increaseIndent(); }, - suiteResults: function (suite) { - this.newLine(); - this.decreaseIndent(); + computeSuiteIndent: function () { + this.resetIndent(); + for (var i = 0 ; i < this.suiteHierarchyDisplayed.length ; i++) { + this.increaseIndent(); + } }, log: function (stuff) { @@ -165,30 +191,6 @@ SpecDisplay.prototype = { } }, - computeSuiteHierarchy: function (suite) { - var parentName = this.getParentName(suite); - for (var i = 0 ; i < this.suiteHierarchy.length ; i++) { - if (this.suiteHierarchy[i] == parentName) { - this.suiteHierarchy.splice(i + 1, this.suiteHierarchy.length - i - 1); - break; - } - } - if (i == this.suiteHierarchy.length) { - this.suiteHierarchy.push(parentName); - } - }, - - computeSuiteIndent: function () { - this.resetIndent(); - for (var i = 0 ; i < this.suiteHierarchy.length ; i++) { - this.increaseIndent(); - } - }, - - getParentName: function (element) { - return element.fullName.replace(element.description, ''); - }, - resetIndent: function () { this.currentIndent = ''; },