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

chore(cucumber): allow multiple formatters for cucumber #2630

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions lib/frameworks/cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ exports.run = function(runner, specs) {
}

// Process Cucumber Format param
if (runner.getConfig().cucumberOpts.format) {
if (Array.isArray(runner.getConfig().cucumberOpts.format)) {
runner.getConfig().cucumberOpts.format.forEach(function (format) {
execOptions.push('-f');
execOptions.push(format);
});
} else if (runner.getConfig().cucumberOpts.format) {
execOptions.push('-f');
execOptions.push(runner.getConfig().cucumberOpts.format);
}
Expand Down Expand Up @@ -118,12 +123,19 @@ exports.run = function(runner, specs) {
var originalHandleStepResultEvent = formatter.handleStepResultEvent;
formatter.handleStepResultEvent = function(event, callback) {
var stepResult = event.getPayloadItem('stepResult');
if (stepResult.isSuccessful()) {
var isStepFailed = stepResult.isFailed ?
stepResult.isFailed() :
stepResult.getStatus() === Cucumber.Status.FAILED;
var isStepSuccessful = stepResult.isSuccessful ?
stepResult.isSuccessful() :
stepResult.getStatus() === Cucumber.Status.PASSED;

if (isStepSuccessful) {
stepResults.assertions.push({
passed: true
});
stepResults.duration += stepResult.getDuration();
} else if (stepResult.isFailed()) {
} else if (isStepFailed) {
scenarioFailed = true;
var failureMessage = stepResult.getFailureException();
stepResults.assertions.push({
Expand All @@ -147,9 +159,13 @@ exports.run = function(runner, specs) {
return q.promise(function(resolve, reject) {
var cucumberConf = Cucumber.Cli.Configuration(execOptions);
var runtime = Cucumber.Runtime(cucumberConf);
var formatter = cucumberConf.getFormatter();
addResultListener(formatter);
runtime.attachListener(formatter);
var formatters = cucumberConf.getFormatter ?
[cucumberConf.getFormatter()] :
cucumberConf.getFormatters();

addResultListener(formatters[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, protractor just needs 1 of the formatters to hook into in order to figure out which scenarios passed/failed. All of the formatters have the same api so it doesn't matter which one we use.

formatters.forEach(runtime.attachListener.bind(runtime));

runtime.start(function() {
try {
if (runner.getConfig().onComplete) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"chai-as-promised": "~5.1.0",
"jshint": "2.5.0",
"mocha": "2.3.3",
"cucumber": "~0.6.0",
"cucumber": "~0.8.0",
"express": "~3.3.4",
"rimraf": "~2.2.6"
},
Expand Down