Skip to content

Commit 81a23dd

Browse files
committed
feat(test-runner-visual-regression): add testName to GetNameArgs
by supplying test name to each of the extensibility points, it becomes easier to store images relative to the test itself
1 parent 4f3117d commit 81a23dd

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

packages/test-runner-visual-regression/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type PixelMatchOptions = PixelMatchParams[5];
7676
export interface GetNameArgs {
7777
browser: string;
7878
name: string;
79+
testFile: string;
7980
}
8081

8182
export interface ImageArgs {

packages/test-runner-visual-regression/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type PixelMatchOptions = PixelMatchParams[5];
1111
export interface GetNameArgs {
1212
browser: string;
1313
name: string;
14+
testFile: string;
1415
}
1516

1617
export interface ImageArgs {

packages/test-runner-visual-regression/src/visualDiffCommand.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ export async function visualDiffCommand(
2222
image: Buffer,
2323
browser: string,
2424
name: string,
25+
testFile: string,
2526
): Promise<VisualDiffCommandResult> {
2627
const baseDir = path.resolve(options.baseDir);
27-
const baselineName = options.getBaselineName({ browser, name });
28+
const baselineName = options.getBaselineName({ browser, name, testFile });
2829

2930
const baselineImage = await options.getBaseline({
3031
filePath: resolveImagePath(baseDir, baselineName),
@@ -42,8 +43,8 @@ export async function visualDiffCommand(
4243
return { diffPercentage: -1, passed: true };
4344
}
4445

45-
const diffName = options.getDiffName({ browser, name });
46-
const failedName = options.getFailedName({ browser, name });
46+
const diffName = options.getDiffName({ browser, name, testFile });
47+
const failedName = options.getFailedName({ browser, name, testFile });
4748

4849
const saveFailed = async () => {
4950
await options.saveFailed({

packages/test-runner-visual-regression/src/visualRegressionPlugin.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ export function visualRegressionPlugin(
6767
}
6868

6969
const screenshot = (await element.screenshot({ encoding: 'binary' })) as Buffer;
70-
return visualDiffCommand(mergedOptions, screenshot, session.browser.name, payload.name);
70+
return visualDiffCommand(
71+
mergedOptions,
72+
screenshot,
73+
session.browser.name,
74+
payload.name,
75+
session.testFile,
76+
);
7177
}
7278

7379
if (session.browser.type === 'playwright') {
@@ -88,7 +94,13 @@ export function visualRegressionPlugin(
8894
}
8995

9096
const screenshot = await element.screenshot();
91-
return visualDiffCommand(mergedOptions, screenshot, session.browser.name, payload.name);
97+
return visualDiffCommand(
98+
mergedOptions,
99+
screenshot,
100+
session.browser.name,
101+
payload.name,
102+
session.testFile,
103+
);
92104
}
93105

94106
if (session.browser.type === 'webdriver') {
@@ -106,7 +118,13 @@ export function visualRegressionPlugin(
106118
`;
107119

108120
const screenshot = await browser.takeScreenshot(session.id, locator);
109-
return visualDiffCommand(mergedOptions, screenshot, session.browser.name, payload.name);
121+
return visualDiffCommand(
122+
mergedOptions,
123+
screenshot,
124+
session.browser.name,
125+
payload.name,
126+
session.testFile,
127+
);
110128
}
111129

112130
throw new Error(

0 commit comments

Comments
 (0)