@@ -8,7 +8,7 @@ class SnapshotMatcher {
88 constructor ( ) {
99 this . referenceDir = path . join ( __dirname , '../snapshots/reference' ) ;
1010 this . outputDir = path . join ( __dirname , '../snapshots/output' ) ;
11-
11+
1212 // Ensure directories exist
1313 if ( ! fs . existsSync ( this . referenceDir ) ) {
1414 fs . mkdirSync ( this . referenceDir , { recursive : true } ) ;
@@ -28,7 +28,10 @@ class SnapshotMatcher {
2828 async captureAndValidate ( testName , element = null , updateReference = false ) {
2929 const timestamp = Date . now ( ) ;
3030 const sanitizedName = testName . replace ( / [ ^ a - z A - Z 0 - 9 - ] / g, '_' ) ;
31- const outputPath = path . join ( this . outputDir , `${ sanitizedName } _${ timestamp } .png` ) ;
31+ const outputPath = path . join (
32+ this . outputDir ,
33+ `${ sanitizedName } _${ timestamp } .png` ,
34+ ) ;
3235 const referencePath = path . join ( this . referenceDir , `${ sanitizedName } .png` ) ;
3336
3437 try {
@@ -42,7 +45,7 @@ class SnapshotMatcher {
4245 // On iOS/Android, Detox saves screenshots to artifacts directory
4346 // We need to find and copy the latest screenshot
4447 const artifactsPath = this . findLatestScreenshot ( sanitizedName ) ;
45-
48+
4649 if ( artifactsPath && fs . existsSync ( artifactsPath ) ) {
4750 // Copy to output directory
4851 fs . copyFileSync ( artifactsPath , outputPath ) ;
@@ -58,15 +61,21 @@ class SnapshotMatcher {
5861 // Compare with reference if it exists
5962 if ( fs . existsSync ( referencePath ) ) {
6063 const matched = await this . compareImages ( outputPath , referencePath ) ;
61- console . log ( `${ matched ? '✅' : '❌' } Snapshot ${ matched ? 'matches' : 'differs from' } reference` ) ;
64+ console . log (
65+ `${ matched ? '✅' : '❌' } Snapshot ${ matched ? 'matches' : 'differs from' } reference` ,
66+ ) ;
6267 return { path : outputPath , matched, referencePath } ;
6368 } else {
6469 console . log ( `⚠️ No reference snapshot found at: ${ referencePath } ` ) ;
65- console . log ( `💡 Run with updateReference=true to create reference snapshot` ) ;
70+ console . log (
71+ `💡 Run with updateReference=true to create reference snapshot` ,
72+ ) ;
6673 return { path : outputPath , matched : null , needsReference : true } ;
6774 }
6875 } else {
69- throw new Error ( `Could not find captured screenshot for ${ sanitizedName } ` ) ;
76+ throw new Error (
77+ `Could not find captured screenshot for ${ sanitizedName } ` ,
78+ ) ;
7079 }
7180 } catch ( error ) {
7281 console . error ( `❌ Error capturing screenshot: ${ error . message } ` ) ;
@@ -76,27 +85,32 @@ class SnapshotMatcher {
7685
7786 /**
7887 * Find the latest screenshot file created by Detox
79- * @param {string } name - Test name
88+ * @param {string } _name - Test name
8089 * @returns {string|null } Path to screenshot file
8190 */
82- findLatestScreenshot ( name ) {
91+ findLatestScreenshot ( _name ) {
8392 // Detox saves screenshots in artifacts directory
8493 const possiblePaths = [
85- path . join ( process . cwd ( ) , 'artifacts' , `${ name } .png` ) ,
86- path . join ( process . cwd ( ) , 'e2e' , 'artifacts' , `${ name } .png` ) ,
87- path . join ( process . cwd ( ) , 'artifacts' , 'ios.sim.debug' , `${ name } .png` ) ,
88- path . join ( process . cwd ( ) , 'artifacts' , 'android.emu.debug' , `${ name } .png` ) ,
94+ path . join ( process . cwd ( ) , 'artifacts' , `${ _name } .png` ) ,
95+ path . join ( process . cwd ( ) , 'e2e' , 'artifacts' , `${ _name } .png` ) ,
96+ path . join ( process . cwd ( ) , 'artifacts' , 'ios.sim.debug' , `${ _name } .png` ) ,
97+ path . join (
98+ process . cwd ( ) ,
99+ 'artifacts' ,
100+ 'android.emu.debug' ,
101+ `${ _name } .png` ,
102+ ) ,
89103 ] ;
90104
91105 // Also check for timestamped versions
92106 const artifactsDir = path . join ( process . cwd ( ) , 'artifacts' ) ;
93107 if ( fs . existsSync ( artifactsDir ) ) {
94108 const files = fs . readdirSync ( artifactsDir , { recursive : true } ) ;
95109 const screenshots = files
96- . filter ( f => f . includes ( name ) && f . endsWith ( '.png' ) )
110+ . filter ( f => f . includes ( _name ) && f . endsWith ( '.png' ) )
97111 . map ( f => ( {
98112 path : path . join ( artifactsDir , f ) ,
99- mtime : fs . statSync ( path . join ( artifactsDir , f ) ) . mtime
113+ mtime : fs . statSync ( path . join ( artifactsDir , f ) ) . mtime ,
100114 } ) )
101115 . sort ( ( a , b ) => b . mtime - a . mtime ) ;
102116
@@ -129,7 +143,9 @@ class SnapshotMatcher {
129143
130144 // Basic size check
131145 if ( image1 . length !== image2 . length ) {
132- console . log ( `📏 Image sizes differ: ${ image1 . length } vs ${ image2 . length } bytes` ) ;
146+ console . log (
147+ `📏 Image sizes differ: ${ image1 . length } vs ${ image2 . length } bytes` ,
148+ ) ;
133149 return false ;
134150 }
135151
@@ -173,12 +189,12 @@ class SnapshotMatcher {
173189 } ) ;
174190
175191 // Keep only latest N for each test
176- Object . entries ( groups ) . forEach ( ( [ testName , fileList ] ) => {
192+ Object . entries ( groups ) . forEach ( ( [ _testName , fileList ] ) => {
177193 if ( fileList . length > keep ) {
178194 const sorted = fileList
179195 . map ( f => ( {
180196 name : f ,
181- mtime : fs . statSync ( path . join ( this . outputDir , f ) ) . mtime
197+ mtime : fs . statSync ( path . join ( this . outputDir , f ) ) . mtime ,
182198 } ) )
183199 . sort ( ( a , b ) => b . mtime - a . mtime ) ;
184200
@@ -193,4 +209,3 @@ class SnapshotMatcher {
193209}
194210
195211module . exports = SnapshotMatcher ;
196-
0 commit comments