Skip to content

Commit 666caf1

Browse files
committed
FI-1437 fix: add more fields to screenshot metadata
1 parent 0473be6 commit 666caf1

8 files changed

Lines changed: 59 additions & 29 deletions

File tree

autotests/configurator/matchScreenshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const matchScreenshot: MatchScreenshot = {
2323

2424
return `https://joomcode.github.io/e2ed/${path.slice(-2).join('/')}` as Url;
2525
},
26-
readScreenshot: (screenshotId) => {
26+
readScreenshot: (screenshotId, _meta) => {
2727
const path = getPath(screenshotId);
2828
const screenshotPath = join(...path) as FilePathFromRoot;
2929

src/types/matchScreenshot.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ export type MatchScreenshotConfig<TestMeta = TestMetaPlaceholder> = Readonly<{
1616
/**
1717
* Reads screenshot by `screenshotId`.
1818
*/
19-
readScreenshot: (this: void, screenshotId: string) => Promise<Uint8Array | undefined>;
19+
readScreenshot: (
20+
this: void,
21+
screenshotId: string,
22+
meta: ScreenshotMeta<TestMeta>,
23+
) => Promise<Uint8Array | undefined>;
2024

2125
/**
2226
* Writes screenshot by `screenshotId` and optional context info.
@@ -32,14 +36,16 @@ export type MatchScreenshotConfig<TestMeta = TestMetaPlaceholder> = Readonly<{
3236
* General screenshot metadata (like test name, assert description, etc.).
3337
*/
3438
export type ScreenshotMeta<TestMeta = TestMetaPlaceholder> = Readonly<{
39+
actual: string | undefined;
3540
description: string;
36-
isDiff: boolean;
41+
expected: string | undefined;
3742
options: ToMatchScreenshotOptions;
43+
pageUrl: Url;
3844
pathToPack: string;
3945
runLabel: RunLabel;
4046
selector: string;
4147
testStaticOptions: TestStaticOptions<TestMeta>;
42-
writeTimeInMs: number;
48+
timeInMs: number;
4349
}>;
4450

4551
/**
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {getTestStaticOptions} from '../../context/testStaticOptions';
2+
import {getPlaywrightPage} from '../../useContext';
3+
4+
import {getPathToPack, getRunLabel} from '../environment';
5+
6+
import type {ScreenshotMeta, Selector, ToMatchScreenshotOptions, Url} from '../../types/internal';
7+
8+
type Options = Readonly<{
9+
actualValue: Selector;
10+
description: string;
11+
expectedScreenshotId: string;
12+
options: ToMatchScreenshotOptions;
13+
}>;
14+
15+
/**
16+
* Get screenshot metadata.
17+
* @internal
18+
*/
19+
export const getScreenshotMeta = ({
20+
actualValue,
21+
description,
22+
expectedScreenshotId,
23+
options,
24+
}: Options): ScreenshotMeta => ({
25+
actual: undefined,
26+
description,
27+
expected: expectedScreenshotId !== '' ? expectedScreenshotId : undefined,
28+
options,
29+
pageUrl: getPlaywrightPage().url() as Url,
30+
pathToPack: getPathToPack(),
31+
runLabel: getRunLabel(),
32+
selector: actualValue.description,
33+
testStaticOptions: getTestStaticOptions(),
34+
timeInMs: Date.now(),
35+
});

src/utils/expect/toMatchScreenshot.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,15 @@ import {
88
INTERNAL_REPORTS_DIRECTORY_PATH,
99
} from '../../constants/internal';
1010
import {getOutputDirectoryName} from '../../context/outputDirectoryName';
11-
import {getTestStaticOptions} from '../../context/testStaticOptions';
1211

1312
import {getFullPackConfig} from '../config';
14-
import {getPathToPack, getRunLabel} from '../environment';
1513
import {E2edError} from '../error';
1614
import {writeFile} from '../fs';
1715
import {setReadonlyProperty} from '../setReadonlyProperty';
1816

19-
import type {
20-
FilePathFromRoot,
21-
ScreenshotMeta,
22-
Selector,
23-
ToMatchScreenshotOptions,
24-
Url,
25-
} from '../../types/internal';
17+
import {getScreenshotMeta} from './getScreenshotMeta';
18+
19+
import type {FilePathFromRoot, Selector, ToMatchScreenshotOptions, Url} from '../../types/internal';
2620

2721
import type {Expect} from './Expect';
2822

@@ -70,12 +64,14 @@ export const toMatchScreenshot = async (
7064

7165
setReadonlyProperty(context, 'additionalLogFields', additionalLogFields);
7266

67+
const meta = getScreenshotMeta({actualValue, description, expectedScreenshotId, options});
68+
7369
let expectedScreenshotFound = false;
7470

7571
if (expectedScreenshotId) {
7672
additionalLogFields.expectedScreenshotUrl = getScreenshotUrlById(expectedScreenshotId);
7773

78-
const expectedScreenshot = await readScreenshot(expectedScreenshotId);
74+
const expectedScreenshot = await readScreenshot(expectedScreenshotId, meta);
7975

8076
if (expectedScreenshot !== undefined) {
8177
expectedScreenshotFound = true;
@@ -99,16 +95,6 @@ export const toMatchScreenshot = async (
9995
}
10096

10197
const {mask = [], ...restOptions} = options;
102-
const meta: ScreenshotMeta = {
103-
description,
104-
isDiff: false,
105-
options,
106-
pathToPack: getPathToPack(),
107-
runLabel: getRunLabel(),
108-
selector: actualValue.description,
109-
testStaticOptions: getTestStaticOptions(),
110-
writeTimeInMs: Date.now(),
111-
};
11298

11399
try {
114100
const playwrightLocator = actualValue.getPlaywrightLocator();
@@ -131,7 +117,10 @@ export const toMatchScreenshot = async (
131117
additionalLogFields.actualScreenshotUrl = getScreenshotUrlById(actualScreenshotId);
132118

133119
const diffScreenshot = await readFile(diffScreenshotPath);
134-
const diffScreenshotId = await writeScreenshot(diffScreenshot, {...meta, isDiff: true});
120+
const diffScreenshotId = await writeScreenshot(diffScreenshot, {
121+
...meta,
122+
actual: actualScreenshotId,
123+
});
135124

136125
additionalLogFields.diffScreenshotId = diffScreenshotId;
137126
additionalLogFields.diffScreenshotUrl = getScreenshotUrlById(diffScreenshotId);

src/utils/packCompiler/getCompilerOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const frozenCompilerOptions: CompilerOptions = {
2525
resolveJsonModule: true,
2626
rootDir: '.',
2727
skipLibCheck: true,
28-
target: ScriptTarget.ES2023,
28+
target: ScriptTarget.ES2024,
2929
types: ['node'],
3030
};
3131

src/utils/report/client/render/renderTestRunError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function renderTestRunError(runError: RunError): SafeHtml {
1515
}
1616

1717
// eslint-disable-next-line no-control-regex
18-
const stylesRegexp = /(\\x1B\[)|(\x1B\[)[\d;]+m/gi;
18+
const stylesRegexp = /(\\x1B\[)|(\x1B\[)|(\\u001b\[)[\d;]+m/gi;
1919

2020
const runErrorWithoutStyle = String(runError).replace(stylesRegexp, '');
2121

src/utils/valueToString/removeStyleFromString.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// eslint-disable-next-line no-control-regex
2-
const stylesRegexp = /\x1B\[[\d;]+m/gi;
2+
const stylesRegexp = /(\\x1B\[)|(\x1B\[)|(\\u001b\[)[\d;]+m/gi;
33

44
/**
55
* Removes console (terminal) styles from a string (like `\x1B[3m...`).

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"skipLibCheck": false,
2828
"strict": true,
2929
"stripInternal": true,
30-
"target": "ES2023",
30+
"target": "ES2024",
3131
"types": ["node"],
3232
"useDefineForClassFields": true
3333
},

0 commit comments

Comments
 (0)