Skip to content

Commit 9997e69

Browse files
author
Eduardo Lanchares
committed
Add threshold option to test command
1 parent 0187302 commit 9997e69

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

bin/email-diff.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ yargs
6666
default: Infinity,
6767
type: 'number',
6868
})
69+
.option('threshold', {
70+
describe: 'Image diff threshold',
71+
default: 0.01, // 1%
72+
type: 'number',
73+
})
6974
},
7075
(argv) => {
7176
testCommand({

commands/test.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async function getScreenshots(dir) {
3232

3333
async function compareSnapshot(
3434
snapshotName,
35-
{ referenceDir, testDir, outputDir }
35+
{ referenceDir, testDir, outputDir, threshold }
3636
) {
3737
console.log(`Comparing screenshot ${snapshotName}`)
3838

@@ -45,21 +45,26 @@ async function compareSnapshot(
4545
),
4646
imageOutputLimit: PixelDiff.OUTPUT_SIMILAR,
4747
thresholdType: PixelDiff.THRESHOLD_PERCENT,
48-
threshold: 0.01, // 1% threshold
48+
threshold: threshold,
4949
})
5050

5151
return diff.runWithPromise()
5252
}
5353

54-
async function command({ referenceDir, testDir, outputDir, max }) {
54+
async function command({ referenceDir, testDir, outputDir, max, threshold }) {
5555
await ensureScreenshotsDir(outputDir)
5656

5757
const snapshots = await getScreenshots(referenceDir)
5858

5959
console.log('Starting tests...\n')
6060

6161
for (let snapshotName of snapshots.slice(0, max)) {
62-
await compareSnapshot(snapshotName, { referenceDir, testDir, outputDir })
62+
await compareSnapshot(snapshotName, {
63+
referenceDir,
64+
testDir,
65+
outputDir,
66+
threshold,
67+
})
6368
}
6469
}
6570

0 commit comments

Comments
 (0)