Skip to content

Commit

Permalink
Merge pull request #46479 from ant-design/feat/support-run-visual-reg…
Browse files Browse the repository at this point in the history
…ression-locally
  • Loading branch information
vagusX committed Dec 15, 2023
2 parents 635e05b + 43563cf commit 3a2cf49
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions scripts/visual-regression/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -209,20 +211,30 @@ ${commonHeader}
async function boot() {
const { prId, baseRef: targetBranch = 'master' } = parseArgs();

const baseImgSourceDir = path.resolve(__dirname, `../../imageSnapshots-${targetBranch}`);

console.log(
chalk.green(
'Preparing image snapshots from latest `%s` branch for pr %s\n',
targetBranch,
prId,
`Preparing image snapshots from latest \`${targetBranch}\` branch for pr \`${prId}\`\n`,
),
);
const baseImgSourceDir = path.resolve(__dirname, `../../imageSnapshots-${targetBranch}`);
await fse.ensureDir(baseImgSourceDir);

const targetRef = await getBranchLatestRef(targetBranch);
assert(targetRef, `Missing ref from ${targetBranch}`);

await downloadBaseSnapshots(targetRef, baseImgSourceDir);
if (!isLocalEnv) {
await downloadBaseSnapshots(targetRef, baseImgSourceDir);
} else 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);
}

const currentImgSourceDir = path.resolve(__dirname, '../../imageSnapshots');

Expand Down

0 comments on commit 3a2cf49

Please sign in to comment.