Skip to content

Commit

Permalink
Merge pull request #114 from deckaddict/master
Browse files Browse the repository at this point in the history
Add support to skip uuid as part of feature file path to enable stati…
  • Loading branch information
wswebcreation authored Feb 29, 2020
2 parents 437ef98 + 9121359 commit 9c9eed2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ The directory in which the report needs to be saved, relative from where the scr

**N.B.:** If you use a npm script from the command line, like for example `npm run generate-report` the `reportPath` will be relative from the path where the script is executed. Executing it from the root of your project will also save the report in the `reportPath` in the root of you project.

### `staticFilePath`
- **Type:** `boolean`
- **Mandatory:** No

If true each feature will get a static filename for the html. Use this feature only if you are not running multiple instances of the same tests.

### `openReportInBrowser`
- **Type:** `boolean`
- **Mandatory:** No
Expand Down
6 changes: 5 additions & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ We try to achieve a 100% coverage on the Javascript code. Please make sure that
- clone the project to your local machine
- do a npm install

To create a report use `npm test`. To create a report and also check the coverage use `unit.test.coverage`
To create a report use `npm test`. To create a report and also check the coverage use `unit.test.coverage`

## Documentation

Make any applicable changes to the documentation.
4 changes: 3 additions & 1 deletion lib/generate-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function generateReport(options) {
const pageTitle = options.pageTitle || 'Multiple Cucumber HTML Reporter';
const pageFooter = options.pageFooter || false;
const useCDN = options.useCDN || false;
const staticFilePath = options.staticFilePath || false;

fs.ensureDirSync(reportPath);
fs.ensureDirSync(path.resolve(reportPath, FEATURE_FOLDER));
Expand Down Expand Up @@ -177,7 +178,8 @@ function generateReport(options) {
feature.isNotdefined = false;
feature.isPending = false;
suite.featureCount.total++;
feature.id = `${ uuid() }.${ feature.id }`.replace(/[^a-zA-Z0-9-_]/g, '-');
var idPrefix = staticFilePath ? '' : `${ uuid() }.` ;
feature.id = `${ idPrefix }${ feature.id }`.replace(/[^a-zA-Z0-9-_]/g, '-');
feature.app = 0;
feature.browser = 0;

Expand Down
7 changes: 6 additions & 1 deletion test/unit/generate-json.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ describe('generate-report.js', () => {

expect(fs.statSync(`${path.join(process.cwd(), REPORT_PATH, 'index.html')}`).isFile())
.toEqual(true, 'Index file exists');
expect(function() { fs.statSync(`${path.join(process.cwd(), REPORT_PATH, 'features/happy-flow-v2.html')}`); })
.toThrow();
expect(fs.statSync(`${path.join(process.cwd(), REPORT_PATH, 'merged-output.json')}`).isFile())
.toEqual(true, 'merged-output.json file exists');
expect(fs.statSync(`${path.join(process.cwd(), REPORT_PATH, 'enriched-output.json')}`).isFile())
.toEqual(true, 'temp-output.json file exists');
});
it('should create a report from the merged found json files with custom data', () => {
it('should create a report from the merged found json files with custom data with static file paths', () => {
fs.removeSync(REPORT_PATH);
multiCucumberHTMLReporter.generate({
jsonDir: './test/unit/data/json',
reportPath: REPORT_PATH,
staticFilePath: true,
saveCollectedJSON: true,
reportName: 'You can adjust this report name',
customData: {
Expand All @@ -46,6 +49,8 @@ describe('generate-report.js', () => {

expect(fs.statSync(`${path.join(process.cwd(), REPORT_PATH, 'index.html')}`).isFile())
.toEqual(true, 'Index file exists');
expect(fs.statSync(`${path.join(process.cwd(), REPORT_PATH, 'features/happy-flow-v2.html')}`).isFile())
.toEqual(true, 'uuid free feature exists');
expect(fs.statSync(`${path.join(process.cwd(), REPORT_PATH, 'merged-output.json')}`).isFile())
.toEqual(true, 'merged-output.json file exists');
expect(fs.statSync(`${path.join(process.cwd(), REPORT_PATH, 'enriched-output.json')}`).isFile())
Expand Down

0 comments on commit 9c9eed2

Please sign in to comment.