Skip to content

Commit

Permalink
EPMRPP-88826 || Code Review fixes - 1
Browse files Browse the repository at this point in the history
  • Loading branch information
AliakseiLiasnitski committed May 8, 2024
1 parent e1d3b50 commit 253ef30
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 82 deletions.
24 changes: 11 additions & 13 deletions modules/cucumber-reportportal-formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const createRPFormatterClass = (config) =>
}

onGherkinDocumentEvent(data) {
this.storage.setDocument(data);
this.storage.setFeature(data.uri, data.feature);
this.storage.setAstNodesData(data, utils.findAstNodesData(data.feature.children));
}

Expand Down Expand Up @@ -146,7 +146,7 @@ const createRPFormatterClass = (config) =>
this.storage.setSteps(testCaseId, stepsMap);
}

suiteStart({ pickleFeatureUri, feature }) {
startFeature({ pickleFeatureUri, feature }) {
if (this.storage.getFeatureTempId(pickleFeatureUri)) return;

const launchTempId = this.storage.getLaunchTempId();
Expand All @@ -160,19 +160,17 @@ const createRPFormatterClass = (config) =>
};

const { tempId } = this.reportportal.startTestItem(suiteData, launchTempId);
this.storage.setFeatureTempId(pickleFeatureUri, tempId);
this.storage.updateFeature(pickleFeatureUri, { tempId });
}

