Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
Fix a bug where actionId was not set for screenshots (#131)
Browse files Browse the repository at this point in the history
* fix a bug where actionId was not set for screenshots

* bump version
  • Loading branch information
VasilyStrelyaev committed Dec 28, 2022
1 parent e9383b9 commit 1336a0c
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 46 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down
18 changes: 10 additions & 8 deletions src/reporter-object-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,21 +259,23 @@ 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: {
current: currentUploadId
}
};

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));
Expand Down
54 changes: 51 additions & 3 deletions test/data/test-layout-testing-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -60,7 +108,7 @@ export const layoutTestingTestDoneInfo: TestRunInfo = {
userAgent: '',
quarantineAttempt: 1,
takenOnFail: true,
actionId: layoutTestingActionInfo1.command.actionId
actionId: layoutTestingScreenshotActionInfo1.command.actionId
},
{
testRunId,
Expand Down
9 changes: 5 additions & 4 deletions test/reporter-methods/test-done.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -226,7 +226,8 @@ describe('reportTestDone', () => {
current: 'upload_id'
},
path: '%filePath%chrome_1_1.png',
comparisonFailed: false
comparisonFailed: false,
actionId: 'action1'
},
{
ids: {
Expand Down
74 changes: 44 additions & 30 deletions test/upload-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand All @@ -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);
Expand Down

0 comments on commit 1336a0c

Please sign in to comment.