@@ -13,6 +13,8 @@ jest.mock('../../../config/nx-json', () => ({
1313 readNxJson : jest . fn ( ) ,
1414} ) ) ;
1515import { createVersionConfig } from './test/test-utils' ;
16+ import { createNxReleaseConfig , NxReleaseConfig } from '../config/config' ;
17+ import { createProjectFileMapUsingProjectGraph } from '../../../project-graph/file-map-utils' ;
1618
1719describe ( 'shared' , ( ) => {
1820 describe ( 'createCommitMessageValues()' , ( ) => {
@@ -483,8 +485,9 @@ describe('shared', () => {
483485
484486 describe ( `getCommitsRelevantToProjects()` , ( ) => {
485487 let mockProjectGraph : ProjectGraph ;
488+ let mockReleaseConfig : NxReleaseConfig | null ;
486489
487- beforeEach ( ( ) => {
490+ beforeEach ( async ( ) => {
488491 ( readNxJson as jest . Mock ) . mockReturnValue ( { } ) ;
489492
490493 mockProjectGraph = {
@@ -532,6 +535,19 @@ describe('shared', () => {
532535 } ,
533536 externalNodes : { } ,
534537 } ;
538+
539+ ( { nxReleaseConfig : mockReleaseConfig } = await createNxReleaseConfig (
540+ mockProjectGraph ,
541+ await createProjectFileMapUsingProjectGraph ( mockProjectGraph ) ,
542+ {
543+ projects : Object . keys ( mockProjectGraph . nodes ) ,
544+ changelog : {
545+ git : {
546+ commitMessage : 'chore(release): publish packages' ,
547+ } ,
548+ } ,
549+ }
550+ ) ) ;
535551 } ) ;
536552
537553 it ( 'should include commits that directly touch target projects' , async ( ) => {
@@ -544,7 +560,8 @@ describe('shared', () => {
544560 const result = await getCommitsRelevantToProjects (
545561 mockProjectGraph ,
546562 commits ,
547- [ 'lib-a' , 'lib-b' ]
563+ [ 'lib-a' , 'lib-b' ] ,
564+ mockReleaseConfig !
548565 ) ;
549566
550567 expect ( result . size ) . toBe ( 2 ) ;
@@ -564,7 +581,8 @@ describe('shared', () => {
564581 const result = await getCommitsRelevantToProjects (
565582 mockProjectGraph ,
566583 commits ,
567- [ 'lib-a' ]
584+ [ 'lib-a' ] ,
585+ mockReleaseConfig !
568586 ) ;
569587
570588 // Both commits should be included - nx.json affects all, and lib-a is directly touched
@@ -584,7 +602,8 @@ describe('shared', () => {
584602 const result = await getCommitsRelevantToProjects (
585603 mockProjectGraph ,
586604 commits ,
587- [ 'lib-a' ]
605+ [ 'lib-a' ] ,
606+ mockReleaseConfig !
588607 ) ;
589608
590609 expect ( result . size ) . toBe ( 1 ) ;
@@ -610,7 +629,8 @@ describe('shared', () => {
610629 const result = await getCommitsRelevantToProjects (
611630 mockProjectGraph ,
612631 commits ,
613- [ 'lib-a' ]
632+ [ 'lib-a' ] ,
633+ mockReleaseConfig !
614634 ) ;
615635
616636 // lib-a depends on lib-c, so commit touching lib-c should affect lib-a
@@ -631,7 +651,8 @@ describe('shared', () => {
631651 const result = await getCommitsRelevantToProjects (
632652 mockProjectGraph ,
633653 commits ,
634- [ 'lib-a' ]
654+ [ 'lib-a' ] ,
655+ mockReleaseConfig !
635656 ) ;
636657
637658 expect ( result . size ) . toBe ( 1 ) ;
@@ -650,7 +671,8 @@ describe('shared', () => {
650671 const result = await getCommitsRelevantToProjects (
651672 mockProjectGraph ,
652673 commits ,
653- [ 'lib-a' , 'lib-b' ]
674+ [ 'lib-a' , 'lib-b' ] ,
675+ mockReleaseConfig !
654676 ) ;
655677
656678 // Same commit should appear for both projects
@@ -667,7 +689,8 @@ describe('shared', () => {
667689 const result = await getCommitsRelevantToProjects (
668690 mockProjectGraph ,
669691 commits ,
670- [ 'lib-a' , 'lib-b' ]
692+ [ 'lib-a' , 'lib-b' ] ,
693+ mockReleaseConfig !
671694 ) ;
672695
673696 // Global file should appear for all requested projects
@@ -686,7 +709,8 @@ describe('shared', () => {
686709 const result = await getCommitsRelevantToProjects (
687710 mockProjectGraph ,
688711 commits ,
689- [ 'lib-a' , 'lib-b' ]
712+ [ 'lib-a' , 'lib-b' ] ,
713+ mockReleaseConfig !
690714 ) ;
691715
692716 expect ( result . has ( 'lib-a' ) ) . toBe ( false ) ;
@@ -698,7 +722,8 @@ describe('shared', () => {
698722 const result = await getCommitsRelevantToProjects (
699723 mockProjectGraph ,
700724 [ ] ,
701- [ 'lib-a' ]
725+ [ 'lib-a' ] ,
726+ mockReleaseConfig !
702727 ) ;
703728
704729 expect ( result . size ) . toBe ( 0 ) ;
@@ -712,7 +737,8 @@ describe('shared', () => {
712737 const result = await getCommitsRelevantToProjects (
713738 mockProjectGraph ,
714739 commits ,
715- [ ]
740+ [ ] ,
741+ mockReleaseConfig !
716742 ) ;
717743
718744 expect ( result . size ) . toBe ( 0 ) ;
@@ -727,7 +753,8 @@ describe('shared', () => {
727753 const result = await getCommitsRelevantToProjects (
728754 mockProjectGraph ,
729755 commits ,
730- [ 'lib-a' ]
756+ [ 'lib-a' ] ,
757+ mockReleaseConfig !
731758 ) ;
732759
733760 // Lock file changes typically affect all or many projects
@@ -743,19 +770,45 @@ describe('shared', () => {
743770 const result = await getCommitsRelevantToProjects (
744771 mockProjectGraph ,
745772 commits ,
746- [ 'lib-a' ]
773+ [ 'lib-a' ] ,
774+ mockReleaseConfig !
747775 ) ;
748776
749777 // package.json changes typically affect projects
750778 expect ( result . size ) . toBeGreaterThanOrEqual ( 0 ) ;
751779 } ) ;
752780
781+ it ( 'should exclude automated version or changelog commits' , async ( ) => {
782+ const commits : GitCommit [ ] = [
783+ createMockCommit (
784+ 'abc123' ,
785+ [ 'libs/deleted-lib-1/package.json' ] ,
786+ 'chore(release): publish 1.0.0' // with version interpolated
787+ ) ,
788+ createMockCommit (
789+ 'def456' ,
790+ [ 'libs/deleted-lib-2/package.json' ] ,
791+ 'chore(release): publish packages'
792+ ) ,
793+ ] ;
794+
795+ const result = await getCommitsRelevantToProjects (
796+ mockProjectGraph ,
797+ commits ,
798+ [ 'lib-a' ] ,
799+ mockReleaseConfig !
800+ ) ;
801+
802+ expect ( result . size ) . toBe ( 0 ) ;
803+ } ) ;
804+
753805 function createMockCommit (
754806 shortHash : string ,
755- affectedFiles : string [ ]
807+ affectedFiles : string [ ] ,
808+ message ?: string
756809 ) : GitCommit {
757810 return {
758- message : `feat: commit ${ shortHash } ` ,
811+ message : message || `feat: commit ${ shortHash } ` ,
759812 body : '' ,
760813 shortHash,
761814 author :
{ name :
'Test Author' , email :
'[email protected] ' } ,
0 commit comments