suiteEnd(pickleFeatureUri) {
const featureTempId = this.storage.getFeatureTempId(pickleFeatureUri);
const featureEndTime = this.storage.getFeatureEndTime(pickleFeatureUri);
finishFeature(pickleFeatureUri) {
const { tempId, endTime } = this.storage.getFeature(pickleFeatureUri);

this.reportportal.finishTestItem(featureTempId, {
endTime: featureEndTime || this.reportportal.helpers.now(),
this.reportportal.finishTestItem(tempId, {
endTime: endTime || this.reportportal.helpers.now(),
});

this.storage.deleteFeatureTempId(pickleFeatureUri);
this.storage.deleteFeatureEndTime(pickleFeatureUri);
this.storage.deleteFeature(pickleFeatureUri);
}

onTestCaseStartedEvent(data) {
Expand All @@ -187,7 +185,7 @@ const createRPFormatterClass = (config) =>
const feature = this.storage.getFeature(pickleFeatureUri);
const launchTempId = this.storage.getLaunchTempId();
const featureCodeRef = utils.formatCodeRef(pickleFeatureUri, feature.name);
this.suiteStart({ pickleFeatureUri, feature });
this.startFeature({ pickleFeatureUri, feature });

// current feature node rule(this entity is for grouping several
// scenarios in one logical block) || scenario
Expand Down Expand Up @@ -581,13 +579,13 @@ const createRPFormatterClass = (config) =>
}

const { uri: pickleFeatureUri } = this.storage.getPickle(testCase.pickleId);
this.storage.setFeatureEndTime(pickleFeatureUri, this.reportportal.helpers.now());
this.storage.updateFeature(pickleFeatureUri, { endTime: this.reportportal.helpers.now() });
}

onTestRunFinishedEvent() {
const featureUris = this.storage.getActiveFeatureUris();
featureUris.forEach((featureUri) => {
this.suiteEnd(featureUri);
this.finishFeature(featureUri);
});

const launchId = this.storage.getLaunchTempId();
Expand Down
48 changes: 15 additions & 33 deletions modules/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
module.exports = class Storage {
constructor() {
this.launchTempId = null;
this.featureTempIds = new Map();
this.featureEndTime = new Map();
this.documents = new Map();
this.features = new Map();
this.pickles = new Map();
this.hooks = new Map();
this.testCases = new Map();
Expand All @@ -43,20 +41,6 @@ module.exports = class Storage {
return this.launchTempId;
}

setDocument(gherkinDocument) {
this.documents.set(gherkinDocument.uri, gherkinDocument);
}

getDocument(uri) {
return this.documents.get(uri);
}

getFeature(uri) {
const document = this.getDocument(uri);

return document && document.feature;
}

setPickle(pickle) {
this.pickles.set(pickle.id, pickle);
}
Expand Down Expand Up @@ -131,32 +115,30 @@ module.exports = class Storage {
return this.parameters.get(id);
}

setFeatureTempId(id, value) {
this.featureTempIds.set(id, value);
updateFeature(id, newData) {
const feature = this.features.get(id) || {};
this.features.set(id, { ...feature, ...newData });
}

getFeatureTempId(id) {
return this.featureTempIds.get(id);
}

deleteFeatureTempId(id) {
this.featureTempIds.delete(id);
getFeature(id) {
return this.features.get(id);
}

getActiveFeatureUris() {
return Array.from(this.featureTempIds.keys());
setFeature(id, feature) {
this.features.set(id, feature);
}

getFeatureEndTime(id) {
return this.featureEndTime.get(id);
deleteFeature(id) {
this.features.delete(id);
}

setFeatureEndTime(id, time) {
this.featureEndTime.set(id, time);
getFeatureTempId(id) {
const feature = this.features.get(id);
return feature && feature.tempId;
}

deleteFeatureEndTime(id) {
this.featureEndTime.delete(id);
getActiveFeatureUris() {
return Array.from(this.features.keys());
}

setScenarioTempId(testCaseStartedId, scenarioTempId) {
Expand Down
12 changes: 6 additions & 6 deletions tests/cucumber-reportportal-formatter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ describe('cucumber-reportportal-formatter', () => {
beforeEach(() => {
formatter.onGherkinDocumentEvent(gherkinDocument);
});
it('should set document to storage', () => {
expect(formatter.storage.getDocument(uri)).toBe(gherkinDocument);
it('should set feature to storage', () => {
expect(formatter.storage.getFeature(uri)).toBe(gherkinDocument.feature);
});

it('should set document feature.children', () => {
Expand Down Expand Up @@ -792,12 +792,12 @@ describe('cucumber-reportportal-formatter', () => {
});
});

describe('suiteStart', () => {
describe('startFeature', () => {
it('startTestItem should be called', () => {
const spyStartTestItem = jest.spyOn(formatter.reportportal, 'startTestItem');
formatter.storage.setLaunchTempId(launchTempId);

formatter.suiteStart({ pickleFeatureUri: uri, feature });
formatter.startFeature({ pickleFeatureUri: uri, feature });

expect(spyStartTestItem).lastCalledWith(
{
Expand All @@ -814,9 +814,9 @@ describe('cucumber-reportportal-formatter', () => {

it('should be skipped if suite is already running', () => {
const spyStartTestItem = jest.spyOn(formatter.reportportal, 'startTestItem');
formatter.storage.setFeatureTempId(uri, featureTempId);
formatter.storage.setFeature(uri, { tempId: featureTempId });

formatter.suiteStart({ pickleFeatureUri: uri, feature });
formatter.startFeature({ pickleFeatureUri: uri, feature });

expect(spyStartTestItem).not.toHaveBeenCalled();
});
Expand Down
39 changes: 9 additions & 30 deletions tests/storage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@ describe('test Storage', () => {
expect(storage.getLaunchTempId()).toBe(launchTempId);
});

it('set/getDocument', () => {
storage.setDocument(gherkinDocument);
it('set/getFeature', () => {
storage.setFeature(uri, feature);

expect(storage.getDocument(uri)).toEqual(gherkinDocument);
expect(storage.getFeature(uri)).toEqual(feature);
});

it('set/getFeature', () => {
storage.setDocument(gherkinDocument);
it('set/deleteFeature', () => {
storage.setFeature(uri, feature);
storage.deleteFeature(uri);

expect(storage.getFeature(uri)).toEqual(feature);
expect(storage.getFeature(uri)).toBeUndefined();
});

it('set/getPickle', () => {
Expand Down Expand Up @@ -135,39 +136,17 @@ describe('test Storage', () => {
});

it('set/getFeatureTempId', () => {
storage.setFeatureTempId(uri, featureTempId);
storage.setFeature(uri, { tempId: featureTempId });

expect(storage.getFeatureTempId(uri)).toBe(featureTempId);
});

it('set/deleteFeatureTempId', () => {
storage.setFeatureTempId(uri, featureTempId);
storage.deleteFeatureTempId(uri);

expect(storage.getFeatureTempId(uri)).toBeUndefined();
});

it('set/getActiveFeatureUris', () => {
storage.setFeatureTempId(uri, featureTempId);
storage.setFeature(uri, feature);

expect(storage.getActiveFeatureUris()).toEqual([uri]);
});

it('set/getFeatureEndTime', () => {
const date = Date.now();
storage.setFeatureEndTime(uri, date);

expect(storage.getFeatureEndTime(uri)).toBe(date);
});

it('set/deleteFeatureEndTime', () => {
const date = Date.now();
storage.setFeatureEndTime(uri, date);
storage.deleteFeatureEndTime(uri);

expect(storage.getFeatureEndTime(uri)).toBeUndefined();
});

it('set/getScenarioTempId', () => {
storage.setScenarioTempId(testCaseStartedId, scenarioTempId);

Expand Down

0 comments on commit 253ef30

Please sign in to comment.