Skip to content

Commit ee8b0d9

Browse files
committed
PRO-14710 fix: layout of tests in HTML report for Safari
fix: autoopen first failed test fix: autoopen end screenshot of failed test
1 parent 5d5696d commit ee8b0d9

14 files changed

Lines changed: 43 additions & 41 deletions

src/utils/expect/additionalMatchers.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@ import {expect} from '@playwright/test';
1212
* @internal
1313
*/
1414
export const additionalMatchers: NonSelectorAdditionalMatchers<unknown> & SelectorMatchers = {
15-
contains(this: Expect, expected) {
15+
async contains(this: Expect, expected) {
1616
const {actualValue, description} = this;
1717

1818
if (typeof actualValue === 'string' || Array.isArray(actualValue)) {
19-
return Promise.resolve(expect(actualValue, description).toContain(expected));
19+
return expect(actualValue, description).toContain(expected);
2020
}
2121

22-
return Promise.resolve(
23-
expect(actualValue, description).toEqual(
24-
expect.objectContaining(expected as Record<string, unknown>),
25-
),
22+
return expect(actualValue, description).toEqual(
23+
expect.objectContaining(expected as Record<string, unknown>),
2624
);
2725
},
2826
async eql(this: Expect, expected) {

src/utils/report/client/addDomContentLoadedHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
* This client function should not use scope variables (except global functions).
55
* @internal
66
*/
7-
export function addDomContentLoadedHandler(handler: () => void): void {
7+
export const addDomContentLoadedHandler = (handler: () => void): void => {
88
if (document.readyState !== 'loading') {
99
handler();
1010

1111
return;
1212
}
1313

1414
document.addEventListener('DOMContentLoaded', handler);
15-
}
15+
};

src/utils/report/client/chooseTestRun.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable no-console */
2+
13
import {assertValueIsDefined as clientAssertValueIsDefined} from './assertValueIsDefined';
24
import {
35
MaybeApiStatistics as clientMaybeApiStatistics,
@@ -19,11 +21,10 @@ declare const reportClientState: ReportClientState;
1921
* @internal
2022
*/
2123
// eslint-disable-next-line max-statements
22-
export function chooseTestRun(runHash: RunHash): void {
24+
export const chooseTestRun = (runHash: RunHash): void => {
2325
const {e2edRightColumnContainer} = reportClientState;
2426

25-
if (e2edRightColumnContainer === undefined) {
26-
// eslint-disable-next-line no-console
27+
if (!e2edRightColumnContainer) {
2728
console.error(
2829
'Cannot find right column container (id="e2edRightColumnContainer"). Probably page not yet completely loaded. Please try click again later',
2930
);
@@ -45,6 +46,10 @@ export function chooseTestRun(runHash: RunHash): void {
4546
e2edRightColumnContainer.firstElementChild as HTMLElement | null;
4647

4748
if (!previousTestRunDetailsElement) {
49+
console.error(
50+
'Cannot find first child element in right column container (id="e2edRightColumnContainer"). Probably page not yet completely loaded. Please try click again later',
51+
);
52+
4853
return;
4954
}
5055

@@ -72,7 +77,6 @@ export function chooseTestRun(runHash: RunHash): void {
7277
const fullTestRun = fullTestRuns.find((testRun) => testRun.runHash === runHash);
7378

7479
if (fullTestRun === undefined) {
75-
// eslint-disable-next-line no-console
7680
console.error(
7781
`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`,
7882
);
@@ -88,4 +92,4 @@ export function chooseTestRun(runHash: RunHash): void {
8892
const nextTestRunDetailsElement = e2edRightColumnContainer.firstElementChild as HTMLElement;
8993

9094
testRunDetailsElementsByHash[runHash] = nextTestRunDetailsElement;
91-
}
95+
};

src/utils/report/client/createJsxRuntime.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const sanitizeHtml = clientSanitizeHtml;
1515
* This client function should not use scope variables (except global functions).
1616
* @internal
1717
*/
18-
export function createJsxRuntime(): JSX.Runtime {
18+
export const createJsxRuntime = (): JSX.Runtime => {
1919
const maxDepth = 8;
2020

2121
const createElement: JSX.CreateElement = (type, properties, ...children) => {
@@ -104,4 +104,4 @@ export function createJsxRuntime(): JSX.Runtime {
104104
};
105105

106106
return {Fragment, createElement};
107-
}
107+
};

src/utils/report/client/onDomContentLoad.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ const readJsonReportData = clientReadJsonReportData;
1111
* This client function should not use scope variables (except global functions).
1212
* @internal
1313
*/
14-
export function onDomContentLoad(): void {
14+
export const onDomContentLoad = (): void => {
1515
const e2edRightColumnContainer = document.getElementById('e2edRightColumnContainer') ?? undefined;
1616

17-
if (e2edRightColumnContainer === undefined) {
17+
if (!e2edRightColumnContainer) {
1818
// eslint-disable-next-line no-console
1919
console.error(
2020
'Cannot find right column container (id="e2edRightColumnContainer") after DOMContentLoaded.',
@@ -32,4 +32,4 @@ export function onDomContentLoad(): void {
3232
}
3333

3434
reportClientState.readJsonReportDataObservers.length = 0;
35-
}
35+
};

src/utils/report/client/parseMarkdownLinks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ const sanitizeHtml = clientSanitizeHtml;
1313
* This client function should not use scope variables (except global functions).
1414
* @internal
1515
*/
16-
export function parseMarkdownLinks(
16+
export const parseMarkdownLinks = (
1717
stringParts: readonly string[],
1818
...values: readonly unknown[]
19-
): SafeHtml {
19+
): SafeHtml => {
2020
const sanitizedHtml = sanitizeHtml(stringParts, ...values);
2121

2222
const htmlWithLinks = sanitizedHtml.replace(
@@ -25,4 +25,4 @@ export function parseMarkdownLinks(
2525
);
2626

2727
return createSafeHtmlWithoutSanitize`${htmlWithLinks}`;
28-
}
28+
};

src/utils/report/client/readJsonReportData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ declare const reportClientState: ReportClientState;
1515
* This client function should not use scope variables (except global functions).
1616
* @internal
1717
*/
18-
export function readJsonReportData(areAllScriptsLoaded = false): void {
18+
export const readJsonReportData = (areAllScriptsLoaded = false): void => {
1919
const {lengthOfReadedJsonReportDataParts} = reportClientState;
2020
const scripts = document.querySelectorAll('body > script.e2edJsonReportData');
2121
const {length} = scripts;
@@ -40,4 +40,4 @@ export function readJsonReportData(areAllScriptsLoaded = false): void {
4040
}
4141

4242
reportClientState.lengthOfReadedJsonReportDataParts = newLength;
43-
}
43+
};

src/utils/report/client/readPartOfJsonReportData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Options = Readonly<{
1313
* This client function should not use scope variables (except global functions).
1414
* @internal
1515
*/
16-
export function readPartOfJsonReportData({scriptToRead, shouldLogError}: Options): boolean {
16+
export const readPartOfJsonReportData = ({scriptToRead, shouldLogError}: Options): boolean => {
1717
try {
1818
const data = JSON.parse(scriptToRead?.textContent ?? '') as ScriptJsonData;
1919

@@ -32,4 +32,4 @@ export function readPartOfJsonReportData({scriptToRead, shouldLogError}: Options
3232
}
3333

3434
return true;
35-
}
35+
};

src/utils/report/client/render/Step.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ type Props = Readonly<{
2121
isEnd?: boolean;
2222
logEvent: LogEventWithChildren;
2323
nextLogEventTime: UtcTimeInMs;
24+
open?: boolean;
2425
}>;
2526

2627
/**
2728
* Renders single step of test run.
2829
* This base client function should not use scope variables (except other base functions).
2930
* @internal
3031
*/
31-
export const Step: JSX.Component<Props> = ({isEnd = false, logEvent, nextLogEventTime}) => {
32+
export const Step: JSX.Component<Props> = ({isEnd = false, logEvent, nextLogEventTime, open}) => {
3233
const {children, message, payload, time, type} = logEvent;
3334
const date = new Date(time).toISOString();
3435
const isPayloadEmpty = !payload || Object.keys(payload).length === 0;
@@ -49,6 +50,7 @@ export const Step: JSX.Component<Props> = ({isEnd = false, logEvent, nextLogEven
4950
}
5051

5152
let content = <></>;
53+
const isErrorScreenshot = pathToScreenshotOfPage !== undefined;
5254

5355
if (!isEnd) {
5456
content =
@@ -60,7 +62,7 @@ export const Step: JSX.Component<Props> = ({isEnd = false, logEvent, nextLogEven
6062
</span>
6163
</div>
6264
) : (
63-
<details class="step__details">
65+
<details class="step__details" open={open ?? isErrorScreenshot}>
6466
<summary class="step__head">
6567
<span class="step__name">{message}</span>
6668
<span class="step__duration">

src/utils/report/client/sanitizeHtml.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ export function sanitizeValue(value: unknown): string {
7070
* This base client function should not use scope variables (except other base functions).
7171
* @internal
7272
*/
73-
export function sanitizeHtml(
73+
export const sanitizeHtml = (
7474
stringParts: readonly string[],
7575
...values: readonly unknown[]
76-
): SafeHtml {
76+
): SafeHtml => {
7777
const parts: string[] = [];
7878

7979
for (let index = 0; index < values.length; index += 1) {
@@ -96,13 +96,11 @@ export function sanitizeHtml(
9696
const html = parts.join('');
9797

9898
return createSafeHtmlWithoutSanitize`${html}`;
99-
}
99+
};
100100

101101
/**
102102
* Sanitizes JSON string (simple protection against XSS attacks).
103103
* This base client function should not use scope variables (except other base functions).
104104
* @internal
105105
*/
106-
export function sanitizeJson(json: string): string {
107-
return json.replace(/</g, '\\u003c');
108-
}
106+
export const sanitizeJson = (json: string): string => json.replace(/</g, '\\u003c');

0 commit comments

Comments
 (0)