Skip to content

Commit 7253eeb

Browse files
authored
Release 5.1.3 (#161)
* 5.1.2 -> 5.1.3-SNAPSHOT * EPMRPP-100661 || Fix item temp ids processing to avoid name collisions (#160) * Update changelog --------- Co-authored-by: reportportal.io <reportportal.io>
2 parents d90d3b5 + bfb2e44 commit 7253eeb

File tree

8 files changed

+66
-87
lines changed

8 files changed

+66
-87
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### Fixed
2+
- Fix test name collisions. Resolves [#153](https://github.com/reportportal/agent-js-jest/issues/153), [#155](https://github.com/reportportal/agent-js-jest/issues/155), [#147](https://github.com/reportportal/agent-js-jest/issues/147).
3+
- `ReportingApi.attachment` error with `sendLog` method.
14

25
## [5.1.2] - 2025-01-30
36
### Fixed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.1.2
1+
5.1.3-SNAPSHOT

__tests__/mocks/data.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const skippedTestResult = {
1717
status: TEST_ITEM_STATUSES.SKIPPED,
1818
ancestorTitles: ['Skipped suite name', 'Skipped test name'],
1919
failureMessages: [],
20-
invocations: 2,
2120
};
2221
const testResult = {
2322
testResults: [failedTestResult],

__tests__/reporter.spec.js

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -119,50 +119,24 @@ describe('Reporter', () => {
119119
expect(spyStartSuites).toHaveBeenCalledTimes(0);
120120
});
121121

122-
test('should start and finish retries in case of any invocations of skipped tests', () => {
122+
test('should start and finish skipped tests', () => {
123123
const spyStartStep = jest.spyOn(reporter, '_startStep');
124124
const spyFinishStep = jest.spyOn(reporter, '_finishStep');
125125

126-
reporter.onTestResult(testObj, testResultWithSkipped);
127-
const skippedTestResultWithStartedAt = { startedAt: currentDateInMs, ...skippedTestResult };
128-
129-
expect(spyStartStep).toHaveBeenNthCalledWith(
130-
1,
131-
skippedTestResultWithStartedAt,
132-
testObj.path,
133-
false,
134-
);
135-
expect(spyStartStep).toHaveBeenNthCalledWith(
136-
2,
137-
skippedTestResultWithStartedAt,
138-
testObj.path,
139-
true,
140-
);
141-
expect(spyFinishStep).toHaveBeenCalledWith(skippedTestResultWithStartedAt);
142-
expect(spyStartStep).toHaveBeenCalledTimes(2);
143-
expect(spyFinishStep).toHaveBeenCalledTimes(2);
144-
});
145-
146-
test('should start and finish just skipped test in case of no or empty invocations', () => {
147-
const spyStartStep = jest.spyOn(reporter, '_startStep');
148-
const spyFinishStep = jest.spyOn(reporter, '_finishStep');
149-
150-
const { invocations, ...skippedTestResultWithoutInvocations } = skippedTestResult;
151-
152126
const testResult = {
153-
testResults: [skippedTestResultWithoutInvocations],
127+
testResults: [skippedTestResult],
154128
testFilePath,
155129
};
156130

157131
reporter.onTestResult(testObj, testResult);
158132

159133
const skippedTestResultWithStartedAt = {
160134
startedAt: currentDateInMs,
161-
...skippedTestResultWithoutInvocations,
135+
...skippedTestResult,
162136
};
163137

164138
expect(spyStartStep).toHaveBeenCalledWith(skippedTestResultWithStartedAt, testObj.path);
165-
expect(spyFinishStep).toHaveBeenCalledWith(skippedTestResultWithStartedAt);
139+
expect(spyFinishStep).toHaveBeenCalledWith(skippedTestResultWithStartedAt, testObj.path);
166140
expect(spyStartStep).toHaveBeenCalledTimes(1);
167141
expect(spyFinishStep).toHaveBeenCalledTimes(1);
168142
});
@@ -312,7 +286,7 @@ describe('Reporter', () => {
312286
startTime: currentDateInMs,
313287
retry: false,
314288
};
315-
const expectedTempStepIds = new Map([['Suite/Step', 'startTestItem']]);
289+
const expectedTempStepIds = new Map([['example.js/Suite/Step', ['startTestItem']]]);
316290

317291
expect(reporter.client.startTestItem).toHaveBeenCalledWith(
318292
expectedStartStepItemParameter,
@@ -343,19 +317,24 @@ describe('Reporter', () => {
343317
});
344318

345319
describe('_finishStep', () => {
320+
beforeEach(() => {
321+
reporter.tempStepIds.set('example.js/suite/fake test', ['tempStepId']);
322+
});
323+
346324
test('_finishPassedTest should be called if step status is passed', () => {
347325
const spyFinishPassedTest = jest.spyOn(reporter, '_finishPassedStep');
348326
const spyFinishFailedTest = jest.spyOn(reporter, '_finishFailedStep');
349327
const spyFinishSkippedTest = jest.spyOn(reporter, '_finishSkippedStep');
350328

351-
reporter.tempStepIds.set('/fake test', 'tempStepId');
352-
353-
reporter._finishStep({
354-
status: TEST_ITEM_STATUSES.PASSED,
355-
failureMessages: [],
356-
ancestorTitles: [],
357-
title: 'fake test',
358-
});
329+
reporter._finishStep(
330+
{
331+
status: TEST_ITEM_STATUSES.PASSED,
332+
failureMessages: [],
333+
ancestorTitles: ['suite'],
334+
title: 'fake test',
335+
},
336+
testFilePath,
337+
);
359338

360339
expect(spyFinishPassedTest).toHaveBeenCalled();
361340
expect(spyFinishFailedTest).not.toHaveBeenCalled();
@@ -367,16 +346,14 @@ describe('Reporter', () => {
367346
const spyFinishFailedTest = jest.spyOn(reporter, '_finishFailedStep');
368347
const spyFinishSkippedTest = jest.spyOn(reporter, '_finishSkippedStep');
369348

370-
reporter.tempStepIds.set('/fake test', 'tempStepId');
371-
372349
reporter._finishStep(
373350
{
374351
status: TEST_ITEM_STATUSES.FAILED,
375352
failureMessages: ['error message'],
376-
ancestorTitles: [],
353+
ancestorTitles: ['suite'],
377354
title: 'fake test',
378355
},
379-
false,
356+
testFilePath,
380357
);
381358

382359
expect(spyFinishFailedTest).toHaveBeenCalledWith('tempStepId', 'error message');
@@ -389,14 +366,15 @@ describe('Reporter', () => {
389366
const spyFinishFailedTest = jest.spyOn(reporter, '_finishFailedStep');
390367
const spyFinishSkippedTest = jest.spyOn(reporter, '_finishSkippedStep');
391368

392-
reporter.tempStepIds.set('/fake test', 'tempStepId');
393-
394-
reporter._finishStep({
395-
status: TEST_ITEM_STATUSES.SKIPPED,
396-
failureMessages: [],
397-
ancestorTitles: [],
398-
title: 'fake test',
399-
});
369+
reporter._finishStep(
370+
{
371+
status: TEST_ITEM_STATUSES.SKIPPED,
372+
failureMessages: [],
373+
ancestorTitles: ['suite'],
374+
title: 'fake test',
375+
},
376+
testFilePath,
377+
);
400378

401379
expect(spyFinishSkippedTest).toHaveBeenCalled();
402380
expect(spyFinishPassedTest).not.toHaveBeenCalled();

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"strip-ansi": "^6.0.1"
2727
},
2828
"devDependencies": {
29-
"@types/jest": "^29.5.12",
29+
"@types/jest": "^29.5.14",
3030
"jest": "^29.7.0",
3131
"eslint": "^8.57.0",
3232
"eslint-config-airbnb-base": "^15.0.0",

src/reporter.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -75,36 +75,24 @@ class JestReportPortal {
7575
onTestCaseStart(test, testCaseStartInfo) {
7676
this._startSuites(testCaseStartInfo.ancestorTitles, test.path, testCaseStartInfo.startedAt);
7777

78-
const isRetried = !!this.tempStepIds.get(getFullStepName(testCaseStartInfo));
79-
this._startStep(testCaseStartInfo, test.path, isRetried);
78+
this._startStep(testCaseStartInfo, test.path);
8079
}
8180

8281
// TODO: cover with tests
8382
// Not called for `skipped` and `todo` specs
8483
onTestCaseResult(test, testCaseStartInfo) {
85-
this._finishStep(testCaseStartInfo);
84+
this._finishStep(testCaseStartInfo, test.path);
8685
}
8786

8887
onTestResult(test, testResult) {
8988
// Handling `skipped` tests and their ancestors
90-
const skippedTests = testResult.testResults.filter(
91-
(t) => t.status === TEST_ITEM_STATUSES.SKIPPED,
92-
);
93-
94-
skippedTests.forEach((testCaseInfo) => {
95-
const testCaseWithStartTime = { startedAt: new Date().valueOf(), ...testCaseInfo };
96-
this._startSuites(testCaseInfo.ancestorTitles, test.path, testCaseWithStartTime.startedAt);
97-
98-
if (testCaseWithStartTime.invocations) {
99-
for (let i = 0; i < testCaseWithStartTime.invocations; i++) {
100-
const isRetried = i > 0;
89+
testResult.testResults.forEach((testCaseInfo) => {
90+
if (testCaseInfo.status === TEST_ITEM_STATUSES.SKIPPED) {
91+
const testCaseWithStartTime = { startedAt: new Date().valueOf(), ...testCaseInfo };
92+
this._startSuites(testCaseInfo.ancestorTitles, test.path, testCaseWithStartTime.startedAt);
10193

102-
this._startStep(testCaseWithStartTime, test.path, isRetried);
103-
this._finishStep(testCaseWithStartTime);
104-
}
105-
} else {
10694
this._startStep(testCaseWithStartTime, test.path);
107-
this._finishStep(testCaseWithStartTime);
95+
this._finishStep(testCaseWithStartTime, test.path);
10896
}
10997
});
11098

@@ -152,9 +140,12 @@ class JestReportPortal {
152140
this.promises.push(promise);
153141
}
154142

155-
_startStep(test, testPath, isRetried = false) {
143+
_startStep(test, testPath) {
156144
const fullStepName = getFullStepName(test);
157145
const codeRef = getCodeRef(testPath, fullStepName);
146+
const retryIds = this.tempStepIds.get(codeRef);
147+
const isRetried = !!retryIds;
148+
158149
const stepStartObj = {
159150
type: TEST_ITEM_TYPES.STEP,
160151
name: test.title,
@@ -172,24 +163,32 @@ class JestReportPortal {
172163
this.tempLaunchId,
173164
parentId,
174165
);
166+
// store item ids as array to not overwrite retry ids
167+
let tempIdToStore = [tempId];
168+
169+
if (isRetried) {
170+
tempIdToStore = retryIds.concat(tempIdToStore);
171+
}
175172

176-
this.tempStepIds.set(fullStepName, tempId);
173+
this.tempStepIds.set(codeRef, tempIdToStore);
177174
this.tempStepId = tempId;
178175
promiseErrorHandler(promise);
179176
this.promises.push(promise);
180177
}
181178

182-
_finishStep(test) {
183-
const errorMsg = test.failureMessages[0];
184-
179+
_finishStep(test, testPath) {
185180
const fullName = getFullStepName(test);
186-
const tempStepId = this.tempStepIds.get(fullName);
181+
const codeRef = getCodeRef(testPath, fullName);
182+
const tempStepIds = this.tempStepIds.get(codeRef);
183+
const tempStepId = Array.isArray(tempStepIds) ? tempStepIds.shift() : undefined;
187184

188-
if (tempStepId === undefined) {
189-
console.error(`Could not finish Test Step - "${fullName}". tempId not found`);
185+
if (!tempStepId) {
186+
console.error(`Could not finish Test Step - "${codeRef}". tempId not found`);
190187
return;
191188
}
192189

190+
const errorMsg = test.failureMessages[0];
191+
193192
switch (test.status) {
194193
case TEST_ITEM_STATUSES.PASSED:
195194
this._finishPassedStep(tempStepId);

src/reportingApi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ module.exports = class ReportingApi {
3434
* @param {String} description - file description (optional).
3535
*/
3636
attachment(file, description) {
37-
this.reporter.sendLog({ message: description, file });
37+
this.reporter._sendLog({ message: description, file });
3838
}
3939
};

0 commit comments

Comments
 (0)