Skip to content

Commit ccab3c2

Browse files
author
Eduardo Lanchares
committed
Fix error when reference and test images don't match
1 parent f5e481b commit ccab3c2

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

commands/test.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,30 @@ async function compareSnapshot(
5454
async function command({ referenceDir, testDir, outputDir, max, threshold }) {
5555
await ensureScreenshotsDir(outputDir)
5656

57-
const snapshots = await getScreenshots(referenceDir)
57+
const snapshotsA = new Set(await getScreenshots(referenceDir))
58+
const snapshotsB = new Set(await getScreenshots(testDir))
59+
const snapshots = new Set(
60+
[...snapshotsA].filter((snapshot) => snapshotsB.has(snapshot)).slice(0, max)
61+
)
62+
63+
if (snapshots.size === 0) {
64+
console.log(`Nothing to compare ¯\\_(ツ)_/¯`)
65+
return
66+
}
5867

5968
console.log('Starting tests...\n')
6069

61-
for (let snapshotName of snapshots.slice(0, max)) {
62-
await compareSnapshot(snapshotName, {
63-
referenceDir,
64-
testDir,
65-
outputDir,
66-
threshold,
67-
})
70+
for (let snapshotName of snapshots) {
71+
try {
72+
await compareSnapshot(snapshotName, {
73+
referenceDir,
74+
testDir,
75+
outputDir,
76+
threshold,
77+
})
78+
} catch (error) {
79+
// Errors will be printed by PixelDiff instance
80+
}
6881
}
6982
}
7083

0 commit comments

Comments
 (0)