From 1336a0ca0b967f2a5c3785ce558ff0b140f64c84 Mon Sep 17 00:00:00 2001 From: Vasily Strelyaev Date: Wed, 28 Dec 2022 10:17:41 +0400 Subject: [PATCH] Fix a bug where actionId was not set for screenshots (#131) * fix a bug where actionId was not set for screenshots * bump version --- package.json | 2 +- src/reporter-object-factory.ts | 18 +++--- test/data/test-layout-testing-info.ts | 54 +++++++++++++++++- test/reporter-methods/test-done.test.ts | 9 +-- test/upload-files.test.ts | 74 +++++++++++++++---------- 5 files changed, 111 insertions(+), 46 deletions(-) diff --git a/package.json b/package.json index 47e96c7..2296a12 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "testcafe-reporter-dashboard-devextreme", - "version": "1.3.3", + "version": "1.3.4", "description": "Dashboard TestCafe reporter plugin fork, tailored to the DevExtreme team.", "author": { "name": "Developer Express Inc.", diff --git a/src/reporter-object-factory.ts b/src/reporter-object-factory.ts index 8185fe8..aeb438b 100644 --- a/src/reporter-object-factory.ts +++ b/src/reporter-object-factory.ts @@ -259,14 +259,6 @@ export function reporterObjectFactory ( if (!currentUploadId) continue; - if (actionId) { - const actions = testRunToActionsMap[testRunId]; - const screenshotAction = actions?.find(action => action.command.actionId === actionId); - - if (screenshotAction) - screenshotAction.screenshotPath = screenshotPath; - } - const screenshotMapItem: ScreenshotMapItem = { path: screenshotPath, ids: { @@ -274,6 +266,16 @@ export function reporterObjectFactory ( } }; + if (actionId) { + const actions = testRunToActionsMap[testRunId]; + const screenshotAction = actions?.find(action => action.command.actionId === actionId); + + if (screenshotAction) { + screenshotAction.screenshotPath = screenshotPath; + screenshotMapItem.actionId = actionId; + } + } + if (comparisonFailed) { const testPath = fixture.path; const baselineScreenshotPath = path.join(path.dirname(testPath), 'etalons', path.basename(screenshotPath)); diff --git a/test/data/test-layout-testing-info.ts b/test/data/test-layout-testing-info.ts index 275ba43..a18ec96 100644 --- a/test/data/test-layout-testing-info.ts +++ b/test/data/test-layout-testing-info.ts @@ -5,7 +5,7 @@ import { CHROME } from './test-browser-info'; const testRunId = 'chrome_1'; const testId = 'test1'; -export const layoutTestingActionInfo1 = { +export const layoutTestingScreenshotActionInfo1 = { duration: 1000, browser: CHROME, testRunId: testRunId, @@ -21,7 +21,55 @@ export const layoutTestingActionInfo1 = { } }; -export const layoutTestingActionInfo2 = { +export const layoutTestingScreenshotActionInfo2 = { + duration: 1000, + browser: CHROME, + testRunId: testRunId, + test: { + name: 'Test 1', + phase: TestPhase.inTest, + id: testId + }, + command: { + actionId: 'action2', + type: CommandType.takeScreenshot, + selector: 'Selector(\'body\')' + } +}; + +export const layoutTestingScreenshotActionInfo3 = { + duration: 1000, + browser: CHROME, + testRunId: testRunId, + test: { + name: 'Test 1', + phase: TestPhase.inTest, + id: testId + }, + command: { + actionId: 'action3', + type: CommandType.takeScreenshot, + selector: 'Selector(\'body\')' + } +}; + +export const layoutTestingScreenshotActionInfo4 = { + duration: 1000, + browser: CHROME, + testRunId: testRunId, + test: { + name: 'Test 1', + phase: TestPhase.inTest, + id: testId + }, + command: { + actionId: 'action4', + type: CommandType.takeScreenshot, + selector: 'Selector(\'body\')' + } +}; + +export const layoutTestingClickActionInfo = { duration: 1000, browser: CHROME, testRunId: testRunId, @@ -60,7 +108,7 @@ export const layoutTestingTestDoneInfo: TestRunInfo = { userAgent: '', quarantineAttempt: 1, takenOnFail: true, - actionId: layoutTestingActionInfo1.command.actionId + actionId: layoutTestingScreenshotActionInfo1.command.actionId }, { testRunId, diff --git a/test/reporter-methods/test-done.test.ts b/test/reporter-methods/test-done.test.ts index 2146d07..3ead25c 100644 --- a/test/reporter-methods/test-done.test.ts +++ b/test/reporter-methods/test-done.test.ts @@ -17,7 +17,7 @@ import { DashboardTestRunInfo, TaskDoneArgs, TestDoneArgs } from '../../src/type import { mockFileExists, mockReadFile, SETTINGS, TESTCAFE_DASHBOARD_URL, UPLOAD_URL_PREFIX } from '../mocks'; import { TC_OLDEST_COMPATIBLE_VERSION } from '../../src/validate-settings'; import { WARNINGS_TEST_RUN_ID_1 } from '../data/test-warnings-info'; -import { layoutTestingActionInfo1, layoutTestingActionInfo2, layoutTestingTestDoneInfo, layoutTestingTestStartInfo } from '../data/test-layout-testing-info'; +import { layoutTestingScreenshotActionInfo1, layoutTestingClickActionInfo, layoutTestingTestDoneInfo, layoutTestingTestStartInfo } from '../data/test-layout-testing-info'; describe('reportTestDone', () => { let testRunInfo = {} as DashboardTestRunInfo; @@ -210,8 +210,8 @@ describe('reportTestDone', () => { await reporter.reportTaskStart(new Date(), [], 1, [], { configuration: {}, dashboardUrl: '' }); await reporter.reportTestStart('Test 1', {}, layoutTestingTestStartInfo); - await reporter.reportTestActionDone('takeScreenshot', layoutTestingActionInfo1); - await reporter.reportTestActionDone('click', layoutTestingActionInfo2); + await reporter.reportTestActionDone('takeScreenshot', layoutTestingScreenshotActionInfo1); + await reporter.reportTestActionDone('click', layoutTestingClickActionInfo); await reporter.reportTestDone('Test 1', layoutTestingTestDoneInfo); @@ -226,7 +226,8 @@ describe('reportTestDone', () => { current: 'upload_id' }, path: '%filePath%chrome_1_1.png', - comparisonFailed: false + comparisonFailed: false, + actionId: 'action1' }, { ids: { diff --git a/test/upload-files.test.ts b/test/upload-files.test.ts index 048fe7a..596cb5b 100644 --- a/test/upload-files.test.ts +++ b/test/upload-files.test.ts @@ -11,6 +11,7 @@ import { TC_OLDEST_COMPATIBLE_VERSION } from '../src/validate-settings'; import { testWarningsInfo, WARNINGS_TEST_RUN_ID_1, WARNINGS_TEST_RUN_ID_2 } from './data/test-warnings-info'; import path from 'path'; import mock from 'mock-require'; +import { layoutTestingScreenshotActionInfo1, layoutTestingScreenshotActionInfo2, layoutTestingScreenshotActionInfo3, layoutTestingScreenshotActionInfo4, layoutTestingTestStartInfo } from './data/test-layout-testing-info'; const testRunIdChrome = 'chrome_headless'; const testRunId1 = 'testRun_1'; @@ -253,47 +254,56 @@ describe('Uploads', () => { const screenshots: Screenshot[] = [ { - testRunId: testRunIdChrome, + testRunId: 'chrome_1', screenshotPath: screenshotPath1, thumbnailPath: thumbnailPath1, userAgent: 'Chrome_79.0.3945.88_Windows_8.1', takenOnFail: false, - quarantineAttempt: 0 + quarantineAttempt: 0, + actionId: 'action1' }, { - testRunId: testRunIdChrome, + testRunId: 'chrome_1', screenshotPath: screenshotPath2, thumbnailPath: thumbnailPath2, userAgent: 'Chrome_79.0.3945.88_Windows_8.1', takenOnFail: false, - quarantineAttempt: 0 + quarantineAttempt: 0, + actionId: 'action2' }, { - testRunId: testRunIdChrome, + testRunId: 'chrome_1', screenshotPath: screenshotPath3, thumbnailPath: thumbnailPath3, userAgent: 'Chrome_79.0.3945.88_Windows_8.1', takenOnFail: true, - quarantineAttempt: 0 + quarantineAttempt: 0, + actionId: 'action3' }, { - testRunId: testRunIdChrome, + testRunId: 'chrome_1', screenshotPath: screenshotPath4, thumbnailPath: thumbnailPath4, userAgent: 'Chrome_79.0.3945.88_Windows_8.1', takenOnFail: false, - quarantineAttempt: 0 + quarantineAttempt: 0, + actionId: 'action4' } ]; const reporter = reporterFactory(readFile, fileExists, fetch, SETTINGS, loggerMock, TC_OLDEST_COMPATIBLE_VERSION); await reporter.reportTaskStart(new Date(), [], 1, [], { configuration: {}, dashboardUrl: '' }); + await reporter.reportTestStart('Test 1', {}, layoutTestingTestStartInfo); + await reporter.reportTestActionDone('takeScreenshot', layoutTestingScreenshotActionInfo1); + await reporter.reportTestActionDone('takeScreenshot', layoutTestingScreenshotActionInfo2); + await reporter.reportTestActionDone('takeScreenshot', layoutTestingScreenshotActionInfo3); + await reporter.reportTestActionDone('takeScreenshot', layoutTestingScreenshotActionInfo4); await reporter.reportTestDone('Test 1', { ...EMPTY_TEST_RUN_INFO, screenshots, - browsers: [ { ...CHROME_HEADLESS, testRunId: 'chrome_headless' } ], + browsers: [ { ...CHROME_HEADLESS, testRunId: 'chrome_1' } ], fixture: { id: 'fixture1', name: 'My fixture', @@ -309,27 +319,31 @@ describe('Uploads', () => { assert.equal(runCommands[0].type, AggregateCommandType.reportTaskStart); assert.equal(runCommands[1].type, AggregateCommandType.reportTestDone); - assert.equal(browserRuns['chrome_headless'].screenshotMap[0].path, screenshotPath1); - assert.equal(browserRuns['chrome_headless'].screenshotMap[0].ids.current, uploadInfos[0].uploadId); - assert.equal(browserRuns['chrome_headless'].screenshotMap[0].ids.baseline, uploadInfos[1].uploadId); - assert.equal(browserRuns['chrome_headless'].screenshotMap[0].ids.diff, uploadInfos[2].uploadId); - assert.equal(browserRuns['chrome_headless'].screenshotMap[0].ids.mask, uploadInfos[3].uploadId); - assert.equal(browserRuns['chrome_headless'].screenshotMap[0].baselineSourcePath, 'testing/tests/suite1/etalons/1.png'); - assert.equal(browserRuns['chrome_headless'].screenshotMap[0].maskSourcePath, 'testing/tests/suite1/etalons/1_mask.png'); - assert.ok(browserRuns['chrome_headless'].screenshotMap[0].comparisonFailed); - assert.equal(browserRuns['chrome_headless'].screenshotMap[1].path, screenshotPath2); - assert.equal(browserRuns['chrome_headless'].screenshotMap[1].ids.current, uploadInfos[4].uploadId); - assert.equal(browserRuns['chrome_headless'].screenshotMap[1].ids.baseline, uploadInfos[5].uploadId); - assert.equal(browserRuns['chrome_headless'].screenshotMap[1].ids.diff, uploadInfos[6].uploadId); - assert.equal(browserRuns['chrome_headless'].screenshotMap[1].baselineSourcePath, 'testing/tests/suite1/etalons/2.png'); - assert.equal(browserRuns['chrome_headless'].screenshotMap[1].maskSourcePath, 'testing/tests/suite1/etalons/2_mask.png'); - assert.ok(browserRuns['chrome_headless'].screenshotMap[1].comparisonFailed); - assert.equal(browserRuns['chrome_headless'].screenshotMap[2].path, screenshotPath3); - assert.equal(browserRuns['chrome_headless'].screenshotMap[2].ids.current, uploadInfos[7].uploadId); - assert.equal(browserRuns['chrome_headless'].screenshotMap[2].comparisonFailed, false); - assert.equal(browserRuns['chrome_headless'].screenshotMap[3].path, screenshotPath4); - assert.equal(browserRuns['chrome_headless'].screenshotMap[3].ids.current, uploadInfos[8].uploadId); - assert.equal(browserRuns['chrome_headless'].screenshotMap[3].comparisonFailed, false); + assert.equal(browserRuns['chrome_1'].screenshotMap[0].path, screenshotPath1); + assert.equal(browserRuns['chrome_1'].screenshotMap[0].actionId, 'action1'); + assert.equal(browserRuns['chrome_1'].screenshotMap[0].ids.current, uploadInfos[0].uploadId); + assert.equal(browserRuns['chrome_1'].screenshotMap[0].ids.baseline, uploadInfos[1].uploadId); + assert.equal(browserRuns['chrome_1'].screenshotMap[0].ids.diff, uploadInfos[2].uploadId); + assert.equal(browserRuns['chrome_1'].screenshotMap[0].ids.mask, uploadInfos[3].uploadId); + assert.equal(browserRuns['chrome_1'].screenshotMap[0].baselineSourcePath, 'testing/tests/suite1/etalons/1.png'); + assert.equal(browserRuns['chrome_1'].screenshotMap[0].maskSourcePath, 'testing/tests/suite1/etalons/1_mask.png'); + assert.ok(browserRuns['chrome_1'].screenshotMap[0].comparisonFailed); + assert.equal(browserRuns['chrome_1'].screenshotMap[1].path, screenshotPath2); + assert.equal(browserRuns['chrome_1'].screenshotMap[1].actionId, 'action2'); + assert.equal(browserRuns['chrome_1'].screenshotMap[1].ids.current, uploadInfos[4].uploadId); + assert.equal(browserRuns['chrome_1'].screenshotMap[1].ids.baseline, uploadInfos[5].uploadId); + assert.equal(browserRuns['chrome_1'].screenshotMap[1].ids.diff, uploadInfos[6].uploadId); + assert.equal(browserRuns['chrome_1'].screenshotMap[1].baselineSourcePath, 'testing/tests/suite1/etalons/2.png'); + assert.equal(browserRuns['chrome_1'].screenshotMap[1].maskSourcePath, 'testing/tests/suite1/etalons/2_mask.png'); + assert.ok(browserRuns['chrome_1'].screenshotMap[1].comparisonFailed); + assert.equal(browserRuns['chrome_1'].screenshotMap[2].path, screenshotPath3); + assert.equal(browserRuns['chrome_1'].screenshotMap[2].actionId, 'action3'); + assert.equal(browserRuns['chrome_1'].screenshotMap[2].ids.current, uploadInfos[7].uploadId); + assert.equal(browserRuns['chrome_1'].screenshotMap[2].comparisonFailed, false); + assert.equal(browserRuns['chrome_1'].screenshotMap[3].path, screenshotPath4); + assert.equal(browserRuns['chrome_1'].screenshotMap[3].actionId, 'action4'); + assert.equal(browserRuns['chrome_1'].screenshotMap[3].ids.current, uploadInfos[8].uploadId); + assert.equal(browserRuns['chrome_1'].screenshotMap[3].comparisonFailed, false); assert.equal(runCommands[1].payload.uploadId, uploadInfos[9].uploadId); assert.equal(uploadInfos.length, 10);