@@ -407,6 +407,21 @@ describe('TestVariationsService', () => {
407407 updatedAt : new Date ( ) ,
408408 branchName : mergedBranch ,
409409 } ;
410+ const testVariationSecond : TestVariation = {
411+ id : '123' ,
412+ projectId : project . id ,
413+ name : 'Test name second' ,
414+ baselineName : 'baselineName' ,
415+ os : 'OS' ,
416+ browser : 'browser' ,
417+ viewport : 'viewport' ,
418+ device : 'device' ,
419+ ignoreAreas : '[]' ,
420+ comment : 'some comment' ,
421+ createdAt : new Date ( ) ,
422+ updatedAt : new Date ( ) ,
423+ branchName : mergedBranch ,
424+ } ;
410425 const testVariationNoBaseline : TestVariation = {
411426 id : '123' ,
412427 projectId : project . id ,
@@ -439,16 +454,22 @@ describe('TestVariationsService', () => {
439454 } ;
440455 const projectFindOneMock = jest . fn ( ) . mockResolvedValueOnce ( project ) ;
441456 const buildCreateMock = jest . fn ( ) . mockResolvedValueOnce ( build ) ;
442- const variationFindManyMock = jest . fn ( ) . mockResolvedValueOnce ( [ testVariation , testVariationNoBaseline ] ) ;
457+ const variationFindManyMock = jest
458+ . fn ( )
459+ . mockResolvedValueOnce ( [ testVariation , testVariationSecond , testVariationNoBaseline ] ) ;
443460 const image = new PNG ( {
444461 width : 10 ,
445462 height : 10 ,
446463 } ) ;
447464 const getImageMock = jest
448465 . fn ( )
449466 . mockReturnValueOnce ( image )
467+ . mockReturnValueOnce ( image )
450468 . mockReturnValueOnce ( null ) ;
451- const findOrCreateMock = jest . fn ( ) . mockResolvedValueOnce ( testVariationMainBranch ) ;
469+ const findOrCreateMock = jest
470+ . fn ( )
471+ . mockResolvedValueOnce ( testVariationMainBranch )
472+ . mockResolvedValueOnce ( testVariationMainBranch ) ;
452473 const testRunCreateMock = jest . fn ( ) ;
453474 const service = await initModule ( {
454475 projectFindOneMock,
@@ -478,12 +499,22 @@ describe('TestVariationsService', () => {
478499 viewport : testVariation . viewport ,
479500 branchName : project . mainBranchName ,
480501 } ) ;
481- expect ( testRunCreateMock ) . toHaveBeenCalledWith ( testVariationMainBranch , {
502+
503+ await new Promise ( r => setTimeout ( r , 1 ) ) ;
504+ expect ( testRunCreateMock ) . toHaveBeenNthCalledWith ( 1 , testVariationMainBranch , {
482505 ...testVariation ,
483506 buildId : build . id ,
484507 imageBase64 : PNG . sync . write ( image ) . toString ( 'base64' ) ,
485508 diffTollerancePercent : 0 ,
486509 merge : true ,
487510 } ) ;
511+ expect ( testRunCreateMock ) . toHaveBeenNthCalledWith ( 2 , testVariationMainBranch , {
512+ ...testVariationSecond ,
513+ buildId : build . id ,
514+ imageBase64 : PNG . sync . write ( image ) . toString ( 'base64' ) ,
515+ diffTollerancePercent : 0 ,
516+ merge : true ,
517+ } ) ;
518+ expect ( testRunCreateMock ) . toHaveBeenCalledTimes ( 2 ) ;
488519 } ) ;
489520} ) ;
0 commit comments