@@ -322,6 +322,71 @@ describe('hermione test adapter', () => {
322322 imagesInfo : [ { test : 123 } ]
323323 } ) ;
324324 } ) ;
325+
326+ describe ( 'saving error screenshot' , ( ) => {
327+ beforeEach ( ( ) => {
328+ sandbox . stub ( logger , 'warn' ) ;
329+ sandbox . stub ( utils , 'makeDirFor' ) . resolves ( ) ;
330+ sandbox . stub ( fs , 'writeFile' ) . resolves ( ) ;
331+ sandbox . stub ( utils , 'copyFileAsync' ) ;
332+ } ) ;
333+
334+ describe ( 'if screenshot on reject does not exist' , ( ) => {
335+ it ( 'should not save screenshot' , ( ) => {
336+ const testResult = mkTestResult_ ( {
337+ err : { screenshot : { base64 : null } } ,
338+ assertViewResults : [ ]
339+ } ) ;
340+ const hermioneTestAdapter = mkHermioneTestResultAdapter ( testResult ) ;
341+
342+ return hermioneTestAdapter . saveTestImages ( )
343+ . then ( ( ) => assert . notCalled ( fs . writeFile ) ) ;
344+ } ) ;
345+
346+ it ( 'should warn about it' , ( ) => {
347+ const testResult = mkTestResult_ ( {
348+ err : { screenshot : { base64 : null } } ,
349+ assertViewResults : [ ]
350+ } ) ;
351+ const hermioneTestAdapter = mkHermioneTestResultAdapter ( testResult ) ;
352+
353+ return hermioneTestAdapter . saveTestImages ( )
354+ . then ( ( ) => assert . calledWith ( logger . warn , 'Cannot save screenshot on reject' ) ) ;
355+ } ) ;
356+ } ) ;
357+
358+ it ( 'should create directory for screenshot' , ( ) => {
359+ const testResult = mkTestResult_ ( {
360+ err : { screenshot : { base64 : 'base64-data' } } ,
361+ assertViewResults : [ ]
362+ } ) ;
363+ utils . getCurrentPath . returns ( 'dest/path' ) ;
364+ const hermioneTestAdapter = mkHermioneTestResultAdapter ( testResult ) ;
365+
366+ return hermioneTestAdapter . saveTestImages ( )
367+ . then ( ( ) => assert . calledOnceWith ( utils . makeDirFor , sinon . match ( 'dest/path' ) ) ) ;
368+ } ) ;
369+
370+ it ( 'should save screenshot from base64 format' , async ( ) => {
371+ const testResult = mkTestResult_ ( {
372+ err : { screenshot : { base64 : 'base64-data' } } ,
373+ assertViewResults : [ ]
374+ } ) ;
375+ utils . getCurrentPath . returns ( 'dest/path' ) ;
376+ const bufData = new Buffer ( 'base64-data' , 'base64' ) ;
377+ const imagesSaver = { saveImg : sandbox . stub ( ) } ;
378+ const hermioneTestAdapter = mkHermioneTestResultAdapter ( testResult , {
379+ htmlReporter : {
380+ imagesSaver
381+ }
382+ } ) ;
383+
384+ await hermioneTestAdapter . saveTestImages ( 'report/path' ) ;
385+
386+ assert . calledOnceWith ( fs . writeFile , sinon . match ( 'dest/path' ) , bufData , 'base64' ) ;
387+ assert . calledWith ( imagesSaver . saveImg , sinon . match ( 'dest/path' ) , { destPath : 'dest/path' , reportDir : 'report/path' } ) ;
388+ } ) ;
389+ } ) ;
325390 } ) ;
326391
327392 describe ( 'hasDiff()' , ( ) => {
@@ -528,67 +593,6 @@ describe('hermione test adapter', () => {
528593 } ) ;
529594 } ) ;
530595
531- describe ( 'saveErrorScreenshot' , ( ) => {
532- beforeEach ( ( ) => {
533- sandbox . stub ( logger , 'warn' ) ;
534- sandbox . stub ( utils , 'makeDirFor' ) . resolves ( ) ;
535- sandbox . stub ( fs , 'writeFile' ) . resolves ( ) ;
536- sandbox . stub ( utils , 'copyFileAsync' ) ;
537- } ) ;
538-
539- describe ( 'if screenshot on reject does not exist' , ( ) => {
540- it ( 'should not save screenshot' , ( ) => {
541- const testResult = mkTestResult_ ( {
542- err : { screenshot : { base64 : null } }
543- } ) ;
544- const hermioneTestAdapter = mkHermioneTestResultAdapter ( testResult ) ;
545-
546- return hermioneTestAdapter . saveErrorScreenshot ( )
547- . then ( ( ) => assert . notCalled ( fs . writeFile ) ) ;
548- } ) ;
549-
550- it ( 'should warn about it' , ( ) => {
551- const testResult = mkTestResult_ ( {
552- err : { screenshot : { base64 : null } }
553- } ) ;
554- const hermioneTestAdapter = mkHermioneTestResultAdapter ( testResult ) ;
555-
556- return hermioneTestAdapter . saveErrorScreenshot ( )
557- . then ( ( ) => assert . calledWith ( logger . warn , 'Cannot save screenshot on reject' ) ) ;
558- } ) ;
559- } ) ;
560-
561- it ( 'should create directory for screenshot' , ( ) => {
562- const testResult = mkTestResult_ ( {
563- err : { screenshot : { base64 : 'base64-data' } }
564- } ) ;
565- utils . getCurrentPath . returns ( 'dest/path' ) ;
566- const hermioneTestAdapter = mkHermioneTestResultAdapter ( testResult ) ;
567-
568- return hermioneTestAdapter . saveErrorScreenshot ( )
569- . then ( ( ) => assert . calledOnceWith ( utils . makeDirFor , sinon . match ( 'dest/path' ) ) ) ;
570- } ) ;
571-
572- it ( 'should save screenshot from base64 format' , async ( ) => {
573- const testResult = mkTestResult_ ( {
574- err : { screenshot : { base64 : 'base64-data' } }
575- } ) ;
576- utils . getCurrentPath . returns ( 'dest/path' ) ;
577- const bufData = new Buffer ( 'base64-data' , 'base64' ) ;
578- const imagesSaver = { saveImg : sandbox . stub ( ) } ;
579- const hermioneTestAdapter = mkHermioneTestResultAdapter ( testResult , {
580- htmlReporter : {
581- imagesSaver
582- }
583- } ) ;
584-
585- await hermioneTestAdapter . saveErrorScreenshot ( 'report/path' ) ;
586-
587- assert . calledOnceWith ( fs . writeFile , sinon . match ( 'dest/path' ) , bufData , 'base64' ) ;
588- assert . calledWith ( imagesSaver . saveImg , sinon . match ( 'dest/path' ) , { destPath : 'dest/path' , reportDir : 'report/path' } ) ;
589- } ) ;
590- } ) ;
591-
592596 describe ( 'timestamp' , ( ) => {
593597 it ( 'should return corresponding timestamp of the test result' , ( ) => {
594598 const testResult = mkTestResult_ ( {
0 commit comments