Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature run summaries can now be reused among formatters.
- Loading branch information
Showing
5 changed files
with
1,291 additions
and
1,025 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
var SummaryLogger = function () { | ||
var Cucumber = require('../../cucumber'); | ||
|
||
var logs = ""; | ||
var failedScenarioLogBuffer = ""; | ||
var undefinedStepLogBuffer = ""; | ||
var failedStepResults = Cucumber.Type.Collection(); | ||
var statsJournal = Cucumber.Listener.StatsJournal(); | ||
|
||
var self = Cucumber.Listener(); | ||
|
||
var parentHear = self.hear; | ||
self.hear = function hear(event, callback) { | ||
statsJournal.hear(event, function () { | ||
parentHear(event, callback); | ||
}); | ||
}; | ||
|
||
self.log = function log(string) { | ||
logs += string; | ||
}; | ||
|
||
self.getLogs = function getLogs() { | ||
return logs; | ||
}; | ||
|
||
self.handleStepResultEvent = function handleStepResult(event, callback) { | ||
var stepResult = event.getPayloadItem('stepResult'); | ||
if (stepResult.isUndefined()) { | ||
self.handleUndefinedStepResult(stepResult); | ||
} else if (stepResult.isFailed()) { | ||
self.handleFailedStepResult(stepResult); | ||
} | ||
callback(); | ||
}; | ||
|
||
self.handleUndefinedStepResult = function handleUndefinedStepResult(stepResult) { | ||
var step = stepResult.getStep(); | ||
self.storeUndefinedStep(step); | ||
}; | ||
|
||
self.handleFailedStepResult = function handleFailedStepResult(stepResult) { | ||
self.storeFailedStepResult(stepResult); | ||
}; | ||
|
||
self.handleAfterScenarioEvent = function handleAfterScenarioEvent(event, callback) { | ||
if (statsJournal.isCurrentScenarioFailing()) { | ||
var scenario = event.getPayloadItem('scenario'); | ||
self.storeFailedScenario(scenario); | ||
} | ||
callback(); | ||
}; | ||
|
||
self.handleAfterFeaturesEvent = function handleAfterFeaturesEvent(event, callback) { | ||
self.logSummary(); | ||
callback(); | ||
}; | ||
|
||
self.storeFailedStepResult = function storeFailedStepResult(failedStepResult) { | ||
failedStepResults.add(failedStepResult); | ||
}; | ||
|
||
self.storeFailedScenario = function storeFailedScenario(failedScenario) { | ||
var name = failedScenario.getName(); | ||
var line = failedScenario.getLine(); | ||
self.appendStringToFailedScenarioLogBuffer(":" + line + " # Scenario: " + name); | ||
}; | ||
|
||
self.storeUndefinedStep = function storeUndefinedStep(step) { | ||
var snippetBuilder = Cucumber.SupportCode.StepDefinitionSnippetBuilder(step); | ||
var snippet = snippetBuilder.buildSnippet(); | ||
self.appendStringToUndefinedStepLogBuffer(snippet); | ||
}; | ||
|
||
self.appendStringToFailedScenarioLogBuffer = function appendStringToFailedScenarioLogBuffer(string) { | ||
failedScenarioLogBuffer += string + "\n"; | ||
}; | ||
|
||
self.appendStringToUndefinedStepLogBuffer = function appendStringToUndefinedStepLogBuffer(string) { | ||
if (undefinedStepLogBuffer.indexOf(string) == -1) | ||
undefinedStepLogBuffer += string + "\n"; | ||
}; | ||
|
||
self.getFailedScenarioLogBuffer = function getFailedScenarioLogBuffer() { | ||
return failedScenarioLogBuffer; | ||
}; | ||
|
||
self.getUndefinedStepLogBuffer = function getUndefinedStepLogBuffer() { | ||
return undefinedStepLogBuffer; | ||
}; | ||
|
||
self.logSummary = function logSummary() { | ||
self.log("\n\n"); | ||
if (statsJournal.witnessedAnyFailedStep()) | ||
self.logFailedStepResults(); | ||
self.logScenariosSummary(); | ||
self.logStepsSummary(); | ||
if (statsJournal.witnessedAnyUndefinedStep()) | ||
self.logUndefinedStepSnippets(); | ||
}; | ||
|
||
self.logFailedStepResults = function logFailedStepResults() { | ||
self.log("(::) failed steps (::)\n\n"); | ||
failedStepResults.syncForEach(function(stepResult) { | ||
self.logFailedStepResult(stepResult); | ||
}); | ||
self.log("Failing scenarios:\n"); | ||
var failedScenarios = self.getFailedScenarioLogBuffer(); | ||
self.log(failedScenarios); | ||
self.log("\n"); | ||
}; | ||
|
||
self.logFailedStepResult = function logFailedStepResult(stepResult) { | ||
var failureMessage = stepResult.getFailureException(); | ||
self.log(failureMessage.stack || failureMessage); | ||
self.log("\n\n"); | ||
}; | ||
|
||
self.logScenariosSummary = function logScenariosSummary() { | ||
var scenarioCount = statsJournal.getScenarioCount(); | ||
var passedScenarioCount = statsJournal.getPassedScenarioCount(); | ||
var undefinedScenarioCount = statsJournal.getUndefinedScenarioCount(); | ||
var pendingScenarioCount = statsJournal.getPendingScenarioCount(); | ||
var failedScenarioCount = statsJournal.getFailedScenarioCount(); | ||
var details = []; | ||
|
||
self.log(scenarioCount + " scenario" + (scenarioCount != 1 ? "s" : "")); | ||
if (scenarioCount > 0 ) { | ||
if (failedScenarioCount > 0) | ||
details.push(failedScenarioCount + " failed"); | ||
if (undefinedScenarioCount > 0) | ||
details.push(undefinedScenarioCount + " undefined"); | ||
if (pendingScenarioCount > 0) | ||
details.push(pendingScenarioCount + " pending"); | ||
if (passedScenarioCount > 0) | ||
details.push(passedScenarioCount + " passed"); | ||
self.log(" (" + details.join(', ') + ")"); | ||
} | ||
self.log("\n"); | ||
}; | ||
|
||
self.logStepsSummary = function logStepsSummary() { | ||
var stepCount = statsJournal.getStepCount(); | ||
var passedStepCount = statsJournal.getPassedStepCount(); | ||
var undefinedStepCount = statsJournal.getUndefinedStepCount(); | ||
var skippedStepCount = statsJournal.getSkippedStepCount(); | ||
var pendingStepCount = statsJournal.getPendingStepCount(); | ||
var failedStepCount = statsJournal.getFailedStepCount(); | ||
var details = []; | ||
|
||
self.log(stepCount + " step" + (stepCount != 1 ? "s" : "")); | ||
if (stepCount > 0) { | ||
if (failedStepCount > 0) | ||
details.push(failedStepCount + " failed"); | ||
if (undefinedStepCount > 0) | ||
details.push(undefinedStepCount + " undefined"); | ||
if (pendingStepCount > 0) | ||
details.push(pendingStepCount + " pending"); | ||
if (skippedStepCount > 0) | ||
details.push(skippedStepCount + " skipped"); | ||
if (passedStepCount > 0) | ||
details.push(passedStepCount + " passed"); | ||
self.log(" (" + details.join(', ') + ")"); | ||
} | ||
self.log("\n"); | ||
}; | ||
|
||
self.logUndefinedStepSnippets = function logUndefinedStepSnippets() { | ||
var undefinedStepLogBuffer = self.getUndefinedStepLogBuffer(); | ||
self.log("\nYou can implement step definitions for undefined steps with these snippets:\n\n"); | ||
self.log(undefinedStepLogBuffer); | ||
}; | ||
|
||
return self; | ||
}; | ||
module.exports = SummaryLogger; |
Oops, something went wrong.