Skip to content

Commit

Permalink
Fix error when reference and test images don't match
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Lanchares committed Apr 2, 2019
1 parent f5e481b commit ccab3c2
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit ccab3c2

Please sign in to comment.