Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to ignore bad json files when reading the jsondir #13

Merged
merged 4 commits into from
Sep 8, 2016
Merged
Show file tree
Hide file tree
Changes from 3 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
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) {
Copy link
Owner

Choose a reason for hiding this comment

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

Can you add parenthesis to the both if & else conditions?

if ((!cucumberJson || typeof cucumberJson[0] === 'undefined') && !options.ignoreBadJsonFile) 

Because it will throw Error even if options.ignoreBadJsonFile = false but if cucumberJson isn't valid object.

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