Skip to content

Commit

Permalink
feat: add relativePath to refImg
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovRoman committed Jun 20, 2024
1 parent ddb5abd commit b722899
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
7 changes: 4 additions & 3 deletions lib/gui/tool-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import type {
TestplaneTestResult,
ImageFile,
ImageInfoDiff, ImageInfoUpdated, ImageInfoWithState,
ReporterConfig, TestSpecByPath
ReporterConfig, TestSpecByPath, RefImageFile
} from '../../types';

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

assertViewResults.push({stateName, refImg, currImg: actualImg, isUpdated: isUpdatedStatus(imageInfo.status)});
});
Expand Down
44 changes: 33 additions & 11 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ export interface ImageFile {
size: ImageSize;
}

export interface RefImageFile extends ImageFile {
/**
* @note defined if testplane >= 8.13.0
*/
relativePath?: string;
}

export interface ImageBuffer {
buffer: Buffer;
}
Expand All @@ -59,7 +66,10 @@ export interface DiffOptions extends LooksSameOptions {
export interface TestError {
name: string;
message: string;
snippet?: string; // defined if testplane >= 8.11.0
/**
* @note defined if testplane >= 8.11.0
*/
snippet?: string;
stack?: string;
stateName?: string;
details?: ErrorDetails
Expand All @@ -69,27 +79,37 @@ export interface TestError {
export interface ImageInfoDiff {
status: TestStatus.FAIL;
stateName: string;
// Ref image is absent in pwt test results
refImg?: ImageFile;
/**
* @note Ref image is absent in pwt test results
*/
refImg?: RefImageFile;
diffClusters?: CoordBounds[];
expectedImg: ImageFile;
actualImg: ImageFile;
diffImg?: ImageFile | ImageBuffer;
diffOptions: DiffOptions;
differentPixels?: number; // defined if hermione >= 8.2.0
diffRatio?: number; // defined if hermione >= 8.2.0
/**
* @note defined if hermione >= 8.2.0
*/
differentPixels?: number;
/**
* @note defined if hermione >= 8.2.0
*/
diffRatio?: number;
}

interface AssertViewSuccess {
stateName: string;
refImg: ImageFile;
refImg: RefImageFile;
}

export interface ImageInfoSuccess {
status: TestStatus.SUCCESS;
stateName: string;
// Ref image may be absent in pwt test results
refImg?: ImageFile;
/**
* @note Ref image is absent in pwt test results
*/
refImg?: RefImageFile;
diffClusters?: CoordBounds[];
expectedImg: ImageFile;
actualImg?: ImageFile;
Expand All @@ -109,15 +129,17 @@ export interface ImageInfoNoRef {
status: TestStatus.ERROR;
error?: TestError;
stateName: string;
// Ref image may be absent in pwt test results
refImg?: ImageFile;
/**
* @note Ref image is absent in pwt test results
*/
refImg?: RefImageFile;
actualImg: ImageFile;
}

export interface ImageInfoUpdated {
status: TestStatus.UPDATED;
stateName: string;
refImg: ImageFile;
refImg: RefImageFile;
actualImg: ImageFile;
expectedImg: ImageFile;
}
Expand Down
8 changes: 5 additions & 3 deletions test/unit/lib/gui/tool-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ describe('lib/gui/tool-runner/index', () => {
}).ToolRunner;

sandbox.stub(logger, 'warn');

sandbox.stub(process, 'cwd').returns('/ref/cwd');
});

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

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

assert.calledTwice(toolAdapter.updateReference);
assert.calledWith(toolAdapter.updateReference.firstCall, {
refImg: {path: '/ref/path1', size: {height: 100, width: 200}},
refImg: {path: '/ref/path1', relativePath: '../path1', size: {height: 100, width: 200}},
state: 'plain1'
});
assert.calledWith(toolAdapter.updateReference.secondCall, {
refImg: {path: '/ref/path2', size: {height: 200, width: 300}},
refImg: {path: '/ref/path2', relativePath: '../path2', size: {height: 200, width: 300}},
state: 'plain2'
});
});
Expand Down

0 comments on commit b722899

Please sign in to comment.