From ccab3c2d38938485b5bbb1c72bc7c022cf224975 Mon Sep 17 00:00:00 2001 From: Eduardo Lanchares Date: Tue, 2 Apr 2019 12:36:43 +0200 Subject: [PATCH] Fix error when reference and test images don't match --- commands/test.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/commands/test.js b/commands/test.js index 928e671..d3a63e5 100644 --- a/commands/test.js +++ b/commands/test.js @@ -54,17 +54,30 @@ async function compareSnapshot( async function command({ referenceDir, testDir, outputDir, max, threshold }) { await ensureScreenshotsDir(outputDir) - const snapshots = await getScreenshots(referenceDir) + const snapshotsA = new Set(await getScreenshots(referenceDir)) + const snapshotsB = new Set(await getScreenshots(testDir)) + const snapshots = new Set( + [...snapshotsA].filter((snapshot) => snapshotsB.has(snapshot)).slice(0, max) + ) + + if (snapshots.size === 0) { + console.log(`Nothing to compare ¯\\_(ツ)_/¯`) + return + } console.log('Starting tests...\n') - for (let snapshotName of snapshots.slice(0, max)) { - await compareSnapshot(snapshotName, { - referenceDir, - testDir, - outputDir, - threshold, - }) + for (let snapshotName of snapshots) { + try { + await compareSnapshot(snapshotName, { + referenceDir, + testDir, + outputDir, + threshold, + }) + } catch (error) { + // Errors will be printed by PixelDiff instance + } } }