From 7c105d090b3ea2bf93970684db5c3f6bacf56395 Mon Sep 17 00:00:00 2001 From: Ilya Date: Mon, 1 Jul 2024 17:09:27 +0300 Subject: [PATCH] EPMRPP-92471 || Fix launch finishing for tests annotated with .skip (#196) --- lib/reporter.js | 11 +++++++---- lib/utils.js | 1 + test/reporter.test.js | 15 --------------- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/lib/reporter.js b/lib/reporter.js index ee1ff0b..96fd4bb 100644 --- a/lib/reporter.js +++ b/lib/reporter.js @@ -54,7 +54,9 @@ class Reporter { this.currentTestTempInfo = null; this.suitesStackTempInfo = []; this.suiteTestCaseIds = new Map(); + // TODO: use a single Map for test info this.pendingTestsIds = []; + // TODO: use a single Map for suite info this.suiteStatuses = new Map(); this.cucumberSteps = new Map(); } @@ -150,6 +152,7 @@ class Reporter { }; if (this.pendingTestsIds.includes(test.id)) { this.testEnd(test); + this.pendingTestsIds = this.pendingTestsIds.filter((id) => id !== test.id); } } @@ -165,10 +168,9 @@ class Reporter { } testEnd(test) { - let testId = this.testItemIds.get(test.id); + const testId = this.testItemIds.get(test.id); if (!testId) { - this.testStart(test); - testId = this.testItemIds.get(test.id); + return; } this.sendLogOnFinishFailedItem(test, testId); this.finishFailedStep(test); @@ -180,12 +182,13 @@ class Reporter { promiseErrorHandler(finishTestItemPromise, 'Fail to finish test'); this.resetCurrentTestFinishParams(); this.currentTestTempInfo = null; + this.testItemIds.delete(test.id); } testPending(test) { // if test has not been started, save test.id to finish in testStart(). // if testStarted() has been called, call testEnd() directly. - if (this.testItemIds.get(test.id) != null) { + if (this.testItemIds.get(test.id)) { this.testEnd(test); } else { this.pendingTestsIds.push(test.id); diff --git a/lib/utils.js b/lib/utils.js index 0f43015..81d8485 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -131,6 +131,7 @@ const getSuiteEndObject = (suite) => ({ endTime: new Date().valueOf(), }); +// TODO: update/split to not return the redundant and confusing data for items start const getTestInfo = (test, testFileName, status, err) => ({ id: test.id, status: status || (test.state === 'pending' ? testItemStatuses.SKIPPED : test.state), diff --git a/test/reporter.test.js b/test/reporter.test.js index 848e1f8..889e3a9 100644 --- a/test/reporter.test.js +++ b/test/reporter.test.js @@ -297,21 +297,6 @@ describe('reporter script', () => { expect(spyFinishTestItem).toHaveBeenCalledWith('tempTestItemId', expectedTestFinishObj); }); - it('end not started test: should call testStart', function () { - const spyTestStart = jest.spyOn(reporter, 'testStart'); - const testInfoObject = { - id: 'testId', - title: 'test name', - status: 'failed', - parentId: 'suiteId', - err: 'error message', - }; - - reporter.testEnd(testInfoObject); - - expect(spyTestStart).toHaveBeenCalled(); - }); - it('end failed test: should call sendLog on test fail', function () { const spySendLogOnFinishFailedItem = jest.spyOn(reporter, 'sendLogOnFinishFailedItem'); const testInfoObject = {