@@ -221,74 +221,88 @@ describe("Main", function () {
221221 } ) ;
222222
223223 describe ( "Reporting" , function ( ) {
224- var triggerDelayedPromise = function ( ) {
225- jasmine . clock ( ) . tick ( 100 ) ;
226- } ;
227-
228- beforeEach ( function ( ) {
229- jasmine . clock ( ) . install ( ) ;
230- } ) ;
231-
232- afterEach ( function ( ) {
233- jasmine . clock ( ) . uninstall ( ) ;
234- } ) ;
235-
236- it ( "should report a starting comparison with reference image" , function ( ) {
224+ it ( "should report a starting comparison with reference image" , function ( done ) {
237225 setUpReferenceImage ( "the image" , "the viewport" ) ;
238226
239227 csscritic . add ( "samplepage.html" ) ;
240- csscritic . execute ( ) ;
228+ csscritic
229+ . execute ( )
230+ . then ( null , function ( ) { } ) // catch error
231+ . then ( function ( ) {
232+ expect (
233+ reporting . doReportConfiguredComparison
234+ ) . toHaveBeenCalledWith (
235+ {
236+ testCase : {
237+ url : "samplepage.html" ,
238+ } ,
239+ referenceImage : "the image" ,
240+ viewport : "the viewport" ,
241+ } ,
242+ true
243+ ) ;
241244
242- triggerDelayedPromise ( ) ;
243- expect ( reporting . doReportConfiguredComparison ) . toHaveBeenCalledWith (
244- {
245- testCase : {
246- url : "samplepage.html" ,
247- } ,
248- referenceImage : "the image" ,
249- viewport : "the viewport" ,
250- } ,
251- true
252- ) ;
245+ done ( ) ;
246+ } ) ;
253247 } ) ;
254248
255- it ( "should report a starting comparison without reference image" , function ( ) {
249+ it ( "should report a starting comparison without reference image" , function ( done ) {
256250 setUpReferenceImageMissing ( ) ;
257251
258252 csscritic . add ( "samplepage.html" ) ;
259- csscritic . execute ( ) ;
253+ csscritic
254+ . execute ( )
255+ . then ( null , function ( ) { } ) // catch error
256+ . then ( function ( ) {
257+ expect (
258+ reporting . doReportConfiguredComparison
259+ ) . toHaveBeenCalledWith (
260+ {
261+ testCase : {
262+ url : "samplepage.html" ,
263+ } ,
264+ } ,
265+ true
266+ ) ;
260267
261- triggerDelayedPromise ( ) ;
262- expect ( reporting . doReportConfiguredComparison ) . toHaveBeenCalledWith (
263- {
264- testCase : {
265- url : "samplepage.html" ,
266- } ,
267- } ,
268- true
269- ) ;
268+ done ( ) ;
269+ } ) ;
270270 } ) ;
271271
272- it ( "should wait for reporting on starting comparison to finish" , function ( ) {
273- var defer = ayepromise . defer ( ) ,
272+ var sleep = function ( ) {
273+ return new Promise ( function ( fulfill ) {
274+ setTimeout ( fulfill , 100 ) ;
275+ } ) ;
276+ } ;
277+
278+ it ( "should wait for reporting on starting comparison to finish" , function ( done ) {
279+ var reportingFulfill ,
274280 callback = jasmine . createSpy ( "callback" ) ;
275281
276282 setUpReferenceImageMissing ( ) ;
277283 setUpComparison ( { testCase : { url : "something" } } ) ;
278284 csscritic . add ( "something" ) ;
279285
280286 reporting . doReportConfiguredComparison . and . returnValue (
281- defer . promise
287+ new Promise ( function ( fulfill ) {
288+ reportingFulfill = fulfill ;
289+ } )
282290 ) ;
283291 csscritic . execute ( ) . then ( callback ) ;
284292
285- triggerDelayedPromise ( ) ;
286- expect ( callback ) . not . toHaveBeenCalled ( ) ;
293+ sleep ( )
294+ . then ( function ( ) {
295+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
296+
297+ reportingFulfill ( ) ;
287298
288- defer . resolve ( ) ;
299+ return sleep ( ) ;
300+ } )
301+ . then ( function ( ) {
302+ expect ( callback ) . toHaveBeenCalled ( ) ;
289303
290- triggerDelayedPromise ( ) ;
291- expect ( callback ) . toHaveBeenCalled ( ) ;
304+ done ( ) ;
305+ } ) ;
292306 } ) ;
293307
294308 it ( "should call final report on empty test case list and report as failed" , function ( done ) {
@@ -297,46 +311,63 @@ describe("Main", function () {
297311
298312 done ( ) ;
299313 } ) ;
300-
301- triggerDelayedPromise ( ) ;
302314 } ) ;
303315
304- it ( "should wait for reporting on comparison to finish" , function ( ) {
305- var defer = ayepromise . defer ( ) ,
316+ it ( "should wait for reporting on comparison to finish" , function ( done ) {
317+ var reportingFulfill ,
306318 callback = jasmine . createSpy ( "callback" ) ;
307319
308320 setUpReferenceImage ( "the image" , "the viewport" ) ;
309321 setUpComparison ( {
310322 status : "success" ,
311323 } ) ;
312324
313- reporting . doReportComparison . and . returnValue ( defer . promise ) ;
325+ reporting . doReportComparison . and . returnValue (
326+ new Promise ( function ( fulfill ) {
327+ reportingFulfill = fulfill ;
328+ } )
329+ ) ;
314330 csscritic . add ( "a_test" ) ;
315331 csscritic . execute ( ) . then ( callback ) ;
316332
317- triggerDelayedPromise ( ) ;
318- expect ( callback ) . not . toHaveBeenCalled ( ) ;
333+ sleep ( )
334+ . then ( function ( ) {
335+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
319336
320- defer . resolve ( ) ;
337+ reportingFulfill ( ) ;
338+ return sleep ( ) ;
339+ } )
340+ . then ( function ( ) {
341+ expect ( callback ) . toHaveBeenCalled ( ) ;
321342
322- triggerDelayedPromise ( ) ;
323- expect ( callback ) . toHaveBeenCalled ( ) ;
343+ done ( ) ;
344+ } ) ;
324345 } ) ;
325346
326- it ( "should wait for reporting on final report to finish" , function ( ) {
327- var defer = ayepromise . defer ( ) ,
347+ it ( "should wait for reporting on final report to finish" , function ( done ) {
348+ var reportingFulfill ,
328349 callback = jasmine . createSpy ( "callback" ) ;
329350
330- reporting . doReportTestSuite . and . returnValue ( defer . promise ) ;
351+ reporting . doReportTestSuite . and . returnValue (
352+ new Promise ( function ( fulfill ) {
353+ reportingFulfill = fulfill ;
354+ } )
355+ ) ;
331356 csscritic . execute ( ) . then ( callback ) ;
332357
333- triggerDelayedPromise ( ) ;
334- expect ( callback ) . not . toHaveBeenCalled ( ) ;
358+ sleep ( )
359+ . then ( function ( ) {
360+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
361+
362+ reportingFulfill ( ) ;
335363
336- defer . resolve ( ) ;
364+ return sleep ( ) ;
365+ } )
366+ . then ( function ( ) {
367+ expect ( callback ) . toHaveBeenCalled ( ) ;
337368
338- triggerDelayedPromise ( ) ;
339- expect ( callback ) . toHaveBeenCalled ( ) ;
369+ done ( ) ;
370+ } ) ;
340371 } ) ;
341372 } ) ;
342373
0 commit comments