Skip to content

Commit 46df772

Browse files
committed
PRO-10170 fix: error with rendering tests with initial runHash
fix: catch errors from original `actualValue` in `expect`
1 parent 4ffea9d commit 46df772

5 files changed

Lines changed: 68 additions & 42 deletions

File tree

src/utils/events/registerEndTestRunEvent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {calculateTestRunStatus} from './calculateTestRunStatus';
1414
import {getTestRunEvent} from './getTestRunEvent';
1515
import {writeFullMocksIfNeeded} from './writeFullMocksIfNeeded';
1616

17-
import type {EndTestRunEvent, FullTestRun, TestRun} from '../../types/internal';
17+
import type {EndTestRunEvent, FullTestRun, RunHash, TestRun} from '../../types/internal';
1818

1919
/**
2020
* Registers end test run event (for report) after test closing.
@@ -74,7 +74,7 @@ export const registerEndTestRunEvent = async (endTestRunEvent: EndTestRunEvent):
7474
const {getMainTestRunParams, getTestRunHash} = getUserlandHooks();
7575

7676
const mainParams = getMainTestRunParams(testRun);
77-
const runHash = getTestRunHash(testRun);
77+
const runHash = getTestRunHash(testRun).replaceAll('#', '') as RunHash;
7878

7979
const fullTestRun: FullTestRun = {mainParams, runHash, ...testRun};
8080

src/utils/expect/createExpectMethod.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ export const createExpectMethod = (
9292
}
9393

9494
return runAssertion(this.actualValue);
95-
});
95+
}).catch((error: Error) => ({
96+
actualValue: this.actualValue,
97+
description: this.description,
98+
error,
99+
}));
96100

97101
return assertionPromise.then(({actualValue, additionalLogFields, error}) => {
98102
const logMessage = `Assert: ${this.description}`;

src/utils/report/client/chooseTestRun.ts

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import {assertValueIsDefined as clientAssertValueIsDefined} from './assertValueIsDefined';
2-
import {
3-
renderApiStatistics as clientRenderApiStatistics,
4-
renderTestRunDetails as clientRenderTestRunDetails,
5-
} from './render';
6-
7-
import type {
8-
ApiStatisticsReportHash,
9-
ReportClientState,
10-
RunHash,
11-
SafeHtml,
12-
} from '../../../types/internal';
2+
import {maybeRenderApiStatistics as clientMaybeRenderApiStatistics} from './maybeRenderApiStatistics';
3+
import {renderTestRunDetails as clientRenderTestRunDetails} from './render';
4+
5+
import type {ReportClientState, RunHash, SafeHtml} from '../../../types/internal';
136

147
const assertValueIsDefined: typeof clientAssertValueIsDefined = clientAssertValueIsDefined;
15-
const renderApiStatistics = clientRenderApiStatistics;
8+
const maybeRenderApiStatistics = clientMaybeRenderApiStatistics;
169
const renderTestRunDetails = clientRenderTestRunDetails;
1710

1811
declare const reportClientState: ReportClientState;
@@ -35,7 +28,7 @@ export function chooseTestRun(runHash: RunHash): void {
3528
return;
3629
}
3730

38-
const previousHash = window.location.hash as RunHash;
31+
const previousHash = window.location.hash.replaceAll('#', '') as RunHash;
3932

4033
window.location.hash = runHash;
4134

@@ -47,7 +40,10 @@ export function chooseTestRun(runHash: RunHash): void {
4740

4841
const previousTestRunDetailsElement = e2edRightColumnContainer.firstElementChild as HTMLElement;
4942

50-
if (!(previousHash in testRunDetailsElementsByHash)) {
43+
if (
44+
!(previousHash in testRunDetailsElementsByHash) &&
45+
!previousTestRunDetailsElement.classList.contains('test-details-empty')
46+
) {
5147
testRunDetailsElementsByHash[previousHash] = previousTestRunDetailsElement;
5248
}
5349

@@ -61,30 +57,9 @@ export function chooseTestRun(runHash: RunHash): void {
6157
return;
6258
}
6359

64-
const pagesHash: ApiStatisticsReportHash = 'api-statistics-pages';
65-
const requestsHash: ApiStatisticsReportHash = 'api-statistics-requests';
66-
const resourcesHash: ApiStatisticsReportHash = 'api-statistics-resources';
67-
68-
let rightColumnHtml: SafeHtml | undefined;
69-
70-
const hash = String(runHash);
71-
72-
if (hash === pagesHash || hash === requestsHash || hash === resourcesHash) {
73-
const {reportClientData} = reportClientState;
74-
75-
if (reportClientData === undefined) {
76-
// eslint-disable-next-line no-console
77-
console.error(
78-
`Cannot find report client data in JSON report data (tried to click "${runHash}"). Probably JSON report data not yet completely loaded. Please try click again later`,
79-
);
80-
81-
return;
82-
}
83-
84-
const {apiStatistics} = reportClientData;
60+
let rightColumnHtml: SafeHtml | undefined = maybeRenderApiStatistics(runHash);
8561

86-
rightColumnHtml = renderApiStatistics({apiStatistics, hash});
87-
} else {
62+
if (rightColumnHtml === undefined) {
8863
const {fullTestRuns} = reportClientState;
8964
const fullTestRun = fullTestRuns.find((testRun) => testRun.runHash === runHash);
9065

src/utils/report/client/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ export {clickOnTestRun} from './clickOnTestRun';
1515
/** @internal */
1616
export {createJsxRuntime} from './createJsxRuntime';
1717
/** @internal */
18+
export {initialScript} from './initialScript';
19+
/** @internal */
20+
export {maybeRenderApiStatistics} from './maybeRenderApiStatistics';
21+
/** @internal */
1822
export {onDomContentLoad} from './onDomContentLoad';
1923
/** @internal */
2024
export {onFirstJsonReportDataLoad} from './onFirstJsonReportDataLoad';
2125
/** @internal */
22-
export {initialScript} from './initialScript';
23-
/** @internal */
2426
export {parseMarkdownLinks} from './parseMarkdownLinks';
2527
/** @internal */
2628
export {readJsonReportData} from './readJsonReportData';
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {renderApiStatistics as clientRenderApiStatistics} from './render';
2+
3+
import type {
4+
ApiStatisticsReportHash,
5+
ReportClientState,
6+
RunHash,
7+
SafeHtml,
8+
} from '../../../types/internal';
9+
10+
const renderApiStatistics = clientRenderApiStatistics;
11+
12+
declare const reportClientState: ReportClientState;
13+
14+
/**
15+
* Renders `ApiStatistics` by `runHash`, if this is a one of kind of `ApiStatistics` hash
16+
* (pages, requests or resources).
17+
* This base client function should not use scope variables (except other base functions).
18+
* @internal
19+
*/
20+
export function maybeRenderApiStatistics(runHash: RunHash): SafeHtml | undefined {
21+
const hash = String(runHash);
22+
23+
const pagesHash: ApiStatisticsReportHash = 'api-statistics-pages';
24+
const requestsHash: ApiStatisticsReportHash = 'api-statistics-requests';
25+
const resourcesHash: ApiStatisticsReportHash = 'api-statistics-resources';
26+
27+
if (hash !== pagesHash && hash !== requestsHash && hash !== resourcesHash) {
28+
return;
29+
}
30+
31+
const {reportClientData} = reportClientState;
32+
33+
if (reportClientData === undefined) {
34+
// eslint-disable-next-line no-console
35+
console.error(
36+
`Cannot find report client data in JSON report data (tried to click "${hash}"). Probably JSON report data not yet completely loaded. Please try click again later`,
37+
);
38+
39+
return;
40+
}
41+
42+
const {apiStatistics} = reportClientData;
43+
44+
return renderApiStatistics({apiStatistics, hash});
45+
}

0 commit comments

Comments
 (0)