From 057aac046c224d3604be8b00d710b0c18aed80c2 Mon Sep 17 00:00:00 2001 From: shadowusr Date: Thu, 2 Nov 2023 00:34:03 +0300 Subject: [PATCH] test: fix unit tests --- lib/config/custom-gui-asserts.ts | 2 +- lib/gui/constants/index.ts | 4 ++ lib/gui/{event-source.js => event-source.ts} | 14 ++--- lib/gui/tool-runner/index.js | 6 +- ...ort-subscriber.js => report-subscriber.ts} | 60 ++++++++++--------- lib/report-builder/gui.ts | 2 +- lib/tests-tree-builder/gui.ts | 5 +- package.json | 3 + test/unit/lib/gui/tool-runner/index.js | 43 ++++--------- .../lib/gui/tool-runner/report-subsciber.js | 32 +++++----- test/unit/lib/report-builder/gui.js | 41 +++++-------- test/unit/lib/tests-tree-builder/base.js | 1 + test/unit/lib/tests-tree-builder/gui.js | 10 ++-- test/unit/lib/tests-tree-builder/static.js | 3 +- 14 files changed, 104 insertions(+), 122 deletions(-) create mode 100644 lib/gui/constants/index.ts rename lib/gui/{event-source.js => event-source.ts} (58%) rename lib/gui/tool-runner/{report-subscriber.js => report-subscriber.ts} (61%) diff --git a/lib/config/custom-gui-asserts.ts b/lib/config/custom-gui-asserts.ts index 884ed9346..f049c360d 100644 --- a/lib/config/custom-gui-asserts.ts +++ b/lib/config/custom-gui-asserts.ts @@ -1,5 +1,5 @@ import {isUndefined, isArray, isEmpty, isFunction, isPlainObject, isString} from 'lodash'; -import CustomGuiControlTypes from '../gui/constants/custom-gui-control-types'; +import * as CustomGuiControlTypes from '../gui/constants/custom-gui-control-types'; const SUPPORTED_CONTROL_TYPES: string[] = Object.values(CustomGuiControlTypes); diff --git a/lib/gui/constants/index.ts b/lib/gui/constants/index.ts new file mode 100644 index 000000000..a6a5b519a --- /dev/null +++ b/lib/gui/constants/index.ts @@ -0,0 +1,4 @@ +export * from './client-events'; +export * from './custom-gui-control-types'; +export * from './gui-events'; +export * from './server'; diff --git a/lib/gui/event-source.js b/lib/gui/event-source.ts similarity index 58% rename from lib/gui/event-source.js rename to lib/gui/event-source.ts index 6a1066e91..7d033fb4a 100644 --- a/lib/gui/event-source.js +++ b/lib/gui/event-source.ts @@ -1,21 +1,21 @@ -'use strict'; +import {Response} from 'express'; +import stringify from 'json-stringify-safe'; -const stringify = require('json-stringify-safe'); - -module.exports = class EventSource { +export class EventSource { + private _connections: Response[]; constructor() { this._connections = []; } - addConnection(connection) { + addConnection(connection: Response): void { this._connections.push(connection); } - emit(event, data) { + emit(event: string, data?: unknown): void { this._connections.forEach(function(connection) { connection.write('event: ' + event + '\n'); connection.write('data: ' + stringify(data) + '\n'); connection.write('\n\n'); }); } -}; +} diff --git a/lib/gui/tool-runner/index.js b/lib/gui/tool-runner/index.js index 98aa086c8..5b18d15a9 100644 --- a/lib/gui/tool-runner/index.js +++ b/lib/gui/tool-runner/index.js @@ -8,9 +8,9 @@ const Promise = require('bluebird'); const looksSame = require('looks-same'); const {createTestRunner} = require('./runner'); -const subscribeOnToolEvents = require('./report-subscriber'); -const GuiReportBuilder = require('../../report-builder/gui'); -const EventSource = require('../event-source'); +const {subscribeOnToolEvents} = require('./report-subscriber'); +const {GuiReportBuilder} = require('../../report-builder/gui'); +const {EventSource} = require('../event-source'); const {logger} = require('../../common-utils'); const reporterHelper = require('../../reporter-helpers'); const {UPDATED, SKIPPED, IDLE} = require('../../constants/test-statuses'); diff --git a/lib/gui/tool-runner/report-subscriber.js b/lib/gui/tool-runner/report-subscriber.ts similarity index 61% rename from lib/gui/tool-runner/report-subscriber.js rename to lib/gui/tool-runner/report-subscriber.ts index 30490a0d7..3176db7e0 100644 --- a/lib/gui/tool-runner/report-subscriber.js +++ b/lib/gui/tool-runner/report-subscriber.ts @@ -1,32 +1,38 @@ -'use strict'; - -const os = require('os'); -const PQueue = require('p-queue'); -const {ClientEvents} = require('../constants/client-events'); -const {getSuitePath} = require('../../plugin-utils'); -const {createWorkers} = require('../../workers/create-workers'); -const {logError, formatTestResult} = require('../../server-utils'); -const {hasDiff} = require('../../common-utils'); -const {TestStatus, RUNNING, SUCCESS, SKIPPED} = require('../../constants'); - -let workers; - -module.exports = (hermione, reportBuilder, client, reportPath) => { +import os from 'os'; +import PQueue from 'p-queue'; +import Hermione from 'hermione'; +import {ClientEvents} from '../constants'; +import {getSuitePath} from '../../plugin-utils'; +import {createWorkers} from '../../workers/create-workers'; +import {logError, formatTestResult} from '../../server-utils'; +import {hasDiff} from '../../common-utils'; +import {TestStatus, RUNNING, SUCCESS, SKIPPED} from '../../constants'; +import {GuiReportBuilder} from '../../report-builder/gui'; +import {EventSource} from '../event-source'; +import {HermioneTestResult} from '../../types'; +import {HermioneTestAdapter, ReporterTestResult} from '../../test-adapter'; +import {ImageDiffError} from '../../errors'; + +let workers: ReturnType; + +type CreateWorkersRunner = Parameters[0]; + +export const subscribeOnToolEvents = (hermione: Hermione, reportBuilder: GuiReportBuilder, client: EventSource, reportPath: string): void => { const queue = new PQueue({concurrency: os.cpus().length}); const {imageHandler} = reportBuilder; - function failHandler(testResult, formattedResult) { - const actions = [imageHandler.saveTestImages(formattedResult, workers)]; + async function failHandler(formattedResult: ReporterTestResult): Promise { + const actions: Promise[] = [imageHandler.saveTestImages(formattedResult, workers)]; if (formattedResult.errorDetails) { - actions.push(formattedResult.saveErrorDetails(reportPath)); + actions.push((formattedResult as HermioneTestAdapter).saveErrorDetails(reportPath)); } - return Promise.all(actions); + await Promise.all(actions); } hermione.on(hermione.events.RUNNER_START, (runner) => { - workers = createWorkers(runner); + workers = createWorkers(runner as unknown as CreateWorkersRunner); }); hermione.on(hermione.events.SUITE_BEGIN, (suite) => { @@ -41,7 +47,7 @@ module.exports = (hermione, reportBuilder, client, reportPath) => { }); hermione.on(hermione.events.TEST_BEGIN, (data) => { - const formattedResult = formatTestResult(data, RUNNING, reportBuilder); + const formattedResult = formatTestResult(data as HermioneTestResult, RUNNING, reportBuilder); formattedResult.attempt = reportBuilder.getCurrAttempt(formattedResult); reportBuilder.addRunning(formattedResult); @@ -65,11 +71,11 @@ module.exports = (hermione, reportBuilder, client, reportPath) => { hermione.on(hermione.events.RETRY, (testResult) => { queue.add(async () => { - const status = hasDiff(testResult.assertViewResults) ? TestStatus.FAIL : TestStatus.ERROR; + const status = hasDiff(testResult.assertViewResults as ImageDiffError[]) ? TestStatus.FAIL : TestStatus.ERROR; const formattedResult = formatTestResult(testResult, status, reportBuilder); formattedResult.attempt = reportBuilder.getCurrAttempt(formattedResult); - await failHandler(testResult, formattedResult); + await failHandler(formattedResult); reportBuilder.addRetry(formattedResult); const testBranch = reportBuilder.getTestBranch(formattedResult.id); @@ -79,11 +85,11 @@ module.exports = (hermione, reportBuilder, client, reportPath) => { hermione.on(hermione.events.TEST_FAIL, (testResult) => { queue.add(async () => { - const status = hasDiff(testResult.assertViewResults) ? TestStatus.FAIL : TestStatus.ERROR; + const status = hasDiff(testResult.assertViewResults as ImageDiffError[]) ? TestStatus.FAIL : TestStatus.ERROR; const formattedResult = formatTestResult(testResult, status, reportBuilder); formattedResult.attempt = reportBuilder.getCurrAttempt(formattedResult); - await failHandler(testResult, formattedResult); + await failHandler(formattedResult); status === TestStatus.FAIL ? reportBuilder.addFail(formattedResult) : reportBuilder.addError(formattedResult); @@ -95,10 +101,10 @@ module.exports = (hermione, reportBuilder, client, reportPath) => { hermione.on(hermione.events.TEST_PENDING, async (testResult) => { queue.add(async () => { - const formattedResult = formatTestResult(testResult, SKIPPED, reportBuilder); + const formattedResult = formatTestResult(testResult as HermioneTestResult, SKIPPED, reportBuilder); formattedResult.attempt = reportBuilder.getCurrAttempt(formattedResult); - await failHandler(testResult, formattedResult); + await failHandler(formattedResult); reportBuilder.addSkipped(formattedResult); const testBranch = reportBuilder.getTestBranch(formattedResult.id); @@ -110,7 +116,7 @@ module.exports = (hermione, reportBuilder, client, reportPath) => { try { await queue.onIdle(); client.emit(ClientEvents.END); - } catch (err) { + } catch (err: any) { logError(err); } }); diff --git a/lib/report-builder/gui.ts b/lib/report-builder/gui.ts index 37799118c..f5dedef97 100644 --- a/lib/report-builder/gui.ts +++ b/lib/report-builder/gui.ts @@ -153,7 +153,7 @@ export class GuiReportBuilder extends StaticReportBuilder { formattedResult.attempt = formattedResult.attempt - 1; removedResult = resultId; - } else if (previousImage) { + } else { updatedImage = this._testsTree.updateImageInfo(imageId, previousImage); } diff --git a/lib/tests-tree-builder/gui.ts b/lib/tests-tree-builder/gui.ts index 9e68ce4e9..2d7b1e364 100644 --- a/lib/tests-tree-builder/gui.ts +++ b/lib/tests-tree-builder/gui.ts @@ -184,13 +184,14 @@ export class GuiTestsTreeBuilder extends BaseTestsTreeBuilder { this._tree.browsers.allIds.forEach((browserId) => this._reuseBrowser(testsTree, browserId)); } - updateImageInfo(imageId: string, imageInfo: TreeImage): TreeImage { + updateImageInfo(imageId: string, imageInfo?: TreeImage | null): TreeImage { const currentImage = this._tree.images.byId[imageId]; + // TODO: check TreeImage type. Is it correct to let it consist of id and parentId? const updatedImage: TreeImage = { ...imageInfo, id: currentImage.id, parentId: currentImage.parentId - }; + } as TreeImage; this._tree.images.byId[imageId] = updatedImage; diff --git a/package.json b/package.json index 8b7463fbe..776ea1038 100644 --- a/package.json +++ b/package.json @@ -101,10 +101,13 @@ "@playwright/test": "^1.37.1", "@swc/core": "^1.3.64", "@types/better-sqlite3": "^7.6.4", + "@types/bluebird": "^3.5.3", "@types/chai": "^4.3.5", "@types/debug": "^4.1.8", "@types/enzyme": "^3.10.13", + "@types/express": "4.16", "@types/fs-extra": "^7.0.0", + "@types/json-stringify-safe": "^5.0.2", "@types/lodash": "^4.14.195", "@types/nested-error-stacks": "^2.1.0", "@types/opener": "^1.4.0", diff --git a/test/unit/lib/gui/tool-runner/index.js b/test/unit/lib/gui/tool-runner/index.js index 9ff31fdba..6ede82edb 100644 --- a/test/unit/lib/gui/tool-runner/index.js +++ b/test/unit/lib/gui/tool-runner/index.js @@ -4,23 +4,23 @@ const path = require('path'); const fs = require('fs-extra'); const _ = require('lodash'); const proxyquire = require('proxyquire'); -const GuiReportBuilder = require('lib/report-builder/gui'); +const {GuiReportBuilder} = require('lib/report-builder/gui'); const {LOCAL_DATABASE_NAME} = require('lib/constants/database'); const {logger} = require('lib/common-utils'); -const Runner = require('lib/gui/tool-runner/runner'); const {stubTool, stubConfig, mkImagesInfo, mkState, mkSuite} = require('test/unit/utils'); describe('lib/gui/tool-runner/index', () => { const sandbox = sinon.createSandbox(); let reportBuilder; let ToolGuiReporter; - let reportSubscriber; + let subscribeOnToolEvents; let hermione; let getTestsTreeFromDatabase; let looksSame; let removeReferenceImage; let revertReferenceImage; let toolRunnerUtils; + let createTestRunner; const mkTestCollection_ = (testsTree = {}) => { return { @@ -67,6 +67,8 @@ describe('lib/gui/tool-runner/index', () => { beforeEach(() => { hermione = stubTool(); + createTestRunner = sinon.stub(); + toolRunnerUtils = { findTestResult: sandbox.stub(), formatId: sandbox.stub().returns('some-id') @@ -75,7 +77,7 @@ describe('lib/gui/tool-runner/index', () => { reportBuilder = sinon.createStubInstance(GuiReportBuilder); reportBuilder.getUpdatedAttempt.returns(0); - reportSubscriber = sandbox.stub().named('reportSubscriber').resolves(); + subscribeOnToolEvents = sandbox.stub().named('reportSubscriber').resolves(); looksSame = sandbox.stub().named('looksSame').resolves({equal: true}); removeReferenceImage = sandbox.stub().resolves(); revertReferenceImage = sandbox.stub().resolves(); @@ -87,7 +89,8 @@ describe('lib/gui/tool-runner/index', () => { ToolGuiReporter = proxyquire(`lib/gui/tool-runner`, { 'looks-same': looksSame, - './report-subscriber': reportSubscriber, + './runner': {createTestRunner}, + './report-subscriber': {subscribeOnToolEvents}, './utils': toolRunnerUtils, '../../db-utils/server': {getTestsTreeFromDatabase}, '../../reporter-helpers': { @@ -206,7 +209,7 @@ describe('lib/gui/tool-runner/index', () => { const gui = initGuiReporter(hermione, {paths: ['foo']}); return gui.initialize() - .then(() => assert.callOrder(reportSubscriber, hermione.readTests)); + .then(() => assert.callOrder(subscribeOnToolEvents, hermione.readTests)); }); it('should initialize report builder after read tests for the correct order of events', async () => { @@ -303,32 +306,6 @@ describe('lib/gui/tool-runner/index', () => { }); }); }); - - it('should pass "origAttempt" to the ReportBuilder.addUpdate method to be able to calculate status properly', async () => { - const tests = [{ - id: 'some-id', - fullTitle: () => 'some-title', - browserId: 'yabro', - attempt: 10, - suite: {path: ['suite1']}, - state: {}, - metaInfo: {}, - imagesInfo: [] - }]; - - const getScreenshotPath = sandbox.stub().returns('/ref/path1'); - const config = stubConfig({ - browsers: {yabro: {getScreenshotPath}} - }); - - const hermione = mkHermione_(config, {'some-title.yabro': tests[0]}); - const gui = initGuiReporter(hermione); - await gui.initialize(); - - await gui.updateReferenceImage(tests); - - assert.calledOnceWith(reportBuilder.addUpdated, sinon.match({origAttempt: 10})); - }); }); describe('undoAcceptImages', () => { @@ -502,7 +479,7 @@ describe('lib/gui/tool-runner/index', () => { beforeEach(() => { runner = {run: sandbox.stub().resolves()}; collection = mkTestCollection_(); - sandbox.stub(Runner, 'create').withArgs(collection).returns(runner); + createTestRunner.withArgs(collection).returns(runner); hermione.readTests.resolves(collection); }); diff --git a/test/unit/lib/gui/tool-runner/report-subsciber.js b/test/unit/lib/gui/tool-runner/report-subsciber.js index 89f6b174a..ea19cb2ca 100644 --- a/test/unit/lib/gui/tool-runner/report-subsciber.js +++ b/test/unit/lib/gui/tool-runner/report-subsciber.js @@ -3,9 +3,9 @@ const {EventEmitter} = require('events'); const Promise = require('bluebird'); const _ = require('lodash'); -const reportSubscriber = require('lib/gui/tool-runner/report-subscriber'); -const GuiReportBuilder = require('lib/report-builder/gui'); -const clientEvents = require('lib/gui/constants/client-events'); +const {subscribeOnToolEvents} = require('lib/gui/tool-runner/report-subscriber'); +const {GuiReportBuilder} = require('lib/report-builder/gui'); +const {ClientEvents} = require('lib/gui/constants'); const {stubTool, stubConfig} = require('test/unit/utils'); const {HermioneTestAdapter} = require('lib/test-adapter'); const {ErrorName} = require('lib/errors'); @@ -50,10 +50,10 @@ describe('lib/gui/tool-runner/hermione/report-subscriber', () => { it('should emit "END" event for client', () => { const hermione = mkHermione_(); - reportSubscriber(hermione, reportBuilder, client); + subscribeOnToolEvents(hermione, reportBuilder, client); return hermione.emitAsync(hermione.events.RUNNER_END) - .then(() => assert.calledOnceWith(client.emit, clientEvents.END)); + .then(() => assert.calledOnceWith(client.emit, ClientEvents.END)); }); it('should emit "END" event after all promises are resolved', async () => { @@ -63,11 +63,11 @@ describe('lib/gui/tool-runner/hermione/report-subscriber', () => { reportBuilder.imageHandler.saveTestImages.callsFake(() => Promise.delay(100).then(mediator)); - reportSubscriber(hermione, reportBuilder, client); + subscribeOnToolEvents(hermione, reportBuilder, client); hermione.emit(hermione.events.TEST_FAIL, testResult); await hermione.emitAsync(hermione.events.RUNNER_END); - assert.callOrder(mediator, client.emit.withArgs(clientEvents.END)); + assert.callOrder(mediator, client.emit.withArgs(ClientEvents.END)); }); }); @@ -78,10 +78,10 @@ describe('lib/gui/tool-runner/hermione/report-subscriber', () => { reportBuilder.getTestBranch.withArgs('some-id').returns('test-tree-branch'); - reportSubscriber(hermione, reportBuilder, client); + subscribeOnToolEvents(hermione, reportBuilder, client); hermione.emit(hermione.events.TEST_BEGIN, testResult); - assert.calledOnceWith(client.emit, clientEvents.BEGIN_STATE, 'test-tree-branch'); + assert.calledOnceWith(client.emit, ClientEvents.BEGIN_STATE, 'test-tree-branch'); }); }); @@ -90,7 +90,7 @@ describe('lib/gui/tool-runner/hermione/report-subscriber', () => { const hermione = mkHermione_(); const testResult = mkHermioneTestResult(); - reportSubscriber(hermione, reportBuilder, client); + subscribeOnToolEvents(hermione, reportBuilder, client); await hermione.emitAsync(hermione.events.TEST_PENDING, testResult); await hermione.emitAsync(hermione.events.RUNNER_END); @@ -107,11 +107,11 @@ describe('lib/gui/tool-runner/hermione/report-subscriber', () => { reportBuilder.getTestBranch.withArgs('some-id').returns('test-tree-branch'); - reportSubscriber(hermione, reportBuilder, client); + subscribeOnToolEvents(hermione, reportBuilder, client); await hermione.emitAsync(hermione.events.TEST_PENDING, testResult); await hermione.emitAsync(hermione.events.RUNNER_END); - assert.calledWith(client.emit, clientEvents.TEST_RESULT, 'test-tree-branch'); + assert.calledWith(client.emit, ClientEvents.TEST_RESULT, 'test-tree-branch'); }); }); @@ -122,7 +122,7 @@ describe('lib/gui/tool-runner/hermione/report-subscriber', () => { reportBuilder.getCurrAttempt.returns(1); - reportSubscriber(hermione, reportBuilder, client); + subscribeOnToolEvents(hermione, reportBuilder, client); hermione.emit(hermione.events.TEST_FAIL, testResult); await hermione.emitAsync(hermione.events.RUNNER_END); @@ -133,7 +133,7 @@ describe('lib/gui/tool-runner/hermione/report-subscriber', () => { const hermione = mkHermione_(); const testResult = mkHermioneTestResult({assertViewResults: [{name: ErrorName.IMAGE_DIFF}]}); - reportSubscriber(hermione, reportBuilder, client); + subscribeOnToolEvents(hermione, reportBuilder, client); hermione.emit(hermione.events.TEST_FAIL, testResult); await hermione.emitAsync(hermione.events.RUNNER_END); @@ -146,11 +146,11 @@ describe('lib/gui/tool-runner/hermione/report-subscriber', () => { reportBuilder.getTestBranch.withArgs('some-id').returns('test-tree-branch'); - reportSubscriber(hermione, reportBuilder, client); + subscribeOnToolEvents(hermione, reportBuilder, client); hermione.emit(hermione.events.TEST_FAIL, testResult); await hermione.emitAsync(hermione.events.RUNNER_END); - assert.calledWith(client.emit, clientEvents.TEST_RESULT, 'test-tree-branch'); + assert.calledWith(client.emit, ClientEvents.TEST_RESULT, 'test-tree-branch'); }); }); }); diff --git a/test/unit/lib/report-builder/gui.js b/test/unit/lib/report-builder/gui.js index e0d2bdd30..c6acec0aa 100644 --- a/test/unit/lib/report-builder/gui.js +++ b/test/unit/lib/report-builder/gui.js @@ -6,7 +6,7 @@ const proxyquire = require('proxyquire'); const serverUtils = require('lib/server-utils'); const {HermioneTestAdapter} = require('lib/test-adapter'); const {SqliteAdapter} = require('lib/sqlite-adapter'); -const GuiTestsTreeBuilder = require('lib/tests-tree-builder/gui'); +const {GuiTestsTreeBuilder} = require('lib/tests-tree-builder/gui'); const {HtmlReporter} = require('lib/plugin-api'); const {SUCCESS, FAIL, ERROR, SKIPPED, IDLE, RUNNING, UPDATED} = require('lib/constants/test-statuses'); const {LOCAL_DATABASE_NAME} = require('lib/constants/database'); @@ -77,8 +77,13 @@ describe('GuiReportBuilder', () => { hasImage = sandbox.stub().returns(true); deleteFile = sandbox.stub().resolves(); GuiReportBuilder = proxyquire('lib/report-builder/gui', { + './static': { + StaticReportBuilder: proxyquire('lib/report-builder/static', { + '../sqlite-adapter': {SqliteAdapter} + }).StaticReportBuilder + }, '../server-utils': {hasImage, deleteFile} - }); + }).GuiReportBuilder; sandbox.stub(GuiTestsTreeBuilder, 'create').returns(Object.create(GuiTestsTreeBuilder.prototype)); sandbox.stub(GuiTestsTreeBuilder.prototype, 'sortTree').returns({}); @@ -88,7 +93,6 @@ describe('GuiReportBuilder', () => { sandbox.stub(GuiTestsTreeBuilder.prototype, 'getImageDataToFindEqualDiffs').returns({}); sandbox.stub(GuiTestsTreeBuilder.prototype, 'getImagesInfo').returns([]); sandbox.stub(GuiTestsTreeBuilder.prototype, 'getLastResult').returns({}); - sandbox.stub(GuiTestsTreeBuilder.prototype, 'getResultByOrigAttempt').returns({}); sandbox.stub(GuiTestsTreeBuilder.prototype, 'addTestResult').returns({}); sandbox.stub(GuiTestsTreeBuilder.prototype, 'getResultDataToUnacceptImage').returns({}); sandbox.stub(GuiTestsTreeBuilder.prototype, 'updateImageInfo').returns({}); @@ -210,21 +214,16 @@ describe('GuiReportBuilder', () => { assert.equal(getTestResult_().status, SUCCESS); }); - it(`should corectly determine the status based on a previous result`, async () => { + it(`should correctly determine the status based on current result`, async () => { const reportBuilder = await mkGuiReportBuilder_(); - GuiTestsTreeBuilder.prototype.getResultByOrigAttempt.returns({status: FAIL}); - reportBuilder.addUpdated(stubTest_({ + error: {name: 'some-error', message: 'some-message'}, imagesInfo: [{status: FAIL}], - attempt: 4, - origAttempt: 2 + attempt: 4 })); - assert.equal(getTestResult_().status, FAIL); - assert.calledOnceWith(GuiTestsTreeBuilder.prototype.getResultByOrigAttempt, sinon.match({ - origAttempt: 2 - })); + assert.equal(getTestResult_().status, ERROR); }); it('should update test image for current state name', async () => { @@ -239,7 +238,8 @@ describe('GuiReportBuilder', () => { const updatedTest = stubTest_({ imagesInfo: [ - {stateName: 'plain1', status: UPDATED} + {stateName: 'plain1', status: UPDATED}, + {stateName: 'plain2', status: FAIL} ] }); @@ -271,7 +271,7 @@ describe('GuiReportBuilder', () => { reportBuilder.addFail(failedTest); GuiTestsTreeBuilder.prototype.getImagesInfo.returns(failedTest.imagesInfo); - reportBuilder.addUpdated(updatedTest); + reportBuilder.addUpdated(updatedTest, 'result-2'); const {imagesInfo} = GuiTestsTreeBuilder.prototype.addTestResult.secondCall.args[0]; @@ -434,17 +434,6 @@ describe('GuiReportBuilder', () => { assert.calledOnceWith(GuiTestsTreeBuilder.prototype.removeTestResult, 'result-id'); }); - it('should decrease test attempt number after deleting result', async () => { - const resultId = 'id'; - const stateName = 's-name'; - const formattedResult = mkFormattedResultStub_({id: resultId, stateName}); - stubResultData_({shouldRemoveResult: true}, {resultId, stateName}); - - await reportBuilder.undoAcceptImage(formattedResult, stateName); - - assert.calledOnceWith(formattedResult.decreaseAttemptNumber); - }); - it('should resolve removed result id', async () => { const resultId = 'result-id'; const stateName = 's-name'; @@ -507,7 +496,7 @@ describe('GuiReportBuilder', () => { '["s","p"]', 'bro-name', UPDATED, - 100500, + '100500', 'plain' ); }); diff --git a/test/unit/lib/tests-tree-builder/base.js b/test/unit/lib/tests-tree-builder/base.js index 35e6163cd..de57131ea 100644 --- a/test/unit/lib/tests-tree-builder/base.js +++ b/test/unit/lib/tests-tree-builder/base.js @@ -184,6 +184,7 @@ describe('ResultsTreeBuilder', () => { assert.deepEqual( builder.tree.results.byId['s1 b1 0'], { + attempt: 0, id: 's1 b1 0', parentId: 's1 b1', imageIds: [], diff --git a/test/unit/lib/tests-tree-builder/gui.js b/test/unit/lib/tests-tree-builder/gui.js index e4770239b..dff7b4061 100644 --- a/test/unit/lib/tests-tree-builder/gui.js +++ b/test/unit/lib/tests-tree-builder/gui.js @@ -1,7 +1,7 @@ 'use strict'; const _ = require('lodash'); -const GuiResultsTreeBuilder = require('lib/tests-tree-builder/gui'); +const {GuiTestsTreeBuilder} = require('lib/tests-tree-builder/gui'); const {FAIL, SUCCESS, IDLE, UPDATED} = require('lib/constants/test-statuses'); const {ToolName} = require('lib/constants'); @@ -20,7 +20,7 @@ describe('GuiResultsTreeBuilder', () => { }); }; - const mkGuiTreeBuilder = () => GuiResultsTreeBuilder.create({toolName: ToolName.Hermione}); + const mkGuiTreeBuilder = () => GuiTestsTreeBuilder.create({toolName: ToolName.Hermione}); beforeEach(() => { builder = mkGuiTreeBuilder(); @@ -39,7 +39,7 @@ describe('GuiResultsTreeBuilder', () => { }); }); - describe('"getResultByOrigAttempt" method', () => { + describe('"getLastActualResult" method', () => { it('should return previous result from tree', () => { const formattedRes1 = mkFormattedResult_({testPath: ['s'], browserId: 'b', attempt: 0}); const formattedRes2 = mkFormattedResult_({testPath: ['s'], browserId: 'b', attempt: 1}); @@ -48,9 +48,9 @@ describe('GuiResultsTreeBuilder', () => { builder.addTestResult(mkTestResult_(), formattedRes2); builder.addTestResult(mkTestResult_(), formattedRes3); - const lastResult = builder.getResultByOrigAttempt({testPath: ['s'], browserId: 'b', origAttempt: 1}); + const lastResult = builder.getLastActualResult({testPath: ['s'], browserId: 'b', attempt: 1}); - assert.deepEqual(lastResult, builder.tree.results.byId['s b 1']); + assert.deepEqual(lastResult, builder.tree.results.byId['s b 0']); }); }); diff --git a/test/unit/lib/tests-tree-builder/static.js b/test/unit/lib/tests-tree-builder/static.js index 2404e359e..7a2521c21 100644 --- a/test/unit/lib/tests-tree-builder/static.js +++ b/test/unit/lib/tests-tree-builder/static.js @@ -61,6 +61,7 @@ describe('StaticResultsTreeBuilder', () => { suiteUrl: result.suiteUrl, skipReason: result.skipReason, error: result.error, + timestamp: result.timestamp, ...data }; }; @@ -109,7 +110,7 @@ describe('StaticResultsTreeBuilder', () => { ); assert.calledWith( StaticTestsTreeBuilder.prototype.addTestResult.secondCall, - formatToTestResult(dataFromDb1, {attempt: 1}), + formatToTestResult(dataFromDb2, {attempt: 1}), {browserId: 'yabro', testPath: ['s1'], attempt: 1} ); });