Skip to content

Commit 328fc0e

Browse files
Merge pull request #553 from gemini-testing/TESTPLANE-90.html_reporter_relativePath
feat: add relativePath to refImg
2 parents ddb5abd + b722899 commit 328fc0e

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

lib/gui/tool-runner/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import type {
4242
TestplaneTestResult,
4343
ImageFile,
4444
ImageInfoDiff, ImageInfoUpdated, ImageInfoWithState,
45-
ReporterConfig, TestSpecByPath
45+
ReporterConfig, TestSpecByPath, RefImageFile
4646
} from '../../types';
4747

4848
export type ToolRunnerTree = GuiReportBuilderResult & Pick<GuiCliOptions, 'autoRun'>;
@@ -324,8 +324,9 @@ export class ToolRunner {
324324
.filter(({stateName, actualImg}) => Boolean(stateName) && Boolean(actualImg))
325325
.forEach((imageInfo) => {
326326
const {stateName, actualImg} = imageInfo as {stateName: string, actualImg: ImageFile};
327-
const path = this._toolAdapter.config.browsers[browserId].getScreenshotPath(testplaneTest, stateName);
328-
const refImg = {path, size: actualImg.size};
327+
const absoluteRefImgPath = this._toolAdapter.config.browsers[browserId].getScreenshotPath(testplaneTest, stateName);
328+
const relativeRefImgPath = absoluteRefImgPath && path.relative(process.cwd(), absoluteRefImgPath);
329+
const refImg: RefImageFile = {path: absoluteRefImgPath, relativePath: relativeRefImgPath, size: actualImg.size};
329330

330331
assertViewResults.push({stateName, refImg, currImg: actualImg, isUpdated: isUpdatedStatus(imageInfo.status)});
331332
});

lib/types.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ export interface ImageFile {
4141
size: ImageSize;
4242
}
4343

44+
export interface RefImageFile extends ImageFile {
45+
/**
46+
* @note defined if testplane >= 8.13.0
47+
*/
48+
relativePath?: string;
49+
}
50+
4451
export interface ImageBuffer {
4552
buffer: Buffer;
4653
}
@@ -59,7 +66,10 @@ export interface DiffOptions extends LooksSameOptions {
5966
export interface TestError {
6067
name: string;
6168
message: string;
62-
snippet?: string; // defined if testplane >= 8.11.0
69+
/**
70+
* @note defined if testplane >= 8.11.0
71+
*/
72+
snippet?: string;
6373
stack?: string;
6474
stateName?: string;
6575
details?: ErrorDetails
@@ -69,27 +79,37 @@ export interface TestError {
6979
export interface ImageInfoDiff {
7080
status: TestStatus.FAIL;
7181
stateName: string;
72-
// Ref image is absent in pwt test results
73-
refImg?: ImageFile;
82+
/**
83+
* @note Ref image is absent in pwt test results
84+
*/
85+
refImg?: RefImageFile;
7486
diffClusters?: CoordBounds[];
7587
expectedImg: ImageFile;
7688
actualImg: ImageFile;
7789
diffImg?: ImageFile | ImageBuffer;
7890
diffOptions: DiffOptions;
79-
differentPixels?: number; // defined if hermione >= 8.2.0
80-
diffRatio?: number; // defined if hermione >= 8.2.0
91+
/**
92+
* @note defined if hermione >= 8.2.0
93+
*/
94+
differentPixels?: number;
95+
/**
96+
* @note defined if hermione >= 8.2.0
97+
*/
98+
diffRatio?: number;
8199
}
82100

83101
interface AssertViewSuccess {
84102
stateName: string;
85-
refImg: ImageFile;
103+
refImg: RefImageFile;
86104
}
87105

88106
export interface ImageInfoSuccess {
89107
status: TestStatus.SUCCESS;
90108
stateName: string;
91-
// Ref image may be absent in pwt test results
92-
refImg?: ImageFile;
109+
/**
110+
* @note Ref image is absent in pwt test results
111+
*/
112+
refImg?: RefImageFile;
93113
diffClusters?: CoordBounds[];
94114
expectedImg: ImageFile;
95115
actualImg?: ImageFile;
@@ -109,15 +129,17 @@ export interface ImageInfoNoRef {
109129
status: TestStatus.ERROR;
110130
error?: TestError;
111131
stateName: string;
112-
// Ref image may be absent in pwt test results
113-
refImg?: ImageFile;
132+
/**
133+
* @note Ref image is absent in pwt test results
134+
*/
135+
refImg?: RefImageFile;
114136
actualImg: ImageFile;
115137
}
116138

117139
export interface ImageInfoUpdated {
118140
status: TestStatus.UPDATED;
119141
stateName: string;
120-
refImg: ImageFile;
142+
refImg: RefImageFile;
121143
actualImg: ImageFile;
122144
expectedImg: ImageFile;
123145
}

test/unit/lib/gui/tool-runner/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ describe('lib/gui/tool-runner/index', () => {
9595
}).ToolRunner;
9696

9797
sandbox.stub(logger, 'warn');
98+
99+
sandbox.stub(process, 'cwd').returns('/ref/cwd');
98100
});
99101

100102
afterEach(() => sandbox.restore());
@@ -240,7 +242,7 @@ describe('lib/gui/tool-runner/index', () => {
240242
await gui.updateReferenceImage(testRefUpdateData);
241243

242244
assert.calledOnceWith(toolAdapter.updateReference, {
243-
refImg: {path: '/ref/path1', size: {height: 100, width: 200}},
245+
refImg: {path: '/ref/path1', relativePath: '../path1', size: {height: 100, width: 200}},
244246
state: 'plain1'
245247
});
246248
});
@@ -289,11 +291,11 @@ describe('lib/gui/tool-runner/index', () => {
289291

290292
assert.calledTwice(toolAdapter.updateReference);
291293
assert.calledWith(toolAdapter.updateReference.firstCall, {
292-
refImg: {path: '/ref/path1', size: {height: 100, width: 200}},
294+
refImg: {path: '/ref/path1', relativePath: '../path1', size: {height: 100, width: 200}},
293295
state: 'plain1'
294296
});
295297
assert.calledWith(toolAdapter.updateReference.secondCall, {
296-
refImg: {path: '/ref/path2', size: {height: 200, width: 300}},
298+
refImg: {path: '/ref/path2', relativePath: '../path2', size: {height: 200, width: 300}},
297299
state: 'plain2'
298300
});
299301
});

0 commit comments

Comments
 (0)