File tree Expand file tree Collapse file tree 1 file changed +23
-5
lines changed Expand file tree Collapse file tree 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) {
147147 saveImageStream = fs . createWriteStream ( imagePaths . test ) ;
148148
149149 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+ }
155156
156157 /*
157158 * N.B. The non-zero tolerance was added in
@@ -169,6 +170,12 @@ function comparePixels(mockName, cb) {
169170 * Further investigation is needed.
170171 */
171172
173+ var gmOpts = {
174+ file : imagePaths . diff ,
175+ highlightColor : 'purple' ,
176+ tolerance : TOLERANCE
177+ } ;
178+
172179 gm . compare (
173180 imagePaths . test ,
174181 imagePaths . baseline ,
@@ -194,6 +201,17 @@ function comparePixels(mockName, cb) {
194201 . on ( 'close' , checkImage ) ;
195202}
196203
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+
197215function touch ( filePath ) {
198216 fs . closeSync ( fs . openSync ( filePath , 'w' ) ) ;
199217}
You can’t perform that action at this time.
0 commit comments