|
1 | | -import {TestRunStatus} from '../../constants/internal'; |
| 1 | +import {SCREENSHOT_NOT_SPECIFIED_ERROR_MESSAGE, TestRunStatus} from '../../constants/internal'; |
| 2 | + |
| 3 | +import {assertValueIsFalse} from '../asserts'; |
2 | 4 |
|
3 | 5 | import type {Retry} from '../../types/internal'; |
4 | 6 |
|
5 | 7 | /** |
6 | 8 | * Get array of main parameters of pack's failed tests. |
7 | 9 | * @internal |
8 | 10 | */ |
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 | + |
10 | 15 | const failedTests = |
11 | 16 | lastRetry?.fullTestRuns.filter((fullTestRun) => fullTestRun.status === TestRunStatus.Failed) ?? |
12 | 17 | []; |
13 | 18 | const failedTestsMainParams = failedTests.map(({mainParams}) => mainParams); |
14 | 19 |
|
| 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 | + |
15 | 41 | return failedTestsMainParams; |
16 | 42 | }; |
0 commit comments