feat: support options

This commit is contained in:
vagusX 2024-08-08 10:49:13 +08:00
parent 81f5bc53a4
commit bc609d633d
21 changed files with 45 additions and 24 deletions

View File

@ -1,5 +1,5 @@
import { imageDemoTest } from '../../../tests/shared/imageTest';
describe('Breadcrumb image', () => {
imageDemoTest('breadcrumb', { skip: ['react-router.tsx'] });
imageDemoTest('breadcrumb');
});

View File

@ -1 +1 @@
export default { id: 'button', skip: ['loading.tsx'] };
export default { id: 'button', skip: ['loading'] };

View File

@ -1 +1 @@
export default { id: 'config-provider', skip: ['direction.tsx', 'theme.tsx'] };
export default { id: 'config-provider', skip: ['direction', 'theme'] };

View File

@ -1 +1 @@
export default { id: 'dropdown', skip: ['dropdown-button.tsx'] };
export default { id: 'dropdown', skip: ['dropdown-button'] };

View File

@ -1,5 +1,5 @@
import { imageDemoTest } from '../../../tests/shared/imageTest';
describe('float-button image', () => {
imageDemoTest('float-button', { onlyViewport: ['back-top.tsx'] });
imageDemoTest('float-button', { onlyViewport: ['back-top'] });
});

View File

@ -1 +1 @@
export default { id: 'float-button', onlyViewport: ['back-top.tsx'] };
export default { id: 'float-button', onlyViewport: ['back-top'] };

View File

@ -1 +1 @@
export default { id: 'form', skip: ['complex-form-control.tsx'] };
export default { id: 'form', skip: ['complex-form-control'] };

View File

@ -1 +1 @@
export default { id: 'icon', skip: ['basic.tsx'] };
export default { id: 'icon', skip: ['basic'] };

View File

@ -1 +1 @@
export default { id: 'input', skip: ['search-input-loading.tsx'] };
export default { id: 'input', skip: ['search-input-loading'] };

View File

@ -1 +1 @@
export default { id: 'layout', skip: ['fixed-sider.tsx'] };
export default { id: 'layout', skip: ['fixed-sider'] };

View File

@ -1 +1 @@
export default { id: 'list', skip: ['loadmore.tsx'] };
export default { id: 'list', skip: ['loadmore'] };

View File

@ -1 +1 @@
export default { id: 'popconfirm' };
export default { id: 'popconfirm', onlyViewport: ['shift'] };

View File

@ -1 +1 @@
export default { id: 'popover' };
export default { id: 'popover', onlyViewport: ['shift'] };

View File

@ -1 +1 @@
export default { id: 'switch', skip: ['loading.tsx'] };
export default { id: 'switch', skip: ['loading'] };

View File

@ -1 +1 @@
export default { id: 'table', skip: ['virtual-list.tsx'] };
export default { id: 'table', skip: ['virtual-list'] };

View File

@ -1 +1 @@
export default { id: 'tag', skip: ['status.tsx'] };
export default { id: 'tag', skip: ['status'] };

View File

@ -1 +1 @@
export default { id: 'timeline', skip: ['pending.tsx'] };
export default { id: 'timeline', skip: ['pending'] };

View File

@ -1 +1 @@
export default { id: 'tooltip', onlyViewport: ['shift.tsx'] };
export default { id: 'tooltip', onlyViewport: ['shift'] };

View File

@ -1 +1 @@
export default { id: 'tree', skip: ['virtual-scroll.tsx', 'big-data.tsx'] };
export default { id: 'tree', skip: ['virtual-scroll', 'big-data'] };

View File

@ -1 +1 @@
export default { id: 'upload', skip: ['crop-image.tsx'] };
export default { id: 'upload', skip: ['crop-image'] };

View File

@ -15,7 +15,9 @@ import type { LogLevelNames } from 'loglevel';
interface VisualDiffConfig {
id: string;
onlyViewport?: boolean;
skip?: boolean | string[];
onlyViewport?: boolean | string[];
/** Open Trigger to check the popup render */
openTriggerClassName?: string;
}
@ -120,6 +122,14 @@ class BrowserAuto {
const demoUrl = await retrieveDemoUrl(mdPath);
const options = await retrieveConfig(mdPath);
const skip =
Array.isArray(options.skip) &&
options.skip.some((c) => path.basename(mdPath, '.md').endsWith(c));
if (skip) {
loglevel.info('Skip for: %s', mdPath);
return;
}
const query = new URLSearchParams();
query.set('theme', theme);
if (enableCssVar) {
@ -140,7 +150,18 @@ class BrowserAuto {
await page.waitForSelector('.dumi-antd-demo-layout');
if (!options.onlyViewport) {
const onlyViewport =
options.onlyViewport === true ||
(Array.isArray(options.onlyViewport) &&
options.onlyViewport.some((c) => path.basename(mdPath, '.md').endsWith(c)));
loglevel.info(
'visit: %s, onlyViewport: %s, openTriggerClassName: %s',
pageUrl,
onlyViewport,
options.openTriggerClassName,
);
if (!onlyViewport) {
// Get scroll height of the rendered page and set viewport
const bodyHeight = await page.evaluate(() => document.body.scrollHeight);
await page.setViewportSize({ width: 800, height: bodyHeight });
@ -252,8 +273,8 @@ function parseArgs(): {
// 增加并发
await pAll(
visitConfigs.map((visitConfig, i) => async () => {
console.log(
`处理 ${i + 1}/${mdPaths.length}: ${visitConfig.mdPath}-${visitConfig.theme}-${visitConfig.enableCssVar}`,
loglevel.info(
`处理 ${i + 1}/${visitConfigs.length}: ${visitConfig.mdPath} / ${visitConfig.theme} / ${visitConfig.enableCssVar}`,
);
return task(visitConfig);
}),