@@ -121,50 +121,68 @@ for (let mockName of allMockList) {
121121 }
122122 console . log ( '+ test:' , mockName ) ;
123123
124- if ( ! common . doesFileExist ( base ) ) {
125- console . error ( 'baseline image missing' ) ;
126- fs . copyFileSync ( test , diff ) ;
127- failed . add ( mockName ) ;
128- continue ;
129- }
130-
131- const img0 = PNG . sync . read ( fs . readFileSync ( base ) ) ;
132- const img1 = PNG . sync . read ( fs . readFileSync ( test ) ) ;
133- let dimensionMismatch = false ;
134- for ( const key of [ 'height' , 'width' ] ) {
135- const length0 = img0 [ key ] ;
136- const length1 = img1 [ key ] ;
137- if ( length0 !== length1 ) {
138- console . error ( key + 's do not match: ' + length0 + ' vs ' + length1 ) ;
139- dimensionMismatch = true ;
124+ try {
125+ if ( ! common . doesFileExist ( base ) ) {
126+ console . error ( 'baseline image missing' ) ;
127+ fs . copyFileSync ( test , diff ) ;
128+ failed . add ( mockName ) ;
129+ continue ;
140130 }
141- }
142131
143- if ( dimensionMismatch ) {
144- fs . copyFileSync ( test , diff ) ;
145- failed . add ( mockName ) ;
146- continue ;
147- }
132+ const img0 = PNG . sync . read ( fs . readFileSync ( base ) ) ;
133+ const img1 = PNG . sync . read ( fs . readFileSync ( test ) ) ;
134+ let dimensionMismatch = false ;
135+ for ( const key of [ 'height' , 'width' ] ) {
136+ const length0 = img0 [ key ] ;
137+ const length1 = img1 [ key ] ;
138+ if ( length0 !== length1 ) {
139+ console . error ( key + 's do not match: ' + length0 + ' vs ' + length1 ) ;
140+ dimensionMismatch = true ;
141+ }
142+ }
148143
149- if ( virtualWebgl ) {
150- if ( flakyListVirtualWebgl . has ( mockName ) ) threshold = 0.7 ;
151- else threshold = Math . max ( 0.4 , threshold ) ;
152- }
144+ if ( dimensionMismatch ) {
145+ fs . copyFileSync ( test , diff ) ;
146+ failed . add ( mockName ) ;
147+ continue ;
148+ }
153149
154- const { height, width } = img0 ;
155- const imageDiff = new PNG ( { width, height } ) ;
156- const numDiffPixels = pixelmatch ( img0 . data , img1 . data , imageDiff . data , width , height , { threshold } ) ;
150+ if ( virtualWebgl ) {
151+ if ( flakyListVirtualWebgl . has ( mockName ) ) threshold = 0.7 ;
152+ else threshold = Math . max ( 0.4 , threshold ) ;
153+ }
157154
158- if ( numDiffPixels ) {
159- fs . writeFileSync ( diff , PNG . sync . write ( imageDiff ) ) ;
160- console . error ( 'pixels do not match: ' + numDiffPixels ) ;
155+ const { height, width } = img0 ;
156+ const imageDiff = new PNG ( { width, height } ) ;
157+ const numDiffPixels = pixelmatch ( img0 . data , img1 . data , imageDiff . data , width , height , { threshold } ) ;
158+
159+ if ( numDiffPixels ) {
160+ fs . writeFileSync ( diff , PNG . sync . write ( imageDiff ) ) ;
161+ console . error ( 'pixels do not match: ' + numDiffPixels ) ;
162+ failed . add ( mockName ) ;
163+ } else {
164+ // remove when identical
165+ fs . unlinkSync ( test ) ;
166+ }
167+ } catch ( e ) {
168+ console . error ( 'error comparing ' + mockName + ':' , e ) ;
161169 failed . add ( mockName ) ;
162- } else {
163- // remove when identical
164- fs . unlinkSync ( test ) ;
165170 }
166171}
167172
173+ // Debug: list contents of diff folder
174+ console . log ( '\n=== build/test_images/ ===' ) ;
175+ try {
176+ const testFiles = fs . readdirSync ( constants . pathToTestImages ) ;
177+ console . log ( testFiles . length + ' files:' , testFiles . join ( ', ' ) ) ;
178+ } catch { console . log ( '(empty or missing)' ) ; }
179+
180+ console . log ( '=== build/test_images_diff/ ===' ) ;
181+ try {
182+ const diffFiles = fs . readdirSync ( constants . pathToTestImagesDiff ) ;
183+ console . log ( diffFiles . length + ' files:' , diffFiles . join ( ', ' ) ) ;
184+ } catch { console . log ( '(empty or missing)' ) ; }
185+
168186if ( failed . size || skipped . size ) {
169187 throw JSON . stringify (
170188 {
0 commit comments