Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/html-reporter/src/testErrorView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const TestScreenshotErrorView: React.FC<{
diff: ImageDiff,
}> = ({ diff }) => {
return <div data-testid='test-screenshot-error-view' className='test-error-view'>
<ImageDiffView key='image-diff' diff={diff} hideDetails={true}></ImageDiffView>
<ImageDiffView key='image-diff' diff={diff} hideDetails={true} enableBlink={true}></ImageDiffView>
</div>;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/html-reporter/src/testResultView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const TestResultView: React.FC<{
{diffs.map((diff, index) =>
<Anchor key={`diff-${index}`} id={diff.anchors}>
<AutoChip dataTestId='test-results-image-diff' header={`Image mismatch: ${diff.name}`} revealOnAnchorId={diff.anchors}>
<ImageDiffView diff={diff}/>
<ImageDiffView diff={diff} enableBlink={true}/>
</AutoChip>
</Anchor>
)}
Expand Down
16 changes: 14 additions & 2 deletions packages/web/src/shared/imageDiffView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ export const ImageDiffView: React.FC<{
diff: ImageDiff,
noTargetBlank?: boolean,
hideDetails?: boolean,
}> = ({ diff, noTargetBlank, hideDetails }) => {
const [mode, setMode] = React.useState<'diff' | 'actual' | 'expected' | 'slider' | 'sxs'>(diff.diff ? 'diff' : 'actual');
enableBlink?: boolean,
}> = ({ diff, noTargetBlank, hideDetails, enableBlink }) => {
const [mode, setMode] = React.useState<'diff' | 'actual' | 'expected' | 'slider' | 'sxs' | 'blink'>(diff.diff ? 'diff' : 'actual');
const [blinkExpected, setBlinkExpected] = React.useState(false);
const [showSxsDiff, setShowSxsDiff] = React.useState<boolean>(false);

const [expectedImage, setExpectedImage] = React.useState<HTMLImageElement | null>(null);
Expand All @@ -82,6 +84,13 @@ export const ImageDiffView: React.FC<{
})();
}, [diff]);

React.useEffect(() => {
if (!enableBlink || mode !== 'blink')
return;
const interval = window.setInterval(() => setBlinkExpected(expected => !expected), 500);
return () => window.clearInterval(interval);
}, [enableBlink, mode]);

const isLoaded = expectedImage && actualImage && diffImage;

const imageWidth = isLoaded ? Math.max(expectedImage.naturalWidth, actualImage.naturalWidth, 200) : 500;
Expand All @@ -105,18 +114,21 @@ export const ImageDiffView: React.FC<{
{modeTab('expected', expectedImageTitle)}
{modeTab('sxs', 'Side by side')}
{modeTab('slider', 'Slider')}
{enableBlink && modeTab('blink', 'Blink')}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this would be just another option without any "special" treatment which requires a dedicated Boolean parameter such as "enableBlink". I assume the justification is that this is a "new" thing, separate from the current other view options, and so you wish to wrap it in a feature-flag of some sort.

</div>
<div style={{ display: 'flex', justifyContent: 'center', flex: 'auto', minHeight: fitHeight + 60 }}>
{diff.diff && mode === 'diff' && <ImageWithSize image={diffImage} alt='Diff' hideSize={hideDetails} canvasWidth={fitWidth} canvasHeight={fitHeight} scale={scale}/>}
{diff.diff && mode === 'actual' && <ImageWithSize image={actualImage} alt='Actual' hideSize={hideDetails} canvasWidth={fitWidth} canvasHeight={fitHeight} scale={scale}/>}
{diff.diff && mode === 'expected' && <ImageWithSize image={expectedImage} alt={expectedImageTitle} hideSize={hideDetails} canvasWidth={fitWidth} canvasHeight={fitHeight} scale={scale}/>}
{diff.diff && mode === 'slider' && <ImageDiffSlider expectedImage={expectedImage} actualImage={actualImage} hideSize={hideDetails} canvasWidth={fitWidth} canvasHeight={fitHeight} scale={scale} expectedTitle={expectedImageTitle} />}
{diff.diff && mode === 'blink' && <ImageWithSize image={blinkExpected ? expectedImage : actualImage} title={blinkExpected ? expectedImageTitle : 'Actual'} hideSize={hideDetails} canvasWidth={fitWidth} canvasHeight={fitHeight} scale={scale}/>}
{diff.diff && mode === 'sxs' && <div style={{ display: 'flex' }}>
<ImageWithSize image={expectedImage} title={expectedImageTitle} hideSize={hideDetails} canvasWidth={sxsScale * imageWidth} canvasHeight={sxsScale * imageHeight} scale={sxsScale} />
<ImageWithSize image={showSxsDiff ? diffImage : actualImage} title={showSxsDiff ? 'Diff' : 'Actual'} onClick={() => setShowSxsDiff(!showSxsDiff)} hideSize={hideDetails} canvasWidth={sxsScale * imageWidth} canvasHeight={sxsScale * imageHeight} scale={sxsScale} />
</div>}
{!diff.diff && mode === 'actual' && <ImageWithSize image={actualImage} title='Actual' hideSize={hideDetails} canvasWidth={fitWidth} canvasHeight={fitHeight} scale={scale}/>}
{!diff.diff && mode === 'expected' && <ImageWithSize image={expectedImage} title={expectedImageTitle} hideSize={hideDetails} canvasWidth={fitWidth} canvasHeight={fitHeight} scale={scale}/>}
{!diff.diff && mode === 'blink' && <ImageWithSize image={blinkExpected ? expectedImage : actualImage} title={blinkExpected ? expectedImageTitle : 'Actual'} hideSize={hideDetails} canvasWidth={fitWidth} canvasHeight={fitHeight} scale={scale}/>}
{!diff.diff && mode === 'sxs' && <div style={{ display: 'flex' }}>
<ImageWithSize image={expectedImage} title={expectedImageTitle} canvasWidth={sxsScale * imageWidth} canvasHeight={sxsScale * imageHeight} scale={sxsScale} />
<ImageWithSize image={actualImage} title='Actual' canvasWidth={sxsScale * imageWidth} canvasHeight={sxsScale * imageHeight} scale={sxsScale} />
Expand Down
7 changes: 7 additions & 0 deletions tests/playwright-test/reporter-html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
'Expected',
'Side by side',
'Slider',
'Blink',
]);

for (const testId of ['test-results-image-diff', 'test-screenshot-error-view']) {
Expand Down Expand Up @@ -252,6 +253,12 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await expect(imageDiff.locator('img').first()).toHaveAttribute('alt', 'Expected');
await expect(imageDiff.locator('img').last()).toHaveAttribute('alt', 'Actual');
});

await test.step('Blink', async () => {
await imageDiff.getByRole('tab', { name: 'Blink' }).click();
await expect.poll(() => imageDiff.locator('img').getAttribute('alt')).toBe('Actual');
await expect.poll(() => imageDiff.locator('img').getAttribute('alt')).toBe('Expected');
});
});
}
});
Expand Down
Loading