Skip to content

Commit

Permalink
Support for Cucumber v2 (#15)
Browse files Browse the repository at this point in the history
* Cucumber V2 has released with bunch of changes. Updating this module to support Cucummber-V2.

* support Cucumber-2

* test with Node 7

* add tests for mapping scenarios per feature

* fix for parallel.scenarios

* add changelog

* readMe

* highlight

* readme
  • Loading branch information
gkushang authored Jun 19, 2017
1 parent 67b262a commit dfdc1d4
Show file tree
Hide file tree
Showing 19 changed files with 272 additions and 820 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/.idea/
/node_modules/
/test/report/*.html
/test/report/*.json
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: node_js
node_js:
- 0.12
- 7.10.0
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

### 2.0.0 (2017-06-19)

##### Support for Cucumber 2

* Cucumber 2 [PR#15](https://github.com/gkushang/cucumber-parallel/pull/15).

72 changes: 47 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
cucumber-parallel
Cucumber Parallel
=================
***Run Cucumber Features and Scenarios in Parallel***

[![Build Status](https://travis-ci.org/gkushang/cucumber-parallel.svg?branch=develop)](https://travis-ci.org/gkushang/cucumber-parallel)
[![Build Status][travis-shield]][travis-link] [![npm][npm-shield]][npm-link] [![Dependency Status][depedency-shield]][depedency-link] [![License][license-shield]][license-link]

### Run Cucumber Features and Scenarios in Parallel
> For HTML Reporting, head over to [cucumber-html-reporter][cucumber-html-reporter]

### Install
## Install


``` bash
npm install cucumber-parallel --save-dev
```
***Notes:***

* Latest version supports Cucumber 2
* Install `cucumber-parallel@1.0.0` for cucumber version `< Cucumber@2`


#### How to run Features/Scenarios in Parallel?
## Very simple to use


```bash
Expand All @@ -40,26 +45,15 @@ $ node_modules/cucumber-parallel/bin/cucumber-parallel /path/to/features -r /pat
```



#### Format
Because it runs features/scenarios in parallel, it only supports JSON format. You can save the JSON output to file by passing the cucumber-format as,


```bash
-f json:path/to/file.json
```



### Run
## Run

Supports all the arguments as [cucumber-js][1], except `--format` as explained above

``` bash
$ node_modules/cucumber-parallel/bin/cucumber-parallel /path/to/features -r /path/to/step-defs -f json:path/to/file.json --tags=@myTag
```

### Re-run failed scenarios in parallel
#### Re-run failed scenarios in parallel

```bash

Expand All @@ -77,14 +71,25 @@ $ node_modules/cucumber-parallel/bin/cucumber-parallel /path/to/login.feature:10

```


#### Format
Because it runs features/scenarios in parallel, it only supports JSON format. You can save the JSON output to file by passing the cucumber-format as,


```bash
-f json:path/to/file.json
```



Above example will run login & signup features in parallel; two processes in parallel since two features are passed. Total 4 scenarios will run. You can run all 4 in parallel by passing as below,

`/path/to/login.feature:10 /path/to/login.feature:20 /path/to/login.feature:25 path/to/signup.feature:18`


### HTML Reports

Run Features or Scenarios in Parallel and generate HTML Reports with [cucumber-html-reporter][6]
Run Features or Scenarios in Parallel and generate HTML Reports with [cucumber-html-reporter][cucumber-html-reporter]

Cucumber-Parallel is also integrated with HTML reporting Grunt Cucumber module [grunt-cucumberjs][2]

Expand All @@ -94,18 +99,35 @@ Sample HTML Reports:
2. [Foundation Theme Reports][4]
3. [Simple Theme Reports][5]

## Changelog

[changelog][changelog]

### Proposed Enhancements
- Run Features Parallel : LIVE
- Run Scenarios Parallel : LIVE
- Limit number of workers : PENDING

[1]: https://github.com/cucumber/cucumber-js "CucumberJs"
[2]: https://www.npmjs.com/package/grunt-cucumberjs "grunt-cucummberjs"
[3]: http://htmlpreview.github.io/?https://github.com/gkushang/cucumber-html-reporter/blob/develop/samples/html_reports/cucumber_report_bootstrap.html "Bootstrap Theme Reports"
[4]: http://htmlpreview.github.io/?https://github.com/gkushang/cucumber-html-reporter/blob/develop/samples/html_reports/cucumber_report_foundation.html "Foundation Theme Reports"
[5]: http://htmlpreview.github.io/?https://github.com/gkushang/cucumber-html-reporter/blob/develop/samples/html_reports/cucumber_report_simple.html "Simple Theme Reports"
[6]: https://www.npmjs.com/package/cucumber-html-reporter

[cucumber-html-reporter]: https://www.npmjs.com/package/cucumber-html-reporter

[changelog]: https://github.com/gkushang/cucumber-parallel/blob/develop/CHANGELOG.md

[travis-shield]: https://travis-ci.org/gkushang/cucumber-parallel.svg?branch=develop
[travis-link]: https://travis-ci.org/gkushang/cucumber-parallel

[npm-shield]: https://img.shields.io/npm/v/cucumber-parallel.svg
[npm-link]: https://www.npmjs.com/package/cucumber-parallel

[depedency-shield]: https://david-dm.org/gkushang/cucumber-parallel.svg
[depedency-link]: https://david-dm.org/gkushang/cucumber-parallel

[license-shield]: https://img.shields.io/github/license/mashape/apistatus.svg
[license-link]: https://github.com/gkushang/cucumber-parallel/






158 changes: 104 additions & 54 deletions lib/cucumber/cucumber_js.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}

var log = require('debug')('cucumber-parallel:cucumber_js');
var Cucumber = require('cucumber');
var Cli = require('cucumber').Cli;
var ScenarioFilter = require('cucumber').ScenarioFilter;
var helpers = require('cucumber/lib/cli/helpers');

var runTime = _interopRequireDefault(require('cucumber').Runtime);
var path = require('path');
var Command = require('commander').Command;
var fs = require('fs');
var slicedToArray = _interopRequireDefault(require('babel-runtime/helpers/slicedToArray'));
var bluebird = _interopRequireDefault(require('bluebird'));


module.exports = function cucumber_js() {

Expand Down Expand Up @@ -39,95 +55,129 @@ module.exports = function cucumber_js() {
.option('--parallel <NAME>', 'run parallel scenarios or features', collect, [])
.option('--rerun <NAME>', 'reruning the failed scenarios or features', collect, []);


program.on('--help', function() {
program.on('--help', function () {
console.log(' For more details please visit https://github.com/cucumber/cucumber-js#cli\n');
});

program.parse(process.argv);

return program;
}

function reportFormatterOutputFile(formats) {
formats.forEach(function(format) {
formats.forEach(function (format) {
process.send({
info: 'formatter',
format: format
});
})
}

function runCucumber() {
function exit(isSucceed) {
var code = isSucceed ? 0 : 1;

function getConfiguration() {
if (process.argv[2].match('node')) {
process.argv.splice(2, 1);
process.argv.splice(2, 1);
}
process.send({
info: 'report',
report: report,
succeeded: isSucceed,
code: code
});

var program = getProgram();
function exitNow() {
log('exiting with code: ' + code);
process.exit(code);
}

program.parse(process.argv);
function exitAfterTimeOut() {
setTimeout(exitNow, 10000);
}

var profileArgs = Cucumber.Cli.ProfilesLoader.getArgs(program.profile);
if (process.stdout.write('')) {
exitAfterTimeOut();
} else {
process.stdout.on('drain', exitAfterTimeOut);
}
}

if (profileArgs.length > 0) {
var fullArgs = process.argv.slice(0, 2).concat(profileArgs).concat(process.argv.slice(2));
program = getProgram();
program.parse(fullArgs);
}
function run(obj) {
return function (options) {

var features = [];
var options = program.opts();
features.push(process.argv[process.argv.length - 1]);
reportFormatterOutputFile(options.format);
return Cucumber.Cli.Configuration(options, features);
}
var ref = (0, slicedToArray.default)(options, 2);
var features = ref[0];
var ref$ = ref[1];
var cleanup = ref$.cleanup;
var formatters = ref$.formatters;

var configuration = getConfiguration();
var JsonFormatter = formatters[1];

var runtime = Cucumber.Runtime(configuration);
JsonFormatter.log = function (value) {
report.push(value.slice(1, -1));
};

var logToFunction = function(value) {
report.push(value.slice(1, -1));
};
var runtime = new runTime.default({
features: features,
listeners: formatters,
options: getProgram().opts(),
supportCodeLibrary: obj.supportCodeLibrary
});

var formatter = Cucumber.Listener.JsonFormatter(
{
stream: process.stdout,
logToFunction: logToFunction
}
);
runtime.attachListener(formatter);
var isSucceed = runtime.start();

runtime.start(function(succeeded) {
cleanup();

var code = succeeded ? 0 : 1;
return isSucceed;
}
}

process.send({
info: 'report',
report: report,
succeeded: succeeded,
code: code
function applyConfigurationAndRun(cli) {

return function (configuration) {

reportFormatterOutputFile(getProgram().opts().format);

var scenarioFilter = new ScenarioFilter(configuration.scenarioFilterOptions);

var supportCodeLibrary = cli.getSupportCodeLibrary(configuration.supportCodePaths);

var formatters = cli.getFormatters({
formatOptions: configuration.formatOptions,
formats: configuration.formats,
supportCodeLibrary: supportCodeLibrary
});

function exitNow() {
log('exiting with code: ' + code);
process.exit(code);
}
var _ref8 = bluebird.default.all([(0, helpers.getFeatures)({
featurePaths: configuration.featurePaths,
scenarioFilter: scenarioFilter
}), formatters]);

function exitAfterTimeOut() {
setTimeout(exitNow, 5000);
}
return _ref8.then(run({supportCodeLibrary: supportCodeLibrary}))
}
}

if (process.stdout.write('')) {
exitAfterTimeOut();
} else {
process.stdout.on('drain', exitAfterTimeOut);
function runCucumber() {
function removeNodeArgFromProcessArgs() {
if (process.argv[2].match('node')) {
process.argv.splice(2, 1);
process.argv.splice(2, 1);
}
}

removeNodeArgFromProcessArgs();

var cwd = process.cwd();
var argv = process.argv;
var stdout = process.stdout;

var cli = new Cli({
argv: argv,
cwd: cwd,
stdout: stdout
});
}

return cli.getConfiguration()
.then(applyConfigurationAndRun(cli))
.then(exit);
}

return {
getProgram: getProgram,
Expand Down
Loading

0 comments on commit dfdc1d4

Please sign in to comment.