File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -120,11 +120,31 @@ class PlaywrightEnvironment extends NodeEnvironment {
120
120
121
121
const testOptions = this . global . testOptions ;
122
122
function toBeGolden ( received , goldenName ) {
123
- return GoldenUtils . compare ( received , {
123
+ const { snapshotState} = this ;
124
+ const updateSnapshot = snapshotState . _updateSnapshot ;
125
+ const expectedPath = path . join ( testOptions . GOLDEN_DIR , goldenName ) ;
126
+ const fileExists = fs . existsSync ( expectedPath ) ;
127
+ if ( updateSnapshot === 'all' || ( updateSnapshot === 'new' && ! fileExists ) ) {
128
+ fs . writeFileSync ( expectedPath , received ) ;
129
+ if ( fileExists )
130
+ snapshotState . updated ++ ;
131
+ else
132
+ snapshotState . added ++ ;
133
+ return {
134
+ pass : true
135
+ }
136
+ } ;
137
+
138
+ const { pass, message} = GoldenUtils . compare ( received , {
124
139
goldenPath : testOptions . GOLDEN_DIR ,
125
140
outputPath : testOptions . OUTPUT_DIR ,
126
141
goldenName
127
142
} ) ;
143
+ if ( pass )
144
+ snapshotState . matched ++ ;
145
+ else
146
+ snapshotState . unmatched ++ ;
147
+ return { pass, message} ;
128
148
} ;
129
149
this . global . expect . extend ( { toBeGolden } ) ;
130
150
}
You can’t perform that action at this time.
0 commit comments