Skip to content

Commit

Permalink
fix(semver): bump conventional-recommended-bump
Browse files Browse the repository at this point in the history
  • Loading branch information
edbzn committed Oct 22, 2023
1 parent c4ec0cf commit a05c61b
Show file tree
Hide file tree
Showing 22 changed files with 87 additions and 241 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 4 additions & 3 deletions packages/semver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
"dependencies": {
"chalk": "4.1.2",
"conventional-changelog": "^5.1.0",
"conventional-changelog-angular": "^7.0.0",
"conventional-changelog-conventionalcommits": "^7.0.2",
"conventional-recommended-bump": "^7.0.0",
"conventional-commits-parser": "^5.0.0",
"conventional-recommended-bump": "^9.0.0",
"detect-indent": "6.1.0",
"git-semver-tags": "^7.0.1",
"inquirer": "8.2.6",
"rxjs": "7.8.1"
},
"devDependencies": {
"@types/conventional-changelog": "^3.1.4 ",
"@types/conventional-recommended-bump": "6.1.1",
"@types/conventional-recommended-bump": "^9.0.2",
"@types/inquirer": "8.2.9",
"@types/semver": "7.5.4",
"@types/standard-version": "7.1.2",
"@types/tmp": "0.2.5"
}
}
140 changes: 54 additions & 86 deletions packages/semver/src/executors/version/utils/try-bump.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { logger } from '@nx/devkit';
import * as conventionalRecommendedBump from 'conventional-recommended-bump';
import * as gitSemverTags from 'git-semver-tags';
import { lastValueFrom, of, throwError } from 'rxjs';
import { callbackify } from 'util';
import { getLastVersion } from './get-last-version';
import { getCommits, getFirstCommitRef } from './git';
import { tryBump } from './try-bump';
Expand All @@ -24,15 +23,11 @@ describe('tryBump', () => {
const mockGetFirstCommitRef = getFirstCommitRef as jest.MockedFunction<
typeof getFirstCommitRef
>;
let mockGitSemverTags: jest.Mock;
const mockGitSemverTags: jest.Mock = gitSemverTags;

let loggerSpy: jest.SpyInstance;

beforeEach(() => {
mockGitSemverTags = jest.fn();
(gitSemverTags as jest.Mock).mockImplementation(
callbackify(mockGitSemverTags),
);
mockGetLastVersion.mockReturnValue(of('2.1.0'));
loggerSpy = jest.spyOn(logger, 'warn');
});
Expand All @@ -45,11 +40,9 @@ describe('tryBump', () => {
mockGetCommits.mockReturnValue(of(['feat: A', 'feat: B']));
/* Mock bump to return "minor". */
mockConventionalRecommendedBump.mockImplementation(
callbackify(
jest.fn().mockResolvedValue({
releaseType: 'minor',
}),
) as () => void,
jest.fn().mockResolvedValue({
releaseType: 'minor',
}),
);

const newVersion = await lastValueFrom(
Expand All @@ -75,14 +68,11 @@ describe('tryBump', () => {
});

expect(mockConventionalRecommendedBump).toBeCalledTimes(1);
expect(mockConventionalRecommendedBump).toBeCalledWith(
{
path: '/libs/demo',
preset: 'angular',
tagPrefix: 'v',
},
expect.any(Function),
);
expect(mockConventionalRecommendedBump).toBeCalledWith({
path: '/libs/demo',
preset: 'angular',
tagPrefix: 'v',
});
});

it('should compute the next version based on last version, changes, and dependencies', async () => {
Expand All @@ -93,19 +83,17 @@ describe('tryBump', () => {

/* Mock bump to return "minor". */
mockConventionalRecommendedBump.mockImplementation(
callbackify(
jest
.fn()
.mockResolvedValueOnce({
releaseType: undefined,
})
.mockResolvedValueOnce({
releaseType: undefined,
})
.mockResolvedValueOnce({
releaseType: 'minor',
}),
) as () => void,
jest
.fn()
.mockResolvedValueOnce({
releaseType: undefined,
})
.mockResolvedValueOnce({
releaseType: undefined,
})
.mockResolvedValueOnce({
releaseType: 'minor',
}),
);

const newVersion = await lastValueFrom(
Expand Down Expand Up @@ -142,14 +130,11 @@ describe('tryBump', () => {
});

expect(mockConventionalRecommendedBump).toBeCalledTimes(1);
expect(mockConventionalRecommendedBump).toBeCalledWith(
{
path: '/libs/demo',
preset: 'angular',
tagPrefix: 'v',
},
expect.any(Function),
);
expect(mockConventionalRecommendedBump).toBeCalledWith({
path: '/libs/demo',
preset: 'angular',
tagPrefix: 'v',
});
});

it('should use given type to calculate next version', async () => {
Expand Down Expand Up @@ -265,7 +250,6 @@ describe('tryBump', () => {
tagPrefix: 'v',
releaseType: 'minor',
projectName: '',

skipCommitTypes: [],
}),
);
Expand Down Expand Up @@ -309,11 +293,9 @@ describe('tryBump', () => {
mockGetCommits.mockReturnValue(of([]));
mockGetFirstCommitRef.mockReturnValue(of('sha1'));
mockConventionalRecommendedBump.mockImplementation(
callbackify(
jest.fn().mockResolvedValue({
releaseType: undefined,
}),
) as () => void,
jest.fn().mockResolvedValue({
releaseType: undefined,
}),
);

await lastValueFrom(
Expand Down Expand Up @@ -341,11 +323,9 @@ describe('tryBump', () => {
it('should return undefined if there are no changes in current path', async () => {
mockGetCommits.mockReturnValue(of([]));
mockConventionalRecommendedBump.mockImplementation(
callbackify(
jest.fn().mockResolvedValue({
releaseType: 'patch',
}),
) as () => void,
jest.fn().mockResolvedValue({
releaseType: 'patch',
}),
);

const newVersion = await lastValueFrom(
Expand All @@ -370,11 +350,9 @@ describe('tryBump', () => {
it('should try to do a bump even if there are no changes in current path when allowEmptyRelease is true', async () => {
mockGetCommits.mockReturnValue(of([]));
mockConventionalRecommendedBump.mockImplementation(
callbackify(
jest.fn().mockResolvedValue({
releaseType: 'patch',
}),
) as () => void,
jest.fn().mockResolvedValue({
releaseType: 'patch',
}),
);

const newVersion = await lastValueFrom(
Expand All @@ -401,11 +379,9 @@ describe('tryBump', () => {
it('should return undefined if all commits types match skipCommitTypes', async () => {
mockGetCommits.mockReturnValue(of(['docs: A ', 'refactor: B ']));
mockConventionalRecommendedBump.mockImplementation(
callbackify(
jest.fn().mockResolvedValue({
releaseType: 'patch',
}),
) as () => void,
jest.fn().mockResolvedValue({
releaseType: 'patch',
}),
);

const newVersion = await lastValueFrom(
Expand All @@ -425,11 +401,9 @@ describe('tryBump', () => {
it('should return correct version if NOT commits types match skipCommitTypes', async () => {
mockGetCommits.mockReturnValue(of(['feat: A', 'docs: B']));
mockConventionalRecommendedBump.mockImplementation(
callbackify(
jest.fn().mockResolvedValue({
releaseType: 'patch',
}),
) as () => void,
jest.fn().mockResolvedValue({
releaseType: 'patch',
}),
);

const newVersion = await lastValueFrom(
Expand All @@ -453,16 +427,14 @@ describe('tryBump', () => {
.mockReturnValueOnce(of(['docs: A', 'refactor(scope): B']));

mockConventionalRecommendedBump.mockImplementation(
callbackify(
jest
.fn()
.mockResolvedValueOnce({
releaseType: undefined,
})
.mockResolvedValueOnce({
releaseType: undefined,
}),
) as () => void,
jest
.fn()
.mockResolvedValueOnce({
releaseType: undefined,
})
.mockResolvedValueOnce({
releaseType: undefined,
}),
);

const newVersion = await lastValueFrom(
Expand All @@ -489,11 +461,9 @@ describe('tryBump', () => {
);
/* Mock bump to return "minor". */
mockConventionalRecommendedBump.mockImplementation(
callbackify(
jest.fn().mockResolvedValue({
releaseType: 'minor',
}),
) as () => void,
jest.fn().mockResolvedValue({
releaseType: 'minor',
}),
);

const newVersion = await lastValueFrom(
Expand Down Expand Up @@ -529,11 +499,9 @@ describe('tryBump', () => {
);
/* Mock bump to return "minor". */
mockConventionalRecommendedBump.mockImplementation(
callbackify(
jest.fn().mockResolvedValue({
releaseType: 'minor',
}),
) as () => void,
jest.fn().mockResolvedValue({
releaseType: 'minor',
}),
);

const newVersion = await lastValueFrom(
Expand Down
7 changes: 4 additions & 3 deletions packages/semver/src/executors/version/utils/try-bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,16 @@ export function _semverBump({
tagPrefix: string;
}) {
return defer(async () => {
const recommended = (await promisify(conventionalRecommendedBump)({
const recommended = await conventionalRecommendedBump({
path: projectRoot,
tagPrefix,
...(typeof preset === 'string' ? { preset: preset } : {}),
...(typeof preset === 'object' ? { config: preset } : {}),
})) as { releaseType: semver.ReleaseType };
});
const { releaseType } = recommended;

return semver.inc(since, releaseType);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return semver.inc(since, releaseType!);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe(writeChangelog, () => {

it('should print a console.info with the changelog contents without the header', async () => {
expect(console.info).toHaveBeenCalledWith(
expect.stringContaining(`## ${version}`),
expect.stringContaining(version),
);
expect(console.info).toHaveBeenCalledWith(
expect.not.stringContaining(config.changelogHeader),
Expand Down
Loading

0 comments on commit a05c61b

Please sign in to comment.