Skip to content

Commit

Permalink
fix: increase project unit test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptodev-2s committed Nov 28, 2023
1 parent 2ce4fd3 commit 1939ada
Showing 1 changed file with 75 additions and 1 deletion.
76 changes: 75 additions & 1 deletion src/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
});
});
});
});

0 comments on commit 1939ada

Please sign in to comment.