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 922de7a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/frameworks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Requirements

- The returned promise must be resolved when tests are finished and it should return a results object. This object must have a `failedCount` property and optionally a `specResults`
object of the following structure:
```
specResults = [{
description: string,
assertions: [{
Expand All @@ -34,3 +35,4 @@ Requirements
}],
duration: integer
}]
```
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 922de7a

Please sign in to comment.