Skip to content

Commit

Permalink
Added option to ignore bad json files when reading the jsondir (#13)
Browse files Browse the repository at this point in the history
* added option to ignore bad json files

* added option to ignore bad json files and updated readme

* added option to ignore bad json files and updated readme

* taken care of review comments
  • Loading branch information
thyagab authored and gkushang committed Sep 8, 2016
1 parent e39ba02 commit e6d2786
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ var options = {
jsonFile: 'test/report/cucumber_report.json',
output: 'test/report/cucumber_report.html',
reportSuiteAsScenarios: true,
launchReport: true
launchReport: true,
ignoreBadJsonFile:true
};

reporter.generate(options);

//to generate consodilated report from multi-cucumber JSON files, please use `jsonDir` option instead of `jsonFile`. More info is available in `options` section below.

```
Expand All @@ -60,15 +61,15 @@ var options = {
$ cucumberjs test/features/ -f json:test/report/cucumber_report.json
```

> Multiple formatter are also supported,
> Multiple formatter are also supported,
```
$ cucumberjs test/features/ -f pretty -f json:test/report/cucumber_report.json
```

> Are you using cucumber with other frameworks or running [cucumber-parallel][6]? Pass relative path of JSON file to the `options` as shown [here][7]

## Options

#### `theme`
Expand Down Expand Up @@ -102,7 +103,7 @@ Provide HTML output file path and name

#### `reportSuiteAsScenarios`
Type: `Boolean`
Supported in the Bootstrap theme.
Supported in the Bootstrap theme.

`true`: Reports total number of passed/failed scenarios as HEADER.

Expand All @@ -117,6 +118,15 @@ Automatically launch HTML report at the end of test suite

`false`: Do not launch HTML report at the end of test suite

#### `ignoreBadJsonFile`
Type: `Boolean`

Report any bad json files found during merging json files from directory option.

`true`: ignore any bad json files found and continue with remaining files to merge.

`false`: Default option. Fail report generation if any bad files found during merge.


## Tips

Expand All @@ -125,31 +135,31 @@ Automatically launch HTML report at the end of test suite
Capture and Attach screenshots to the Cucumber Scenario and HTML report will render the screenshot image

```javascript

driver.takeScreenshot().then(function (buffer) {
return scenario.attach(new Buffer(buffer, 'base64'), 'image/png');
}

```
#### Attach Plain Text to HTML report
Attach plain-texts/data to HTML report to help debug/review the results
```javascript

scenario.attach('test data goes here');

```
#### Attach pretty JSON to HTML report
Attach JSON to HTML report
```javascript

scenario.attach(JSON.stringity(myJsonObject, undefined, 4));

```
## Credits
Expand All @@ -163,4 +173,3 @@ Credit to the developers of [grunt-cucumberjs][1] for developing pretty HTML rep
[5]: http://htmlpreview.github.io/?https://github.com/gkushang/grunt-cucumberjs/blob/cucumber-reports/test/cucumber-reports/cucumber-report-simple.html "Simple Theme Reports"
[6]: https://www.npmjs.com/package/cucumber-parallel "cucumber-parallel"
[7]: https://github.com/gkushang/cucumber-html-reporter/blob/develop/test/features/step_definitions/hooks.js#L13-L44
7 changes: 5 additions & 2 deletions lib/jsonDir.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ var collectJSONS = function(options) {
jsonOutput.push(json);
}

if (!cucumberJson || typeof cucumberJson[0] === 'undefined') {
if ((!cucumberJson || typeof cucumberJson[0] === 'undefined') && !options.ignoreBadJsonFile) {
throw new Error('Invalid Cucumber JSON file found under ' + options.jsonDir + ': ' + file);
} else {
} else if ((!cucumberJson || typeof cucumberJson[0] === 'undefined') && options.ignoreBadJsonFile) {
console.log('Invalid Cucumber JSON file found under ' + options.jsonDir + ': ' + file);
}
else {
cucumberJson.map(collect)
}
}
Expand Down

0 comments on commit e6d2786

Please sign in to comment.