1- import { describe , expect , it , jest } from '@jest/globals' ;
1+ import { afterEach , describe , expect , it , jest } from '@jest/globals' ;
22import { getPackageChangelogs } from '../../changelog/getPackageChangelogs' ;
33import type { BumpInfo } from '../../types/BumpInfo' ;
44import type { ChangeFileInfo , ChangeSet } from '../../types/ChangeInfo' ;
55import type { PackageInfos } from '../../types/PackageInfo' ;
66import { makePackageInfos } from '../../__fixtures__/packageInfos' ;
7+ import { getFileAddedHash } from 'workspace-tools' ;
78
89const commit = 'deadbeef' ;
910const author = 'something@something.com' ;
1011
1112// Mock the methods used from workspace-tools so we don't access the filesystem
1213jest . mock ( 'workspace-tools' , ( ) => ( {
1314 findProjectRoot : ( ) => '.' ,
14- getFileAddedHash : ( ) => commit ,
15+ getFileAddedHash : jest . fn ( ( ) => commit ) ,
1516} ) ) ;
1617
17- function makeChangeInfo ( pkg : string , overrides ?: Partial < ChangeFileInfo > ) : ChangeSet [ number ] {
18+ function makeChangeInfo ( pkg : string , overrides ?: Partial < ChangeFileInfo > , filename ?: string ) : ChangeSet [ number ] {
1819 return {
19- changeFile : `${ pkg } .json` ,
20+ changeFile : filename || `${ pkg } .json` ,
2021 change : {
2122 comment : `comment for ${ pkg } ` ,
2223 dependentChangeType : 'patch' ,
@@ -28,12 +29,18 @@ function makeChangeInfo(pkg: string, overrides?: Partial<ChangeFileInfo>): Chang
2829 } ;
2930}
3031
31- const options : Parameters < typeof getPackageChangelogs > [ 1 ] = {
32+ const options = {
3233 path : '.' ,
3334 changeDir : 'change' ,
3435} ;
3536
3637describe ( 'getPackageChangelogs' , ( ) => {
38+ const getFileAddedHashMock = getFileAddedHash as jest . MockedFunction < typeof getFileAddedHash > ;
39+
40+ afterEach ( ( ) => {
41+ getFileAddedHashMock . mockClear ( ) ;
42+ } ) ;
43+
3744 it ( 'generates correct changelog entries for a single package' , ( ) => {
3845 const changeFileChangeInfos : ChangeSet = [
3946 makeChangeInfo ( 'foo' ) ,
@@ -60,7 +67,9 @@ describe('getPackageChangelogs', () => {
6067 tag : 'foo_v1.0.0' ,
6168 version : '1.0.0' ,
6269 } ) ;
63- expect ( changelogs . foo . comments . patch ) . toHaveLength ( 1 ) ;
70+
71+ // the fake change files use the same default filename
72+ expect ( getFileAddedHashMock ) . toHaveBeenCalledTimes ( 1 ) ;
6473 } ) ;
6574
6675 it ( 'generates correct changelog entries for multiple packages' , ( ) => {
@@ -97,6 +106,8 @@ describe('getPackageChangelogs', () => {
97106 tag : 'bar_v2.0.0' ,
98107 version : '2.0.0' ,
99108 } ) ;
109+
110+ expect ( getFileAddedHashMock ) . toHaveBeenCalledTimes ( 2 ) ;
100111 } ) ;
101112
102113 it ( 'preserves custom properties from change files' , ( ) => {
@@ -155,7 +166,7 @@ describe('getPackageChangelogs', () => {
155166 tag : 'bar_v2.0.0' ,
156167 version : '2.0.0' ,
157168 } ) ;
158- expect ( Object . keys ( changelogs . bar . comments . patch ! ) ) . toHaveLength ( 1 ) ;
169+ expect ( getFileAddedHashMock ) . toHaveBeenCalledTimes ( 1 ) ;
159170 } ) ;
160171
161172 it ( 'records multiple comment entries when a package has a change file AND was part of a dependent bump' , ( ) => {
@@ -220,4 +231,22 @@ describe('getPackageChangelogs', () => {
220231 expect ( changelogs . bar ) . toBeTruthy ( ) ;
221232 expect ( changelogs [ 'private-pkg' ] ) . toBeUndefined ( ) ;
222233 } ) ;
234+
235+ it ( 'omits commit hashes if requested' , ( ) => {
236+ const changeFileChangeInfos : ChangeSet = [ makeChangeInfo ( 'foo' ) ] ;
237+ const packageInfos = makePackageInfos ( { foo : { version : '1.0.0' } } ) ;
238+
239+ const changelogs = getPackageChangelogs (
240+ {
241+ changeFileChangeInfos,
242+ calculatedChangeTypes : { foo : 'patch' } ,
243+ packageInfos,
244+ } ,
245+ { ...options , changelog : { includeCommitHashes : false } }
246+ ) ;
247+
248+ expect ( changelogs . foo . comments . patch ) . toHaveLength ( 1 ) ;
249+ expect ( changelogs . foo . comments . patch ! [ 0 ] . commit ) . toBeUndefined ( ) ;
250+ expect ( getFileAddedHashMock ) . not . toHaveBeenCalled ( ) ;
251+ } ) ;
223252} ) ;
0 commit comments