From 46df772c3ce7b8f0fb3b9f44ced949b820f5500a Mon Sep 17 00:00:00 2001 From: uid11 Date: Wed, 21 May 2025 05:54:53 +0300 Subject: [PATCH 1/2] PRO-10170 fix: error with rendering tests with initial `runHash` fix: catch errors from original `actualValue` in `expect` --- src/utils/events/registerEndTestRunEvent.ts | 4 +- src/utils/expect/createExpectMethod.ts | 6 ++- src/utils/report/client/chooseTestRun.ts | 49 +++++-------------- src/utils/report/client/index.ts | 6 ++- .../report/client/maybeRenderApiStatistics.ts | 45 +++++++++++++++++ 5 files changed, 68 insertions(+), 42 deletions(-) create mode 100644 src/utils/report/client/maybeRenderApiStatistics.ts diff --git a/src/utils/events/registerEndTestRunEvent.ts b/src/utils/events/registerEndTestRunEvent.ts index d983ab8b..cc9507fb 100644 --- a/src/utils/events/registerEndTestRunEvent.ts +++ b/src/utils/events/registerEndTestRunEvent.ts @@ -14,7 +14,7 @@ import {calculateTestRunStatus} from './calculateTestRunStatus'; import {getTestRunEvent} from './getTestRunEvent'; import {writeFullMocksIfNeeded} from './writeFullMocksIfNeeded'; -import type {EndTestRunEvent, FullTestRun, TestRun} from '../../types/internal'; +import type {EndTestRunEvent, FullTestRun, RunHash, TestRun} from '../../types/internal'; /** * Registers end test run event (for report) after test closing. @@ -74,7 +74,7 @@ export const registerEndTestRunEvent = async (endTestRunEvent: EndTestRunEvent): const {getMainTestRunParams, getTestRunHash} = getUserlandHooks(); const mainParams = getMainTestRunParams(testRun); - const runHash = getTestRunHash(testRun); + const runHash = getTestRunHash(testRun).replaceAll('#', '') as RunHash; const fullTestRun: FullTestRun = {mainParams, runHash, ...testRun}; diff --git a/src/utils/expect/createExpectMethod.ts b/src/utils/expect/createExpectMethod.ts index 668a10e3..067a4822 100644 --- a/src/utils/expect/createExpectMethod.ts +++ b/src/utils/expect/createExpectMethod.ts @@ -92,7 +92,11 @@ export const createExpectMethod = ( } return runAssertion(this.actualValue); - }); + }).catch((error: Error) => ({ + actualValue: this.actualValue, + description: this.description, + error, + })); return assertionPromise.then(({actualValue, additionalLogFields, error}) => { const logMessage = `Assert: ${this.description}`; diff --git a/src/utils/report/client/chooseTestRun.ts b/src/utils/report/client/chooseTestRun.ts index 79b90f52..36341bb3 100644 --- a/src/utils/report/client/chooseTestRun.ts +++ b/src/utils/report/client/chooseTestRun.ts @@ -1,18 +1,11 @@ import {assertValueIsDefined as clientAssertValueIsDefined} from './assertValueIsDefined'; -import { - renderApiStatistics as clientRenderApiStatistics, - renderTestRunDetails as clientRenderTestRunDetails, -} from './render'; - -import type { - ApiStatisticsReportHash, - ReportClientState, - RunHash, - SafeHtml, -} from '../../../types/internal'; +import {maybeRenderApiStatistics as clientMaybeRenderApiStatistics} from './maybeRenderApiStatistics'; +import {renderTestRunDetails as clientRenderTestRunDetails} from './render'; + +import type {ReportClientState, RunHash, SafeHtml} from '../../../types/internal'; const assertValueIsDefined: typeof clientAssertValueIsDefined = clientAssertValueIsDefined; -const renderApiStatistics = clientRenderApiStatistics; +const maybeRenderApiStatistics = clientMaybeRenderApiStatistics; const renderTestRunDetails = clientRenderTestRunDetails; declare const reportClientState: ReportClientState; @@ -35,7 +28,7 @@ export function chooseTestRun(runHash: RunHash): void { return; } - const previousHash = window.location.hash as RunHash; + const previousHash = window.location.hash.replaceAll('#', '') as RunHash; window.location.hash = runHash; @@ -47,7 +40,10 @@ export function chooseTestRun(runHash: RunHash): void { const previousTestRunDetailsElement = e2edRightColumnContainer.firstElementChild as HTMLElement; - if (!(previousHash in testRunDetailsElementsByHash)) { + if ( + !(previousHash in testRunDetailsElementsByHash) && + !previousTestRunDetailsElement.classList.contains('test-details-empty') + ) { testRunDetailsElementsByHash[previousHash] = previousTestRunDetailsElement; } @@ -61,30 +57,9 @@ export function chooseTestRun(runHash: RunHash): void { return; } - const pagesHash: ApiStatisticsReportHash = 'api-statistics-pages'; - const requestsHash: ApiStatisticsReportHash = 'api-statistics-requests'; - const resourcesHash: ApiStatisticsReportHash = 'api-statistics-resources'; - - let rightColumnHtml: SafeHtml | undefined; - - const hash = String(runHash); - - if (hash === pagesHash || hash === requestsHash || hash === resourcesHash) { - const {reportClientData} = reportClientState; - - if (reportClientData === undefined) { - // eslint-disable-next-line no-console - console.error( - `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`, - ); - - return; - } - - const {apiStatistics} = reportClientData; + let rightColumnHtml: SafeHtml | undefined = maybeRenderApiStatistics(runHash); - rightColumnHtml = renderApiStatistics({apiStatistics, hash}); - } else { + if (rightColumnHtml === undefined) { const {fullTestRuns} = reportClientState; const fullTestRun = fullTestRuns.find((testRun) => testRun.runHash === runHash); diff --git a/src/utils/report/client/index.ts b/src/utils/report/client/index.ts index 780020d0..04212e4a 100644 --- a/src/utils/report/client/index.ts +++ b/src/utils/report/client/index.ts @@ -15,12 +15,14 @@ export {clickOnTestRun} from './clickOnTestRun'; /** @internal */ export {createJsxRuntime} from './createJsxRuntime'; /** @internal */ +export {initialScript} from './initialScript'; +/** @internal */ +export {maybeRenderApiStatistics} from './maybeRenderApiStatistics'; +/** @internal */ export {onDomContentLoad} from './onDomContentLoad'; /** @internal */ export {onFirstJsonReportDataLoad} from './onFirstJsonReportDataLoad'; /** @internal */ -export {initialScript} from './initialScript'; -/** @internal */ export {parseMarkdownLinks} from './parseMarkdownLinks'; /** @internal */ export {readJsonReportData} from './readJsonReportData'; diff --git a/src/utils/report/client/maybeRenderApiStatistics.ts b/src/utils/report/client/maybeRenderApiStatistics.ts new file mode 100644 index 00000000..bad9d9f1 --- /dev/null +++ b/src/utils/report/client/maybeRenderApiStatistics.ts @@ -0,0 +1,45 @@ +import {renderApiStatistics as clientRenderApiStatistics} from './render'; + +import type { + ApiStatisticsReportHash, + ReportClientState, + RunHash, + SafeHtml, +} from '../../../types/internal'; + +const renderApiStatistics = clientRenderApiStatistics; + +declare const reportClientState: ReportClientState; + +/** + * Renders `ApiStatistics` by `runHash`, if this is a one of kind of `ApiStatistics` hash + * (pages, requests or resources). + * This base client function should not use scope variables (except other base functions). + * @internal + */ +export function maybeRenderApiStatistics(runHash: RunHash): SafeHtml | undefined { + const hash = String(runHash); + + const pagesHash: ApiStatisticsReportHash = 'api-statistics-pages'; + const requestsHash: ApiStatisticsReportHash = 'api-statistics-requests'; + const resourcesHash: ApiStatisticsReportHash = 'api-statistics-resources'; + + if (hash !== pagesHash && hash !== requestsHash && hash !== resourcesHash) { + return; + } + + const {reportClientData} = reportClientState; + + if (reportClientData === undefined) { + // eslint-disable-next-line no-console + console.error( + `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`, + ); + + return; + } + + const {apiStatistics} = reportClientData; + + return renderApiStatistics({apiStatistics, hash}); +} From 31696fa953fb9828b2e6a8831b05dc490d570024 Mon Sep 17 00:00:00 2001 From: uid11 Date: Wed, 21 May 2025 05:57:58 +0300 Subject: [PATCH 2/2] chore: update `devDependencies` (`types/node`) --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8d0dbf6c..a389614c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ }, "devDependencies": { "@playwright/browser-chromium": "1.52.0", - "@types/node": "22.15.19", + "@types/node": "22.15.21", "@typescript-eslint/eslint-plugin": "7.18.0", "@typescript-eslint/parser": "7.18.0", "assert-modules-support-case-insensitive-fs": "1.0.1", @@ -231,9 +231,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.15.19", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.19.tgz", - "integrity": "sha512-3vMNr4TzNQyjHcRZadojpRaD9Ofr6LsonZAoQ+HMUa/9ORTPoxVIw0e0mpqWpdjj8xybyCM+oKOUH2vwFu/oEw==", + "version": "22.15.21", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.21.tgz", + "integrity": "sha512-EV/37Td6c+MgKAbkcLG6vqZ2zEYHD7bvSrzqqs2RIhbA6w3x+Dqz8MZM3sP6kGTeLrdoOgKZe+Xja7tUB2DNkQ==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 9d4607b4..ef1509e7 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ }, "devDependencies": { "@playwright/browser-chromium": "1.52.0", - "@types/node": "22.15.19", + "@types/node": "22.15.21", "@typescript-eslint/eslint-plugin": "7.18.0", "@typescript-eslint/parser": "7.18.0", "assert-modules-support-case-insensitive-fs": "1.0.1",