Skip to content

Commit

Permalink
#78 unique (#84)
Browse files Browse the repository at this point in the history
* Addressed #79
  * Updated wdio/ cucumber-framework peer dependency to resolve conflicts.

* Addressed #76
  * Appended current timestamp on generation of feature file
  * fixed failed test

* Addressed #76
  * Appended current timestamp on generation of feature file
  * fixed failed test

* Update package.json

update to proper peerDependencies version

Co-authored-by: Bhaslamb <[email protected]>
Co-authored-by: Wim Selles <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2022
1 parent accfde6 commit da70c99
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
3 changes: 2 additions & 1 deletion lib/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ export class CucumberJsJsonReporter extends WDIOReporter {
* Runner is done, write the file
*/
public onRunnerEnd (): void {
const uniqueId = String( Date.now() + Math.random() ).replace( '.','' );
const jsonFolder = resolve( process.cwd(), this.options.jsonFolder );
const jsonFile = resolve( jsonFolder, `${this.report.feature.id}.json` );
const jsonFile = resolve( jsonFolder, `${this.report.feature.id}_${uniqueId}.json` );
const json = [this.report.feature];
// Check if there is an existing file, if so concat the data, else add the new
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
Expand Down
24 changes: 14 additions & 10 deletions lib/tests/reporter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
TEST_SCENARIO_STATS
} from './__mocks__/mocks';
import { HookStatsExtended, RunnerStatsExtended, SuiteStatsExtended, TestStatsExtended } from '../types/wdio';
import { copySync, readJsonSync, readdirSync, removeSync } from 'fs-extra';
import { readJsonSync, readdirSync, removeSync } from 'fs-extra';
import { Metadata } from '../metadata';
import { Step } from '../models';
import WdioCucumberJsJsonReporter from '../reporter';
Expand Down Expand Up @@ -50,7 +50,8 @@ describe( 'reporter', () => {

describe( 'on create', () => {
it( 'should set the defaults if only the logfile option is provided', () => {
const noOptionsReporter = new WdioCucumberJsJsonReporter( { logFile: path.join( logFolder, logFileName ) } );
const noOptionsReporter = new WdioCucumberJsJsonReporter( { logFile: path.join( logFolder, logFileName )
.replace( '\\','/' ) } );

expect( noOptionsReporter.options ).toMatchSnapshot();
} );
Expand Down Expand Up @@ -254,25 +255,28 @@ describe( 'reporter', () => {
// Clean up
removeSync( jsonFolder );
} );
it( 'should create unique Json file and should not add in existing Json file onRunnerEnd', () => {

it( 'should be able to add json to an existing json output', () => {
const jsonFolder = './.tmp/ut-folder';
const jsonFile = `${jsonFolder}/this-feature.json`;

copySync( 'lib/tests/__mocks__/mock.json', jsonFile );

tmpReporter.report.feature = { id: 'this-feature' };
tmpReporter.options.jsonFolder = jsonFolder;

expect( ( readJsonSync( jsonFile ) as any[] ).length ).toEqual( 1 );

tmpReporter.onRunnerEnd();
tmpReporter.onRunnerEnd();
tmpReporter.onRunnerEnd();
tmpReporter.onRunnerEnd();
tmpReporter.onRunnerEnd();

const files = readdirSync( jsonFolder );

expect( files.length ).toEqual( 1 );
expect( ( readJsonSync( jsonFile ) as any[] ).length ).toEqual( 2 );
expect( files.length ).toEqual( 5 );

for( const jsonFile of files ) {
expect( ( readJsonSync( path.resolve( jsonFolder,jsonFile ) ) as any[] ).length )
.toEqual( 1 );

}
// Clean up
removeSync( jsonFolder );
} );
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"webdriverio": "~7.16.13"
},
"peerDependencies": {
"@wdio/cucumber-framework": "~7.13.2"
"@wdio/cucumber-framework": "7.x"
},
"devDependencies": {
"@types/fs-extra": "^9.0.13",
Expand Down

0 comments on commit da70c99

Please sign in to comment.