Skip to content

Commit 96d5ef3

Browse files
committed
PRO-15775 fix: show failed screenshot tests in summary pack results
1 parent 4fcba65 commit 96d5ef3

File tree

8 files changed

+58
-14
lines changed

8 files changed

+58
-14
lines changed

src/actions/getBrowserConsoleMessages.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ import {log} from '../utils/log';
44

55
import type {ConsoleMessage} from '../types/internal';
66

7-
type Options = Readonly<{showMessagesInLog?: boolean}>;
7+
type Options = Readonly<{showMessagesInLog?: boolean; skipLogs?: boolean}>;
88

99
const logMessage = 'Get browser console messages';
1010

1111
/**
1212
* Returns an object that contains messages output to the browser console.
1313
*/
1414
export const getBrowserConsoleMessages = (options: Options = {}): readonly ConsoleMessage[] => {
15-
const {showMessagesInLog = false} = options;
15+
const {skipLogs = false, showMessagesInLog = false} = options;
1616
const consoleMessages = getConsoleMessagesFromContext();
1717

18+
if (skipLogs) {
19+
return consoleMessages;
20+
}
21+
1822
if (showMessagesInLog === false) {
1923
log(logMessage, LogEventType.InternalAction);
2024
} else {

src/constants/internal.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export {
4040
export {LogEventStatus, LogEventType} from './log';
4141
/** @internal */
4242
export {MESSAGE_BACKGROUND_COLOR_BY_STATUS} from './log';
43+
/** @internal */
44+
export {SCREENSHOT_NOT_SPECIFIED_ERROR_MESSAGE} from './matchScreenshot';
4345
export {CREATE_PAGE_TOKEN} from './pages';
4446
/** @internal */
4547
export {

src/constants/matchScreenshot.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Error message for "Expected screenshot not specified" error from the `toMatchScreenshot` assert (in `expect`).
3+
* @internal
4+
*/
5+
export const SCREENSHOT_NOT_SPECIFIED_ERROR_MESSAGE =
6+
'Expected screenshot not specified. If the actual screenshot is correct, specify screenshot from actualScreenshotId field';

src/utils/expect/toMatchScreenshot.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {isLocalRun} from '../../configurator';
66
import {
77
EXPECTED_SCREENSHOTS_DIRECTORY_PATH,
88
INTERNAL_REPORTS_DIRECTORY_PATH,
9+
SCREENSHOT_NOT_SPECIFIED_ERROR_MESSAGE,
910
} from '../../constants/internal';
1011
import {getOutputDirectoryName} from '../../context/outputDirectoryName';
1112

@@ -84,7 +85,7 @@ export const toMatchScreenshot = async (
8485

8586
const message = expectedScreenshotId
8687
? `Cannot read expected screenshot ${expectedScreenshotId}`
87-
: 'Expected screenshot not specified';
88+
: SCREENSHOT_NOT_SPECIFIED_ERROR_MESSAGE;
8889

8990
if (isLocalRun) {
9091
if (expectedScreenshotFound) {

src/utils/report/collectReportData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export const collectReportData = async ({
3838
const retries = getRetries(fullTestRuns);
3939
const exitCode = getExitCode(errors.length > 0, retries);
4040

41-
const failedTestsMainParams = getFailedTestsMainParams(retries.at(-1));
42-
const summaryPackResults = getSummaryPackResults(fullTestRuns, retries.at(-1));
41+
const failedTestsMainParams = getFailedTestsMainParams(retries);
42+
const summaryPackResults = getSummaryPackResults(fullTestRuns, retries);
4343

4444
return {
4545
apiStatistics,
Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
1-
import {TestRunStatus} from '../../constants/internal';
1+
import {SCREENSHOT_NOT_SPECIFIED_ERROR_MESSAGE, TestRunStatus} from '../../constants/internal';
2+
3+
import {assertValueIsFalse} from '../asserts';
24

35
import type {Retry} from '../../types/internal';
46

57
/**
68
* Get array of main parameters of pack's failed tests.
79
* @internal
810
*/
9-
export const getFailedTestsMainParams = (lastRetry: Retry | undefined): readonly string[] => {
11+
export const getFailedTestsMainParams = (retries: readonly Retry[]): readonly string[] => {
12+
const firstRetry = retries[0];
13+
const lastRetry = retries.at(-1);
14+
1015
const failedTests =
1116
lastRetry?.fullTestRuns.filter((fullTestRun) => fullTestRun.status === TestRunStatus.Failed) ??
1217
[];
1318
const failedTestsMainParams = failedTests.map(({mainParams}) => mainParams);
1419

20+
if (retries.length <= 1) {
21+
return failedTestsMainParams;
22+
}
23+
24+
const failedScreenshotTests =
25+
firstRetry?.fullTestRuns.filter(
26+
(fullTestRun) =>
27+
fullTestRun.status === TestRunStatus.Failed &&
28+
String(fullTestRun.runError).includes(SCREENSHOT_NOT_SPECIFIED_ERROR_MESSAGE),
29+
) ?? [];
30+
31+
for (const failedScreenshotTest of failedScreenshotTests) {
32+
assertValueIsFalse(
33+
failedTestsMainParams.includes(failedScreenshotTest.mainParams),
34+
'mainParams of failed screenshot test is unique',
35+
{duplicatedTest: failedScreenshotTest, failedScreenshotTests},
36+
);
37+
38+
failedTestsMainParams.push(failedScreenshotTest.mainParams);
39+
}
40+
1541
return failedTestsMainParams;
1642
};

src/utils/report/getSummaryPackResults.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ const MAX_FAILED_TESTS_COUNT = 8;
1616
*/
1717
export const getSummaryPackResults = (
1818
fullTestRuns: readonly FullTestRun[],
19-
lastRetry: Retry | undefined,
19+
retries: readonly Retry[],
2020
): string => {
21-
const allFailedTestsMainParams = getFailedTestsMainParams(lastRetry);
21+
const lastRetry = retries.at(-1);
22+
23+
const allFailedTestsMainParams = getFailedTestsMainParams(retries);
2224
const failedTestsMainParams = allFailedTestsMainParams.slice(0, MAX_FAILED_TESTS_COUNT);
2325

2426
if (allFailedTestsMainParams.length > MAX_FAILED_TESTS_COUNT) {
@@ -34,7 +36,10 @@ export const getSummaryPackResults = (
3436
? fullTestRuns
3537
: lastRetry?.fullTestRuns;
3638

37-
const count = source?.filter((fullTestRun) => fullTestRun.status === status)?.length ?? 0;
39+
const count =
40+
status === TestRunStatus.Failed
41+
? allFailedTestsMainParams.length
42+
: (source?.filter((fullTestRun) => fullTestRun.status === status)?.length ?? 0);
3843

3944
if (count > 0) {
4045
countsOfStatuses.push(`${count} ${status}`);

src/utils/selectors/Selector.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ class Selector {
9090
return result;
9191
}
9292

93-
get checked(): Promise<boolean | undefined> {
93+
get checked(): Promise<boolean | null> {
9494
const result = this.getPlaywrightLocator()
9595
.isChecked()
96-
.catch(() => undefined);
96+
.catch(() => null);
9797

9898
setRetryData(result, {property: 'checked', selector: this});
9999

@@ -160,10 +160,10 @@ class Selector {
160160
return result;
161161
}
162162

163-
get value(): Promise<string | undefined> {
163+
get value(): Promise<string | null> {
164164
const result = this.getPlaywrightLocator()
165165
.inputValue()
166-
.catch(() => undefined);
166+
.catch(() => null);
167167

168168
setRetryData(result, {property: 'value', selector: this});
169169

0 commit comments

Comments
 (0)