From 1939ada077abb76b6b28e88fdaf29bd24b2a4ca2 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Tue, 28 Nov 2023 15:27:31 +0100 Subject: [PATCH] fix: increase project unit test coverage --- src/project.test.ts | 76 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/src/project.test.ts b/src/project.test.ts index 37a922f..9021c05 100644 --- a/src/project.test.ts +++ b/src/project.test.ts @@ -9,7 +9,11 @@ import { buildMockProject, createNoopWriteStream, } from '../tests/unit/helpers'; -import { readProject, restoreUnreleasedPackagesChangelog } from './project'; +import { + readProject, + restoreUnreleasedPackagesChangelog, + updateChangedPackagesChangelog, +} from './project'; import * as packageModule from './package'; import * as repoModule from './repo'; import { IncrementableVersionParts } from './release-specification'; @@ -199,4 +203,74 @@ describe('project', () => { ); }); }); + + describe('updateChangedPackagesChangelog', () => { + it('should update changelog files of all the packages that has changes since latest release', async () => { + const stderr = createNoopWriteStream(); + const packageA = buildMockPackage('a', { + hasChangesSinceLatestRelease: true, + }); + const packageB = buildMockPackage('b', { + hasChangesSinceLatestRelease: true, + }); + const project = buildMockProject({ + rootPackage: buildMockPackage('monorepo'), + workspacePackages: { + a: packageA, + b: packageB, + }, + }); + + const updatePackageChangelogSpy = jest.spyOn( + packageModule, + 'updatePackageChangelog', + ); + + await updateChangedPackagesChangelog({ + project, + stderr, + }); + + expect(updatePackageChangelogSpy).toHaveBeenCalledWith({ + project, + package: packageA, + stderr, + }); + + expect(updatePackageChangelogSpy).toHaveBeenCalledWith({ + project, + package: packageB, + stderr, + }); + }); + + it('should not update changelog files of all the packages that has not changed since latest release', async () => { + const stderr = createNoopWriteStream(); + const packageA = buildMockPackage('a', { + hasChangesSinceLatestRelease: false, + }); + const project = buildMockProject({ + rootPackage: buildMockPackage('monorepo'), + workspacePackages: { + a: packageA, + }, + }); + + const updatePackageChangelogSpy = jest.spyOn( + packageModule, + 'updatePackageChangelog', + ); + + await updateChangedPackagesChangelog({ + project, + stderr, + }); + + expect(updatePackageChangelogSpy).not.toHaveBeenCalledWith({ + project, + package: packageA, + stderr, + }); + }); + }); });