Skip to content

Commit

Permalink
ci: dont create diff png if no_diff
Browse files Browse the repository at this point in the history
  • Loading branch information
SethFalco committed Dec 25, 2023
1 parent 3d48f3a commit 998c3de
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions test/regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand All @@ -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',
Expand All @@ -73,15 +74,17 @@ 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);
}
await page.close();
};

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()),
);
Expand Down

0 comments on commit 998c3de

Please sign in to comment.