Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that all packages bumped get a new entry in the changelog.json… #797

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/__tests__/bump/setDependentVersions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { describe, expect, it } from '@jest/globals';
import { setDependentVersions } from '../../bump/setDependentVersions';
import { BeachballOptions } from '../../types/BeachballOptions';
import { PackageInfos } from '../../types/PackageInfo';

describe("dependent packages are part of the bump", () => {
it("adds dependents for new changelog entries", () => {
const packageInfos: PackageInfos = {
foo: {
combinedOptions: {} as any,
name: 'foo',
packageJsonPath: 'packages/foo/package.json',
packageOptions: {},
private: false,
version: '1.0.0',
dependencies: {
bar: '*',
},
},
bar: {
combinedOptions: {} as any,
name: 'bar',
packageJsonPath: 'packages/bar/package.json',
packageOptions: {},
private: false,
version: '1.0.0',
},
};

const scopedPackages = new Set(['foo', 'bar']);

const dependentChangedBy = setDependentVersions(
packageInfos,
scopedPackages,
{ verbose: false } as BeachballOptions
);

expect(dependentChangedBy['foo']).toBeTruthy();
expect(dependentChangedBy['foo'].size).toBe(1);

})
})
52 changes: 52 additions & 0 deletions src/__tests__/changelog/getPackageChangelogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,58 @@ describe('getPackageChangelogs', () => {
expect(Object.keys(changelogs.foo.comments.patch!)).toHaveLength(1);
});

it('should have new entries when a package was part of a dependent bump', () => {
const changeFileChangeInfos: ChangeSet = [
{
changeFile: 'bar.json',
change: {
comment: 'comment for bar',
commit: 'deadbeef',
dependentChangeType: 'patch',
email: 'something@something.com',
packageName: 'bar',
type: 'minor',
},
},
];

const dependentChangedBy: BumpInfo['dependentChangedBy'] = {
foo: new Set(['bar']),
};

const packageInfos: PackageInfos = {
foo: {
combinedOptions: {} as any,
name: 'foo',
packageJsonPath: 'packages/foo/package.json',
packageOptions: {},
private: false,
version: '1.0.0',
dependencies: {
bar: '*',
},
},
bar: {
combinedOptions: {} as any,
name: 'bar',
packageJsonPath: 'packages/bar/package.json',
packageOptions: {},
private: false,
version: '1.0.0',
},
};

const changelogs = getPackageChangelogs(
changeFileChangeInfos,
{ bar: 'minor', foo: 'patch' },
dependentChangedBy,
packageInfos,
'.'
);

expect(Object.keys(changelogs.foo)).toBeTruthy();
});

it('should not generate change logs for dependent bumps of private packages', () => {
const changeFileChangeInfos: ChangeSet = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/bump/setDependentVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function setDependentVersions(
if (packageInfo) {
const existingVersionRange = deps[dep];
const bumpedVersionRange = bumpMinSemverRange(packageInfo.version, existingVersionRange);
if (existingVersionRange !== bumpedVersionRange) {
if (bumpedVersionRange === "*" || existingVersionRange !== bumpedVersionRange) {
deps[dep] = bumpedVersionRange;

dependentChangedBy[pkgName] = dependentChangedBy[pkgName] || new Set<string>();
Expand Down