Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions autotests/tests/main/exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ test('exists', {meta: {testId: '1'}, testIdleTimeout: 12_000, testTimeout: 20_00

const successfulResponsePromise = waitForResponse(
({statusCode}) => statusCode === OK_STATUS_CODE,
{includeNavigationRequest: true},
);

await pressKey('Enter');
Expand Down
14 changes: 7 additions & 7 deletions src/utils/report/client/chooseTestRun.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable no-console */

import {assertValueIsDefined as clientAssertValueIsDefined} from './assertValueIsDefined';
import {
MaybeApiStatistics as clientMaybeApiStatistics,
TestRunDetails as clientTestRunDetails,
} from './render';
import {setDomElementsToClientState as clientSetDomElementsToClientState} from './setDomElementsToClientState';

import type {ReportClientState, RunHash} from '../../../types/internal';

const assertValueIsDefined: typeof clientAssertValueIsDefined = clientAssertValueIsDefined;
const MaybeApiStatistics = clientMaybeApiStatistics;
const setDomElementsToClientState = clientSetDomElementsToClientState;
const TestRunDetails = clientTestRunDetails;

declare const jsx: JSX.Runtime;
Expand All @@ -20,15 +20,13 @@ declare const reportClientState: ReportClientState;
* This base client function should not use scope variables (except other base functions).
* @internal
*/
// eslint-disable-next-line max-statements
// eslint-disable-next-line complexity, max-statements
export const chooseTestRun = (runHash: RunHash): void => {
setDomElementsToClientState();

const {e2edRightColumnContainer} = reportClientState;

if (!e2edRightColumnContainer) {
console.error(
'Cannot find right column container (id="e2edRightColumnContainer"). Probably page not yet completely loaded. Please try click again later',
);

return;
}

Expand All @@ -46,6 +44,7 @@ export const chooseTestRun = (runHash: RunHash): void => {
e2edRightColumnContainer.firstElementChild as HTMLElement | null;

if (!previousTestRunDetailsElement) {
// eslint-disable-next-line no-console
console.error(
'Cannot find first child element in right column container (id="e2edRightColumnContainer"). Probably page not yet completely loaded. Please try click again later',
);
Expand Down Expand Up @@ -77,6 +76,7 @@ export const chooseTestRun = (runHash: RunHash): void => {
const fullTestRun = fullTestRuns.find((testRun) => testRun.runHash === runHash);

if (fullTestRun === undefined) {
// eslint-disable-next-line no-console
console.error(
`Cannot find test run with hash ${runHash} in JSON report data. Probably JSON report data for this test run not yet loaded. Please try click again later`,
);
Expand Down
2 changes: 2 additions & 0 deletions src/utils/report/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ export {
sanitizeValue,
} from './sanitizeHtml';
/** @internal */
export {setDomElementsToClientState} from './setDomElementsToClientState';
/** @internal */
export {setReadJsonReportDataObservers} from './setReadJsonReportDataObservers';
15 changes: 3 additions & 12 deletions src/utils/report/client/onDomContentLoad.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
import {readJsonReportData as clientReadJsonReportData} from './readJsonReportData';
import {setDomElementsToClientState as clientSetDomElementsToClientState} from './setDomElementsToClientState';

import type {ReportClientState} from '../../../types/internal';

declare const reportClientState: ReportClientState;

const readJsonReportData = clientReadJsonReportData;
const setDomElementsToClientState = clientSetDomElementsToClientState;

/**
* `DOMContentLoaded` handler for report page.
* This client function should not use scope variables (except global functions).
* @internal
*/
export const onDomContentLoad = (): void => {
const e2edRightColumnContainer = document.getElementById('e2edRightColumnContainer') ?? undefined;

if (!e2edRightColumnContainer) {
// eslint-disable-next-line no-console
console.error(
'Cannot find right column container (id="e2edRightColumnContainer") after DOMContentLoaded.',
);
} else {
Object.assign<ReportClientState, Partial<ReportClientState>>(reportClientState, {
e2edRightColumnContainer,
});
}
setDomElementsToClientState({afterDomContentLoad: true});

readJsonReportData(true);

Expand Down
35 changes: 35 additions & 0 deletions src/utils/report/client/setDomElementsToClientState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type {ReportClientState} from '../../../types/internal';

declare const reportClientState: ReportClientState;

type Options = Readonly<{afterDomContentLoad?: boolean}> | undefined;

/**
* Set dynamic DOM elements to `reportClientState`.
* This client function should not use scope variables (except global functions).
* @internal
*/
export const setDomElementsToClientState = ({afterDomContentLoad = false}: Options = {}): void => {
let {e2edRightColumnContainer} = reportClientState;

if (e2edRightColumnContainer) {
return;
}

e2edRightColumnContainer = document.getElementById('e2edRightColumnContainer') ?? undefined;

if (e2edRightColumnContainer) {
Object.assign<ReportClientState, Partial<ReportClientState>>(reportClientState, {
e2edRightColumnContainer,
});

return;
}

const messageTail = afterDomContentLoad
? ' after DOMContentLoaded'
: '. Probably page not yet completely loaded. Please try click again later';

// eslint-disable-next-line no-console
console.error(`Cannot find right column container (id="e2edRightColumnContainer")${messageTail}`);
};