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

Commit

Permalink
let cucumber work too
Browse files Browse the repository at this point in the history
  • Loading branch information
hankduan committed Nov 6, 2014
1 parent bfa96c5 commit 3519046
Showing 1 changed file with 53 additions and 5 deletions.
58 changes: 53 additions & 5 deletions lib/frameworks/cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,65 @@ exports.run = function(runner, specs) {
}
global.cucumber = Cucumber.Cli(execOptions);

var testResult = [];
var failedCount = 0;
// Add a listener into cucumber so that protractor can find out which
// steps passed/failed
var addResultListener = function(formatter) {
var handleStepResultEvent = formatter.handleStepResultEvent;
var newHandleStepResultEvent = function(event, callback) {

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

if (handleStepResultEvent && typeof(handleStepResultEvent) === 'function') {
handleStepResultEvent(event, callback);
} else {
callback();
}
}
formatter.handleStepResultEvent = newHandleStepResultEvent;
};

return runner.runTestPreparer().then(function () {
return q.promise(function (resolve, reject) {
global.cucumber.run(function (succeeded) {
var cucumberConf = Cucumber.Cli.Configuration(execOptions);
var runtime = Cucumber.Runtime(cucumberConf);
var formatter = cucumberConf.getFormatter();
addResultListener(formatter);
runtime.attachListener(formatter);
runtime.start(function (succeeded) {
try {
if (runner.getConfig().onComplete) {
runner.getConfig().onComplete();
}
var resolvedObj = {
failedCount: succeeded ? 0 : 1
};
resolve(resolvedObj);
resolve({
failedCount: failedCount,
specResults: testResult
});
} catch (err) {
reject(err);
}
Expand Down

0 comments on commit 3519046

Please sign in to comment.