Skip to content

Commit

Permalink
Fixes All specs displayed when using fdescribe and fit. #37
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed May 24, 2015
1 parent 4dc4c38 commit d9e35bb
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 45 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/default-display.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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', ->
Expand Down
4 changes: 2 additions & 2 deletions spec/display-failed-spec.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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', ->
Expand Down
4 changes: 2 additions & 2 deletions spec/display-successful-spec.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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', =>
Expand All @@ -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', ->
Expand Down
18 changes: 15 additions & 3 deletions src/jasmine-spec-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
78 changes: 40 additions & 38 deletions src/spec-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ var SpecDisplay = function (options, displayProcessors) {
this.indent = ' ';
this.currentIndent = '';
this.suiteHierarchy = [];
this.suiteHierarchyDisplayed = [];
this.failedSpecs = [];
this.lastWasNewLine = false;
this.displayFailuresSummary = options.displayFailuresSummary !== false;
this.displaySuccessfulSpec = options.displaySuccessfulSpec !== false;
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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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 = '';
},
Expand Down

0 comments on commit d9e35bb

Please sign in to comment.