mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 12:09:14 +08:00
scripts: support run visual-regression diff locally
This commit is contained in:
parent
635e05b7d8
commit
053b957f03
@ -21,6 +21,8 @@ import { assert } from 'console';
|
||||
|
||||
const ALI_OSS_BUCKET = 'antd-visual-diff';
|
||||
|
||||
const isLocalEnv = process.env.LOCAL;
|
||||
|
||||
const compareScreenshots = async (
|
||||
baseImgPath: string,
|
||||
currentImgPath: string,
|
||||
@ -131,7 +133,7 @@ function generateReport(
|
||||
targetRef: string,
|
||||
prId: string,
|
||||
): [string, string] {
|
||||
const publicPath = `${ossDomain}/pr-${prId}`;
|
||||
const publicPath = isLocalEnv ? path.resolve(__dirname, '../..') : `${ossDomain}/pr-${prId}`;
|
||||
|
||||
const commonHeader = `
|
||||
## Visual Regression Report for PR #${prId}
|
||||
@ -209,20 +211,32 @@ ${commonHeader}
|
||||
async function boot() {
|
||||
const { prId, baseRef: targetBranch = 'master' } = parseArgs();
|
||||
|
||||
console.log(
|
||||
chalk.green(
|
||||
'Preparing image snapshots from latest `%s` branch for pr %s\n',
|
||||
targetBranch,
|
||||
prId,
|
||||
),
|
||||
);
|
||||
const baseImgSourceDir = path.resolve(__dirname, `../../imageSnapshots-${targetBranch}`);
|
||||
await fse.ensureDir(baseImgSourceDir);
|
||||
|
||||
const targetRef = await getBranchLatestRef(targetBranch);
|
||||
assert(targetRef, `Missing ref from ${targetBranch}`);
|
||||
if (isLocalEnv) {
|
||||
if (!fse.existsSync(baseImgSourceDir)) {
|
||||
console.log(
|
||||
chalk.yellow(
|
||||
`Please prepare image snapshots in folder \`$projectRoot/${path.basename(
|
||||
baseImgSourceDir,
|
||||
)}\` from latest \`${targetBranch}\` branch`,
|
||||
),
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
} else {
|
||||
console.log(
|
||||
chalk.green(
|
||||
`Preparing image snapshots from latest \`${targetBranch}\` branch for pr \`${prId}\`\n`,
|
||||
),
|
||||
);
|
||||
await fse.ensureDir(baseImgSourceDir);
|
||||
|
||||
await downloadBaseSnapshots(targetRef, baseImgSourceDir);
|
||||
const targetRef = await getBranchLatestRef(targetBranch);
|
||||
assert(targetRef, `Missing ref from ${targetBranch}`);
|
||||
|
||||
await downloadBaseSnapshots(targetRef, baseImgSourceDir);
|
||||
}
|
||||
|
||||
const currentImgSourceDir = path.resolve(__dirname, '../../imageSnapshots');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user