From ecb55a2dde7e66d67fac5fca81a84a0115973bbf Mon Sep 17 00:00:00 2001 From: Larry Kiniu Date: Thu, 12 Aug 2021 17:16:08 +0300 Subject: [PATCH 1/4] check for renamed change files --- src/validation/areChangeFilesDeleted.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/validation/areChangeFilesDeleted.ts b/src/validation/areChangeFilesDeleted.ts index d0554cb46..9c7395336 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 From ec64d45fedc431b797f168ecf66f03b1aee89d95 Mon Sep 17 00:00:00 2001 From: Larry Kiniu Date: Thu, 12 Aug 2021 17:25:26 +0300 Subject: [PATCH 2/4] update error message in case a change file was renamed --- src/validation/areChangeFilesDeleted.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validation/areChangeFilesDeleted.ts b/src/validation/areChangeFilesDeleted.ts index 9c7395336..a9b05ce21 100644 --- a/src/validation/areChangeFilesDeleted.ts +++ b/src/validation/areChangeFilesDeleted.ts @@ -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`); } From 47119e19c8cf66f29d11e01c739a8c24df1b8199 Mon Sep 17 00:00:00 2001 From: Larry Kiniu Date: Thu, 12 Aug 2021 17:45:02 +0300 Subject: [PATCH 3/4] Change files --- change/beachball-fdbfaaed-1a31-4644-a756-9b44db0b66d1.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/beachball-fdbfaaed-1a31-4644-a756-9b44db0b66d1.json 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 000000000..32d3ecd1e --- /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" +} From 2f57e7c661209aed2bee5e485c0c08eea3446227 Mon Sep 17 00:00:00 2001 From: Larry Kiniu Date: Fri, 20 Aug 2021 17:49:42 +0300 Subject: [PATCH 4/4] add test for validating when change files have been deleted or renamed --- .../validation/areChangeFilesDeleted.test.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/__tests__/validation/areChangeFilesDeleted.test.ts diff --git a/src/__tests__/validation/areChangeFilesDeleted.test.ts b/src/__tests__/validation/areChangeFilesDeleted.test.ts new file mode 100644 index 000000000..ef7b600e5 --- /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