File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ interface Options {
2121 width : number ;
2222 viewHeight : number ;
2323 concurrency : number ;
24+ diffAlpha : number ;
2425 summaryFile : string ;
2526}
2627
@@ -33,6 +34,7 @@ function parseArgs(): Options {
3334 width : 1280 ,
3435 viewHeight : 1024 ,
3536 concurrency : 4 ,
37+ diffAlpha : 1 ,
3638 summaryFile : "visual_diffs/results.json" ,
3739 } ;
3840 for ( let i = 0 ; i < args . length ; i ++ ) {
@@ -62,6 +64,10 @@ function parseArgs(): Options {
6264 case "--concurrency" :
6365 opts . concurrency = Number ( args [ ++ i ] ) ;
6466 break ;
67+ case "-a" :
68+ case "--diff-alpha" :
69+ opts . diffAlpha = Number ( args [ ++ i ] ) ;
70+ break ;
6571 case "-s" :
6672 case "--summary-file" :
6773 opts . summaryFile = args [ ++ i ] ;
@@ -104,7 +110,8 @@ function compareImages(
104110 prodPath : string ,
105111 prevPath : string ,
106112 diffPath : string ,
107- tolerance : number
113+ tolerance : number ,
114+ diffAlpha : number
108115) : boolean {
109116 const prod = PNG . sync . read ( fs . readFileSync ( prodPath ) ) ;
110117 const prev = PNG . sync . read ( fs . readFileSync ( prevPath ) ) ;
@@ -121,6 +128,7 @@ function compareImages(
121128 prod . height ,
122129 {
123130 threshold : tolerance ,
131+ alpha : diffAlpha ,
124132 }
125133 ) ;
126134 if ( numDiff > 0 ) {
@@ -188,7 +196,15 @@ async function run() {
188196 new URL ( cleanPath , opts . previewUrl ) . toString ( ) ,
189197 prevSnap
190198 ) ;
191- if ( compareImages ( prodSnap , prevSnap , diffImg , opts . tolerance ) ) {
199+ if (
200+ compareImages (
201+ prodSnap ,
202+ prevSnap ,
203+ diffImg ,
204+ opts . tolerance ,
205+ opts . diffAlpha
206+ )
207+ ) {
192208 console . log ( `MATCH: /${ cleanPath } ` ) ;
193209 matches += 1 ;
194210 pages . push ( { path : `/${ cleanPath } ` , status : "match" } ) ;
You can’t perform that action at this time.
0 commit comments