Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add relativePath to refImg #553

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading