diff --git a/lib/errors/index.ts b/lib/errors/index.ts index 0025a8cd3..3cad41efb 100644 --- a/lib/errors/index.ts +++ b/lib/errors/index.ts @@ -22,6 +22,8 @@ export interface ImageDiffError { diffClusters: CoordBounds[]; diffBuffer?: ArrayBuffer; diffImg?: ImageFile; + differentPixels?: number; // defined if hermione >= 8.2.0 + diffRatio?: number; // defined if hermione >= 8.2.0 } export interface NoRefImageError { diff --git a/lib/static/components/state/index.jsx b/lib/static/components/state/index.jsx index 384d9cc6b..93372de4b 100644 --- a/lib/static/components/state/index.jsx +++ b/lib/static/components/state/index.jsx @@ -125,7 +125,23 @@ class State extends Component { ); } - _getStateTitle() { + _getDisplayedDiffPercentValue(ratio) { + const percent = ratio * 100; + const percentThreshold = 0.001; + const percentString = String(percent); + + if (percent < percentThreshold) { + return `< ${percentThreshold}` + } + + if (percent > 1) { + return percentString.slice(0, 4); + } + + return percentString.slice(0, 5); + } + + _getStateTitleWithDiffCount() { const {image, shouldImageBeOpened} = this.props; if (!image.stateName) { @@ -138,7 +154,15 @@ class State extends Component { `state-title_${image.status}` ); - return
{image.stateName}
; + let displayedText = image.stateName; + + if (image.differentPixels && image.diffRatio) { + const displayedDiffPercent = this._getDisplayedDiffPercentValue(image.diffRatio); + + displayedText += ` (diff: ${image.differentPixels}px, ${displayedDiffPercent}%)`; + } + + return
{displayedText}
; } render() { @@ -146,7 +170,7 @@ class State extends Component { return (
- {this._getStateTitle()} + {this._getStateTitleWithDiffCount()}
); } @@ -168,7 +192,7 @@ class State extends Component { return (
- {this._getStateTitle()} + {this._getStateTitleWithDiffCount()} {this._drawFailImageControls()} {this._drawUpdatedImageControls()} {elem ?
{elem}
: null} diff --git a/lib/test-adapter/hermione.ts b/lib/test-adapter/hermione.ts index c82b6ddf3..21f8b82b4 100644 --- a/lib/test-adapter/hermione.ts +++ b/lib/test-adapter/hermione.ts @@ -112,7 +112,9 @@ export class HermioneTestAdapter implements ReporterTestResult { ...(diffImg ? {diffImg} : {}), expectedImg: _.clone(assertResult.refImg), diffClusters: assertResult.diffClusters, - diffOptions: assertResult.diffOpts + diffOptions: assertResult.diffOpts, + differentPixels: assertResult.differentPixels, + diffRatio: assertResult.diffRatio } satisfies ImageInfoDiff; } else if (isNoRefImageError(assertResult)) { return { diff --git a/lib/types.ts b/lib/types.ts index 7fb67261a..a17cb3088 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -72,6 +72,8 @@ export interface ImageInfoDiff { actualImg: ImageFile; diffImg?: ImageFile | ImageBuffer; diffOptions: DiffOptions; + differentPixels?: number; // defined if hermione >= 8.2.0 + diffRatio?: number; // defined if hermione >= 8.2.0 } interface AssertViewSuccess { diff --git a/test/unit/lib/test-adapter/hermione.ts b/test/unit/lib/test-adapter/hermione.ts index be8bc8a4a..7b450cd00 100644 --- a/test/unit/lib/test-adapter/hermione.ts +++ b/test/unit/lib/test-adapter/hermione.ts @@ -237,7 +237,9 @@ describe('HermioneTestAdapter', () => { name: 'ImageDiffError', refImg: {path: 'ref-path', size: {width: 25, height: 15}}, stack: 'some-stack', - stateName: 'some-state' + stateName: 'some-state', + differentPixels: 100, + diffRatio: 0.01 }] }); @@ -251,7 +253,9 @@ describe('HermioneTestAdapter', () => { expectedImg: {path: 'ref-path', size: {height: 15, width: 25}}, refImg: {path: 'ref-path', size: {height: 15, width: 25}}, diffClusters: [], - diffOptions: {diffColor: '#000'} as any + diffOptions: {diffColor: '#000'} as any, + differentPixels: 100, + diffRatio: 0.01 } ]); });