import { tagPackages , tagDistTag } from '../../publish/tagPackages' ; import { generateTag } from '../../tag' ; import { BumpInfo } from '../../types/BumpInfo' ; import { gitFailFast } from 'workspace-tools' ; jest . mock ( 'workspace-tools' , ( ) => ( { gitFailFast : jest . fn ( ) , } ) ) ; const createTagParameters = ( tag , cwd ) => { return [ [ 'tag' , '-a' , '-f' , tag , '-m' , tag ] , { cwd } ] ; } ; const noTagBumpInfo = { calculatedChangeTypes : { foo : 'minor' , bar : 'major' , } , packageInfos : { foo : { name : 'foo' , version : '1.0.0' , combinedOptions : { gitTags : false , } , } , bar : { name : 'bar' , version : '1.0.1' , combinedOptions : { gitTags : false , } , } , } , modifiedPackages : new Set ( [ 'foo' , 'bar' ] ) , newPackages : new Set ( ) , } as unknown as BumpInfo ; const oneTagBumpInfo = { calculatedChangeTypes : { foo : 'minor' , bar : 'major' , } , packageInfos : { foo : { name : 'foo' , version : '1.0.0' , combinedOptions : { gitTags : true , } , } , bar : { name : 'bar' , version : '1.0.1' , combinedOptions : { gitTags : false , } , } , } , modifiedPackages : new Set ( [ 'foo' , 'bar' ] ) , newPackages : new Set ( ) , } as unknown as BumpInfo ; beforeEach ( ( ) => { ( gitFailFast as jest . Mock ) . mockReset ( ) ; } ) ; describe ( 'tagPackages' , ( ) => { it ( 'createTag is not called for packages without gitTags' , ( ) => { tagPackages ( noTagBumpInfo , '' ) ; expect ( gitFailFast ) . not . toHaveBeenCalled ( ) ; } ) ; it ( 'createTag is called for packages with gitTags' , ( ) => { tagPackages ( oneTagBumpInfo , '' ) ; expect ( gitFailFast ) . toHaveBeenCalledTimes ( 1 ) ; const newFooTag = generateTag ( 'foo' , oneTagBumpInfo . packageInfos [ 'foo' ] . version ) ; expect ( gitFailFast ) . toHaveBeenCalledWith ( ... createTagParameters ( newFooTag , '' ) ) ; } ) ; } ) ; describe ( 'tagDistTag' , ( ) => { it ( 'createTag is not called for an empty dist tag' , ( ) => { tagDistTag ( '' , '' ) ; expect ( gitFailFast ) . not . toHaveBeenCalled ( ) ; } ) ; it ( 'createTag is called for unique dist tags' , ( ) => { tagDistTag ( 'abc' , '' ) ; expect ( gitFailFast ) . toBeCalledTimes ( 1 ) ; expect ( gitFailFast ) . toHaveBeenCalledWith ( ... createTagParameters ( 'abc' , '' ) ) ; } ) ; } ) ;