File tree 1 file changed +23
-5
lines changed
1 file changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -147,11 +147,12 @@ function comparePixels(mockName, cb) {
147
147
saveImageStream = fs . createWriteStream ( imagePaths . test ) ;
148
148
149
149
function checkImage ( ) {
150
- var gmOpts = {
151
- file : imagePaths . diff ,
152
- highlightColor : 'purple' ,
153
- tolerance : TOLERANCE
154
- } ;
150
+
151
+ // baseline image must be generated first
152
+ if ( ! doesFileExist ( imagePaths . baseline ) ) {
153
+ var err = new Error ( 'baseline image not found' ) ;
154
+ return onEqualityCheck ( err , false ) ;
155
+ }
155
156
156
157
/*
157
158
* N.B. The non-zero tolerance was added in
@@ -169,6 +170,12 @@ function comparePixels(mockName, cb) {
169
170
* Further investigation is needed.
170
171
*/
171
172
173
+ var gmOpts = {
174
+ file : imagePaths . diff ,
175
+ highlightColor : 'purple' ,
176
+ tolerance : TOLERANCE
177
+ } ;
178
+
172
179
gm . compare (
173
180
imagePaths . test ,
174
181
imagePaths . baseline ,
@@ -194,6 +201,17 @@ function comparePixels(mockName, cb) {
194
201
. on ( 'close' , checkImage ) ;
195
202
}
196
203
204
+ function doesFileExist ( filePath ) {
205
+ try {
206
+ if ( fs . statSync ( filePath ) . isFile ( ) ) return true ;
207
+ }
208
+ catch ( e ) {
209
+ return false ;
210
+ }
211
+
212
+ return false ;
213
+ }
214
+
197
215
function touch ( filePath ) {
198
216
fs . closeSync ( fs . openSync ( filePath , 'w' ) ) ;
199
217
}
You can’t perform that action at this time.
0 commit comments