diff --git a/lib/gui/tool-runner/index.ts b/lib/gui/tool-runner/index.ts index 2b771d897..b21d002ce 100644 --- a/lib/gui/tool-runner/index.ts +++ b/lib/gui/tool-runner/index.ts @@ -173,8 +173,12 @@ export class ToolRunner { return Promise.all(tests.map(async (test): Promise => { const updateResult = this._createTestplaneTestResult(test); - const currentResult = formatTestResult(updateResult, UPDATED, test.attempt); - const estimatedStatus = reportBuilder.getUpdatedReferenceTestStatus(currentResult); + const latestAttempt = reportBuilder.getLatestAttempt({ + fullName: updateResult.fullTitle(), + browserId: updateResult.browserId + }); + const latestResult = formatTestResult(updateResult, UPDATED, latestAttempt); + const estimatedStatus = reportBuilder.getUpdatedReferenceTestStatus(latestResult); const formattedResultWithoutAttempt = formatTestResult(updateResult, UPDATED); const formattedResult = reportBuilder.provideAttempt(formattedResultWithoutAttempt); diff --git a/lib/report-builder/static.ts b/lib/report-builder/static.ts index af2ddc6de..141d82cf1 100644 --- a/lib/report-builder/static.ts +++ b/lib/report-builder/static.ts @@ -75,6 +75,10 @@ export class StaticReportBuilder { this._workers = workers; } + getLatestAttempt(testInfo: {fullName: string, browserId: string}): number { + return this._testAttemptManager.getCurrentAttempt(testInfo); + } + /** If passed test result doesn't have attempt, this method registers new attempt and sets attempt number */ provideAttempt(testResultOriginal: ReporterTestResult): ReporterTestResult { let formattedResult = testResultOriginal; diff --git a/test/unit/lib/gui/tool-runner/index.js b/test/unit/lib/gui/tool-runner/index.js index 527921690..9488cc353 100644 --- a/test/unit/lib/gui/tool-runner/index.js +++ b/test/unit/lib/gui/tool-runner/index.js @@ -299,6 +299,44 @@ describe('lib/gui/tool-runner/index', () => { state: 'plain2' }); }); + + it('should determine status based on the latest result', async () => { + const testRefUpdateData = [{ + id: 'some-id', + fullTitle: () => 'some-title', + browserId: 'yabro', + suite: {path: ['suite1']}, + state: {}, + metaInfo: {}, + imagesInfo: [{ + status: UPDATED, + stateName: 'plain1', + actualImg: { + size: {height: 100, width: 200} + } + }] + }]; + + const getScreenshotPath = sandbox.stub().returns('/ref/path1'); + const config = stubConfig({ + browsers: {yabro: {getScreenshotPath}} + }); + + const testCollection = mkTestCollection_({'some-title.yabro': testRefUpdateData[0]}); + const toolAdapter = stubToolAdapter({config, testCollection}); + + reportBuilder.getLatestAttempt.withArgs({fullName: 'some-title', browserId: 'yabro'}).returns(100500); + reportBuilder.getUpdatedReferenceTestStatus.withArgs(sinon.match({attempt: 100500})).returns(TestStatus.UPDATED); + + const gui = initGuiReporter({toolAdapter}); + await gui.initialize(); + + reportBuilder.addTestResult.reset(); + + await gui.updateReferenceImage(testRefUpdateData); + + assert.calledOnceWith(reportBuilder.addTestResult, sinon.match.any, {status: TestStatus.UPDATED}); + }); }); describe('undoAcceptImages', () => {