chore: Improve visual regression screenshot warning (#52053)

* chore: Improve visual regression screenshot warning

* chore: update

* what?
This commit is contained in:
𝑾𝒖𝒙𝒉 2024-12-19 15:29:25 +08:00 committed by GitHub
parent 4fcf3da852
commit bc28f57977
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -1,5 +1,7 @@
import { imageDemoTest } from '../../../tests/shared/imageTest';
describe('Affix image', () => {
imageDemoTest('affix');
imageDemoTest('affix', {
onlyViewport: ['debug.tsx'],
});
});

View File

@ -8,6 +8,7 @@ import fse from 'fs-extra';
import { globSync } from 'glob';
import { JSDOM } from 'jsdom';
import MockDate from 'mockdate';
import rcWarning from 'rc-util/lib/warning';
import type { HTTPRequest } from 'puppeteer';
import ReactDOMServer from 'react-dom/server';
@ -202,6 +203,14 @@ export default function imageTest(
if (!options.onlyViewport) {
// Get scroll height of the rendered page and set viewport
const bodyHeight = await page.evaluate(() => document.body.scrollHeight);
// loooooong image
rcWarning(
bodyHeight < 4096, // Expected height
`[IMAGE TEST] [${identifier}] may cause screenshots to be very long and unacceptable.
Please consider using \`onlyViewport: ["filename.tsx"]\`, read more: https://github.com/ant-design/ant-design/pull/52053`,
);
await page.setViewport({ width: 800, height: bodyHeight });
}