diff --git a/change/beachball-fdbfaaed-1a31-4644-a756-9b44db0b66d1.json b/change/beachball-fdbfaaed-1a31-4644-a756-9b44db0b66d1.json new file mode 100644 index 00000000..32d3ecd1 --- /dev/null +++ b/change/beachball-fdbfaaed-1a31-4644-a756-9b44db0b66d1.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "check for renamed change files", + "packageName": "beachball", + "email": "lkiniu@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/src/__tests__/validation/areChangeFilesDeleted.test.ts b/src/__tests__/validation/areChangeFilesDeleted.test.ts new file mode 100644 index 00000000..ef7b600e --- /dev/null +++ b/src/__tests__/validation/areChangeFilesDeleted.test.ts @@ -0,0 +1,35 @@ +import { areChangeFilesDeleted } from '../../validation/areChangeFilesDeleted'; +import { BeachballOptions } from '../../types/BeachballOptions'; +import { findProjectRoot, getChangePath } from '../../paths'; +import { getChangesBetweenRefs } from 'workspace-tools'; + +jest.mock('workspace-tools',() => ({ + getChangesBetweenRefs: jest.fn().mockReturnValue(['file1.json', 'file2.json']) +})); + +jest.mock('../../paths', () => ({ + findProjectRoot: jest.fn().mockReturnValue('/'), + getChangePath: jest.fn().mockReturnValue('/change') +})); + +const options = { + branch: 'test', + cwd: '/' +} as unknown as BeachballOptions; + +test('return true when change files have been deleted or renamed', () => { + const changeFilesDeleted = areChangeFilesDeleted(options); + expect(getChangesBetweenRefs).toBeCalled(); + expect(findProjectRoot).toBeCalled(); + expect(getChangePath).toBeCalled(); + expect(changeFilesDeleted).toBe(true); +}); + +test('return false when change files have not been deleted or renamed', () => { + (getChangesBetweenRefs as jest.Mock).mockReturnValue([]); + const changeFilesDeleted = areChangeFilesDeleted(options); + expect(getChangesBetweenRefs).toBeCalled(); + expect(findProjectRoot).toBeCalled(); + expect(getChangePath).toBeCalled(); + expect(changeFilesDeleted).toBe(false); +}); \ No newline at end of file diff --git a/src/validation/areChangeFilesDeleted.ts b/src/validation/areChangeFilesDeleted.ts index d0554cb4..a9b05ce2 100644 --- a/src/validation/areChangeFilesDeleted.ts +++ b/src/validation/areChangeFilesDeleted.ts @@ -17,12 +17,12 @@ export function areChangeFilesDeleted(options: BeachballOptions): boolean { process.exit(1); } - console.log(`Checking for deleted change files against "${branch}"`); + console.log(`Checking for deleted and renamed change files against "${branch}"`); const changeFilesDeletedSinceRef = getChangesBetweenRefs( branch, 'HEAD', [ - '--diff-filter=D', // showing only deleted files from the diff. + '--diff-filter=DR', // showing only deleted and renamed change files from the diff. ], `${changePath}/*.json`, root @@ -37,7 +37,7 @@ export function areChangeFilesDeleted(options: BeachballOptions): boolean { if (changeFilesDeleted) { const changeFiles = changeFilesDeletedSinceRef.map(file => `- ${file}`); - const errorMessage = 'The following change files were deleted:'; + const errorMessage = 'The following change files were deleted or renamed:'; console.error(`${errorMessage}\n${changeFiles.join('\n')}\n`); }