Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
fix(cucumber): emit on cucumber scenario instead of step
Browse files Browse the repository at this point in the history
  • Loading branch information
hankduan committed Dec 16, 2014
1 parent 015cafc commit b28355d
Showing 1 changed file with 44 additions and 20 deletions.
64 changes: 44 additions & 20 deletions lib/frameworks/cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,37 +59,61 @@ exports.run = function(runner, specs) {
global.cucumber = Cucumber.Cli(execOptions);

var testResult = [];
var stepResults = {
description: null,
assertions: [],
duration: 0
};
var scenarioFailed = false;

var failedCount = 0;
// Add a listener into cucumber so that protractor can find out which
// steps passed/failed
var addResultListener = function(formatter) {
var originalHandleAfterScenarioEvent = formatter.handleAfterScenarioEvent;
formatter.handleAfterScenarioEvent = function(event, callback) {
var scenario = event.getPayloadItem('scenario');
stepResults.description = scenario.getName();
if (scenarioFailed) {
++failedCount;
runner.emit('testFail');
} else {
runner.emit('testPass');
}

testResult.push(stepResults);
stepResults = {
description: null,
assertions: [],
duration: 0
};
scenarioFailed = false;

if (originalHandleAfterScenarioEvent
&& typeof(originalHandleAfterScenarioEvent) === 'function') {
originalHandleAfterScenarioEvent(event, callback);
} else {
callback();
}
};

var originalHandleStepResultEvent = formatter.handleStepResultEvent;
formatter.handleStepResultEvent = function(event, callback) {

var stepResult = event.getPayloadItem('stepResult');
if (stepResult.isSuccessful()) {
runner.emit('testPass');
testResult.push({
description: stepResult.getStep().getName(),
assertions: [{
passed: true
}],
duration: stepResult.getDuration()
stepResults.assertions.push({
passed: true
});
}
else if (stepResult.isFailed()) {
runner.emit('testFail');
++failedCount;
stepResults.duration += stepResult.getDuration();
} else if (stepResult.isFailed()) {
scenarioFailed = true;
var failureMessage = stepResult.getFailureException();
testResult.push({
description: stepResult.getStep().getName(),
assertions: [{
passed: false,
errorMsg: failureMessage.message,
stackTrace: failureMessage.stack
}],
duration: stepResult.getDuration()
stepResults.assertions.push({
passed: false,
errorMsg: failureMessage.message,
stackTrace: failureMessage.stack
});
stepResults.duration += stepResult.getDuration();
}

if (originalHandleStepResultEvent
Expand Down

0 comments on commit b28355d

Please sign in to comment.