Skip to content

Commit

Permalink
Ensure there is no bump for a pre-release when recommended version is…
Browse files Browse the repository at this point in the history
… null
  • Loading branch information
ygrishajev committed Oct 1, 2024
1 parent c46f3c9 commit 19a5306
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class ConventionalChangelog extends Plugin {
}
if (increment && semver.valid(increment)) {
return increment;
} else if (isPreRelease) {
if (releaseType && (options.strictSemVer || !semver.prerelease(latestVersion))) {
} else if (releaseType && isPreRelease) {
if ((options.strictSemVer || !semver.prerelease(latestVersion))) {
return semver.inc(latestVersion, `pre${releaseType}`, preReleaseId);
}

Expand Down
28 changes: 27 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ test('should follow conventional commit strategy with prereleaase', async t => {
assert.equal(version4, '2.0.0-alpha.1');
});

test.only('should follow conventional commit strategy with prereleaase and custom prefix', async t => {
test('should follow conventional commit strategy with prereleaase and custom prefix', async t => {
setup();
const prefix = 'scope/';
sh.exec(`git tag ${prefix}v1.2.1`);
Expand Down Expand Up @@ -398,6 +398,32 @@ test('should not bump when recommended bump returns null', async () => {
}
});

test('should not bump a pre-release when recommended bump returns null', async () => {
setup();
sh.exec(`git tag 1.0.0`);
add('fix', 'bar');
add('feat', 'baz');
{
const options = getOptions({ preset: 'angular' });
const { version } = await runTasks(...options);
assert.equal(version, '1.1.0');
}
add('blorp', 'faz');
add('faz', 'blorp');
{
const options = getOptions({ preset: 'angular' });
const { version } = await runTasks(...options);
assert.equal(version, '1.1.0'); // Incorrect result from conventional-recommended-bump
}
{
const whatBump = commits => ({ level: null, reason: 'Parsed commits do not warrant a version bump.' });
const [config, container] = getOptions({ whatBump });
config.preRelease = 'alpha';
const { version } = await runTasks(config, container);
assert.equal(version, undefined);
}
});

// TODO Prepare test and verify results influenced by parserOpts and writerOpts
test.skip('should pass parserOpts and writerOpts', async t => {
setup();
Expand Down

0 comments on commit 19a5306

Please sign in to comment.