Skip to content

Commit

Permalink
EPMRPP-95590 || Time with microseconds support
Browse files Browse the repository at this point in the history
  • Loading branch information
AmsterGet committed Oct 1, 2024
1 parent 691486e commit ecac5b0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
35 changes: 18 additions & 17 deletions modules/cucumber-reportportal-formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

const ReportPortalClient = require('@reportportal/client-javascript');
const clientHelpers = require('@reportportal/client-javascript/lib/helpers');
const { Formatter } = require('@cucumber/cucumber');
const stripAnsi = require('strip-ansi');
const utils = require('./utils');
Expand Down Expand Up @@ -110,7 +111,7 @@ const createRPFormatterClass = (config) =>
}
const startLaunchData = {
name: this.config.launch,
startTime: this.reportportal.helpers.now(),
startTime: clientHelpers.now(),
description: this.config.description || '',
attributes,
rerun: this.isRerun,
Expand Down Expand Up @@ -152,7 +153,7 @@ const createRPFormatterClass = (config) =>
const launchTempId = this.storage.getLaunchTempId();
const suiteData = {
name: `${feature.keyword}: ${feature.name}`,
startTime: this.reportportal.helpers.now(),
startTime: clientHelpers.now(),
type: this.isScenarioBasedStatistics ? TEST_ITEM_TYPES.TEST : TEST_ITEM_TYPES.SUITE,
description: (feature.description || '').trim(),
attributes: utils.createAttributes(feature.tags),
Expand All @@ -167,7 +168,7 @@ const createRPFormatterClass = (config) =>
const { tempId, endTime } = this.storage.getFeature(pickleFeatureUri);

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

this.storage.deleteFeature(pickleFeatureUri);
Expand Down Expand Up @@ -203,7 +204,7 @@ const createRPFormatterClass = (config) =>
const childrenIds = children.map((child) => child.scenario.id);
const currentNodeCodeRef = utils.formatCodeRef(featureCodeRef, name);
const testData = {
startTime: this.reportportal.helpers.now(),
startTime: clientHelpers.now(),
type: this.isScenarioBasedStatistics ? TEST_ITEM_TYPES.TEST : TEST_ITEM_TYPES.SUITE,
name: `${keyword}: ${name}`,
description,
Expand Down Expand Up @@ -257,7 +258,7 @@ const createRPFormatterClass = (config) =>
: currentNodeCodeRef;
const scenarioAttributes = utils.createAttributes(scenario.tags);
const testData = {
startTime: this.reportportal.helpers.now(),
startTime: clientHelpers.now(),
type: this.isScenarioBasedStatistics ? TEST_ITEM_TYPES.STEP : TEST_ITEM_TYPES.TEST,
name: `${keyword}: ${name}`,
description: scenario.description,
Expand Down Expand Up @@ -311,7 +312,7 @@ const createRPFormatterClass = (config) =>

const stepData = {
name: keyword ? `${keyword} ${name}` : name,
startTime: this.reportportal.helpers.now(),
startTime: clientHelpers.now(),
type,
codeRef,
hasStats: !this.isScenarioBasedStatistics,
Expand Down Expand Up @@ -396,7 +397,7 @@ const createRPFormatterClass = (config) =>

case 'text/plain': {
const request = {
time: this.reportportal.helpers.now(),
time: clientHelpers.now(),
};
let tempId = this.storage.getStepTempId(testStepId);

Expand All @@ -419,7 +420,7 @@ const createRPFormatterClass = (config) =>
default: {
const fileName = 'file'; // TODO: generate human valuable file name here if possible
const request = {
time: this.reportportal.helpers.now(),
time: clientHelpers.now(),
level: LOG_LEVELS.INFO,
message: fileName,
file: {
Expand Down Expand Up @@ -468,7 +469,7 @@ const createRPFormatterClass = (config) =>
}
case STATUSES.PENDING: {
this.reportportal.sendLog(tempStepId, {
time: this.reportportal.helpers.now(),
time: clientHelpers.now(),
level: LOG_LEVELS.WARN,
message: TEST_STEP_FINISHED_RP_MESSAGES.PENDING,
});
Expand All @@ -477,7 +478,7 @@ const createRPFormatterClass = (config) =>
}
case STATUSES.UNDEFINED: {
this.reportportal.sendLog(tempStepId, {
time: this.reportportal.helpers.now(),
time: clientHelpers.now(),
level: LOG_LEVELS.ERROR,
message: TEST_STEP_FINISHED_RP_MESSAGES.UNDEFINED,
});
Expand All @@ -486,7 +487,7 @@ const createRPFormatterClass = (config) =>
}
case STATUSES.AMBIGUOUS: {
this.reportportal.sendLog(tempStepId, {
time: this.reportportal.helpers.now(),
time: clientHelpers.now(),
level: LOG_LEVELS.ERROR,
message: TEST_STEP_FINISHED_RP_MESSAGES.AMBIGUOUS,
});
Expand All @@ -500,7 +501,7 @@ const createRPFormatterClass = (config) =>
case STATUSES.FAILED: {
status = STATUSES.FAILED;
this.reportportal.sendLog(tempStepId, {
time: this.reportportal.helpers.now(),
time: clientHelpers.now(),
level: LOG_LEVELS.ERROR,
message: stripAnsi(testStepResult.message),
});
Expand All @@ -515,7 +516,7 @@ const createRPFormatterClass = (config) =>
const screenshotName = utils.getScreenshotName(astNodesData, step.astNodeIds);

const request = {
time: this.reportportal.helpers.now(),
time: clientHelpers.now(),
level: LOG_LEVELS.ERROR,
file: { name: screenshotName },
message: screenshotName,
Expand Down Expand Up @@ -556,7 +557,7 @@ const createRPFormatterClass = (config) =>
...(descriptionToSend && { description: descriptionToSend }),
...(customTestCaseId && { testCaseId: customTestCaseId }),
...(withoutIssue && { issue: { issueType: 'NOT_ISSUE' } }),
endTime: this.reportportal.helpers.now(),
endTime: clientHelpers.now(),
});
}

Expand Down Expand Up @@ -585,7 +586,7 @@ const createRPFormatterClass = (config) =>
} = this.storage.getScenario(testCaseId);

this.reportportal.finishTestItem(scenarioTempId, {
endTime: this.reportportal.helpers.now(),
endTime: clientHelpers.now(),
...(this.isScenarioBasedStatistics && {
status: scenarioStatus || testCase.status || STATUSES.PASSED,
}),
Expand All @@ -605,7 +606,7 @@ const createRPFormatterClass = (config) =>

if (ruleTempId && isAllRuleChildrenStarted) {
this.reportportal.finishTestItem(ruleTempId, {
endTime: this.reportportal.helpers.now(),
endTime: clientHelpers.now(),
});

this.storage.removeRuleTempIdToTestCase(testCaseStartedId);
Expand All @@ -622,7 +623,7 @@ const createRPFormatterClass = (config) =>
}

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

onTestRunFinishedEvent() {
Expand Down
2 changes: 2 additions & 0 deletions tests/cucumber-reportportal-formatter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

const helpers = require('@reportportal/client-javascript/lib/helpers');
const { createRPFormatterClass } = require('../modules');
const { RPClientMock, getDefaultConfig, mockedDate } = require('./mocks');
const Storage = require('../modules/storage');
Expand Down Expand Up @@ -51,6 +52,7 @@ const {
} = require('../modules/constants');

describe('cucumber-reportportal-formatter', () => {
jest.spyOn(helpers, 'now').mockReturnValue(mockedDate);
const config = getDefaultConfig();
const FormatterClass = createRPFormatterClass(config);
const formatter = new FormatterClass({
Expand Down
5 changes: 1 addition & 4 deletions tests/mocks.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
const mockedDate = Date.now();
const mockedDate = '2024-09-23T12:20:59.392987Z';

class RPClientMock {
constructor(config) {
this.config = config;
this.helpers = {
now: () => mockedDate,
};

this.startLaunch = jest.fn().mockReturnValue({
promise: Promise.resolve('ok'),
Expand Down
1 change: 0 additions & 1 deletion tests/storage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
const Storage = require('../modules/storage');
const {
launchTempId,
gherkinDocument,
feature,
pickleId,
uri,
Expand Down

0 comments on commit ecac5b0

Please sign in to comment.