update tests
This commit is contained in:
parent
8196a6ba1e
commit
8fd3d32925
|
|
@ -34,10 +34,10 @@ export const TestScreenshotErrorView: React.FC<{
|
||||||
}> = ({ errorPrefix, diff, errorSuffix }) => {
|
}> = ({ errorPrefix, diff, errorSuffix }) => {
|
||||||
const prefixHtml = React.useMemo(() => ansiErrorToHtml(errorPrefix), [errorPrefix]);
|
const prefixHtml = React.useMemo(() => ansiErrorToHtml(errorPrefix), [errorPrefix]);
|
||||||
const suffixHtml = React.useMemo(() => ansiErrorToHtml(errorSuffix), [errorSuffix]);
|
const suffixHtml = React.useMemo(() => ansiErrorToHtml(errorSuffix), [errorSuffix]);
|
||||||
return <div className='test-error-message'>
|
return <div data-testid='test-screenshot-error-view' className='test-error-message'>
|
||||||
<div dangerouslySetInnerHTML={{ __html: prefixHtml || '' }}></div>
|
<div dangerouslySetInnerHTML={{ __html: prefixHtml || '' }}></div>
|
||||||
<ImageDiffView key='image-diff' diff={diff} hideDetails={true} ></ImageDiffView>
|
<ImageDiffView key='image-diff' diff={diff} hideDetails={true} ></ImageDiffView>
|
||||||
<div dangerouslySetInnerHTML={{ __html: suffixHtml || '' }}></div>
|
<div data-testid='error-suffix' dangerouslySetInnerHTML={{ __html: suffixHtml || '' }}></div>
|
||||||
</div>;
|
</div>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ export const TestResultView: React.FC<{
|
||||||
</AutoChip>}
|
</AutoChip>}
|
||||||
|
|
||||||
{diffs.map((diff, index) =>
|
{diffs.map((diff, index) =>
|
||||||
<AutoChip key={`diff-${index}`} header={`Image mismatch: ${diff.name}`} targetRef={imageDiffRef}>
|
<AutoChip key={`diff-${index}`} dataTestId='test-results-image-diff' header={`Image mismatch: ${diff.name}`} targetRef={imageDiffRef}>
|
||||||
<ImageDiffView key='image-diff' diff={diff}></ImageDiffView>
|
<ImageDiffView key='image-diff' diff={diff}></ImageDiffView>
|
||||||
</AutoChip>
|
</AutoChip>
|
||||||
)}
|
)}
|
||||||
|
|
@ -160,17 +160,23 @@ function classifyErrors(testErrors: string[], diffs: ImageDiff[]) {
|
||||||
continue;
|
continue;
|
||||||
if (!error.includes(diff.actual!.attachment.name))
|
if (!error.includes(diff.actual!.attachment.name))
|
||||||
continue;
|
continue;
|
||||||
const index = error.search(/Expected:|Previous:|Received:/);
|
|
||||||
|
const lines = error.split('\n');
|
||||||
|
const index = lines.findIndex(line => line.match(/Expected:|Previous:|Received:/));
|
||||||
let errorPrefix;
|
let errorPrefix;
|
||||||
if (index !== -1)
|
if (index !== -1)
|
||||||
errorPrefix = error.slice(0, index);
|
errorPrefix = lines.slice(0, index).join('\n');
|
||||||
else
|
else
|
||||||
errorPrefix = error.split('\n')[0];
|
errorPrefix = lines[0];
|
||||||
|
|
||||||
const callLog = error.indexOf('Call log:');
|
|
||||||
let errorSuffix;
|
let errorSuffix;
|
||||||
if (callLog !== -1)
|
const diffIndex = lines.findIndex(line => line.match(/ +Diff:/));
|
||||||
errorSuffix = error.slice(callLog);
|
// Skip one empty line after the diff too.
|
||||||
|
if (diffIndex !== -1)
|
||||||
|
errorSuffix = lines.slice(diffIndex + 2).join('\n');
|
||||||
|
else
|
||||||
|
errorSuffix = lines.slice(1).join('\n');
|
||||||
|
|
||||||
screenshotError = { type: 'screenshot', diff, errorPrefix, errorSuffix };
|
screenshotError = { type: 'screenshot', diff, errorPrefix, errorSuffix };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ for (const useIntermediateMergeReport of [false] as const) {
|
||||||
await expect(page.locator('text=Image mismatch')).toBeVisible();
|
await expect(page.locator('text=Image mismatch')).toBeVisible();
|
||||||
await expect(page.locator('text=Snapshot mismatch')).toHaveCount(0);
|
await expect(page.locator('text=Snapshot mismatch')).toHaveCount(0);
|
||||||
|
|
||||||
await expect(page.getByTestId('test-result-image-mismatch-tabs').locator('div')).toHaveText([
|
await expect(page.getByTestId('test-screenshot-error-view').getByTestId('test-result-image-mismatch-tabs').locator('div')).toHaveText([
|
||||||
'Diff',
|
'Diff',
|
||||||
'Actual',
|
'Actual',
|
||||||
'Expected',
|
'Expected',
|
||||||
|
|
@ -187,7 +187,9 @@ for (const useIntermediateMergeReport of [false] as const) {
|
||||||
'Slider',
|
'Slider',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const imageDiff = page.getByTestId('test-result-image-mismatch');
|
for (const testId of ['test-results-image-diff', 'test-screenshot-error-view']) {
|
||||||
|
await test.step(testId, async () => {
|
||||||
|
const imageDiff = page.getByTestId(testId).getByTestId('test-result-image-mismatch');
|
||||||
await test.step('Diff', async () => {
|
await test.step('Diff', async () => {
|
||||||
await expect(imageDiff.locator('img')).toHaveAttribute('alt', 'Diff');
|
await expect(imageDiff.locator('img')).toHaveAttribute('alt', 'Diff');
|
||||||
});
|
});
|
||||||
|
|
@ -218,6 +220,8 @@ for (const useIntermediateMergeReport of [false] as const) {
|
||||||
await expect(imageDiff.locator('img').last()).toHaveAttribute('alt', 'Actual');
|
await expect(imageDiff.locator('img').last()).toHaveAttribute('alt', 'Actual');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('should include multiple image diffs', async ({ runInlineTest, page, showReport }) => {
|
test('should include multiple image diffs', async ({ runInlineTest, page, showReport }) => {
|
||||||
const IMG_WIDTH = 200;
|
const IMG_WIDTH = 200;
|
||||||
|
|
@ -285,8 +289,14 @@ for (const useIntermediateMergeReport of [false] as const) {
|
||||||
|
|
||||||
await showReport();
|
await showReport();
|
||||||
await page.click('text=fails');
|
await page.click('text=fails');
|
||||||
await expect(page.locator('data-testid=test-result-image-mismatch')).toHaveCount(3);
|
await expect(page.getByTestId('test-screenshot-error-view').getByTestId('error-suffix')).toContainText([
|
||||||
await expect(page.locator('text=Image mismatch:')).toHaveText([
|
`> 6 | await expect.soft(screenshot).toMatchSnapshot('expected.png');`,
|
||||||
|
`> 7 | await expect.soft(screenshot).toMatchSnapshot('expected.png');`,
|
||||||
|
`> 8 | await expect.soft(screenshot).toMatchSnapshot('expected.png');`,
|
||||||
|
]);
|
||||||
|
const imageDiffs = page.getByTestId('test-results-image-diff');
|
||||||
|
await expect(imageDiffs.getByTestId('test-result-image-mismatch')).toHaveCount(3);
|
||||||
|
await expect(imageDiffs.getByText('Image mismatch:')).toHaveText([
|
||||||
'Image mismatch: expected.png',
|
'Image mismatch: expected.png',
|
||||||
'Image mismatch: expected-1.png',
|
'Image mismatch: expected-1.png',
|
||||||
'Image mismatch: expected-2.png',
|
'Image mismatch: expected-2.png',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue