1
0
mirror of https://github.com/svg/svgo.git synced 2026-01-27 07:02:06 +03:00

ci: dont create diff png if no_diff (#1903)

This commit is contained in:
Seth Falco
2023-12-25 14:06:44 +00:00
committed by GitHub
parent db78c4b7b5
commit 52961ba28c

View File

@@ -42,13 +42,14 @@ const runTests = async (list) => {
await page.goto(`http://localhost:5000/optimized/${name}`);
const optimizedBufferPromise = page.screenshot(screenshotOptions);
const writeDiffs = process.env.NO_DIFF == null;
const diff = writeDiffs && new PNG({ width, height });
const originalPng = PNG.sync.read(originalBuffer);
const optimizedPng = PNG.sync.read(await optimizedBufferPromise);
const diff = new PNG({ width, height });
const matched = pixelmatch(
originalPng.data,
optimizedPng.data,
diff.data,
diff ? diff.data : null,
width,
height,
);
@@ -59,7 +60,7 @@ const runTests = async (list) => {
} else {
mismatched++;
console.error(`${name} is mismatched`);
if (process.env.NO_DIFF == null) {
if (diff) {
const file = path.join(
__dirname,
'regression-diffs',
@@ -73,7 +74,6 @@ const runTests = async (list) => {
const worker = async () => {
let item;
const page = await context.newPage();
await page.setViewportSize({ width, height });
while ((item = list.pop())) {
await processFile(page, item);
}
@@ -81,7 +81,10 @@ const runTests = async (list) => {
};
const browser = await chromium.launch();
const context = await browser.newContext({ javaScriptEnabled: false });
const context = await browser.newContext({
javaScriptEnabled: false,
viewport: { width, height },
});
await Promise.all(
Array.from(new Array(os.cpus().length * 2), () => worker()),
);