Skip to content

Commit

Permalink
Fix support for (continuation) pre-releases
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jan 9, 2022
1 parent ec42877 commit b2b1275
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ConventionalChangelog extends Plugin {
if (increment && semver.valid(increment)) {
resolve(increment);
} else if (isPreRelease) {
const type = releaseType ? `pre${releaseType}` : 'prerelease';
const type = releaseType && !semver.prerelease(latestVersion) ? `pre${releaseType}` : 'prerelease';
resolve(semver.inc(latestVersion, type, preReleaseId));
} else if (releaseType) {
resolve(semver.inc(latestVersion, releaseType, preReleaseId));
Expand Down
18 changes: 9 additions & 9 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,35 @@ test('should ignore recommended bump (option)', async t => {
assert.strictEqual(version, '1.0.1');
});

test('should ignore recommended bump (prelease)', async t => {
test('should use provided pre-release id', async t => {
const options = { preRelease: 'alpha', [namespace]: { preset }, git };
const plugin = factory(Plugin, { namespace, options });
await runTasks(plugin);
const { version } = plugin.config.getContext();
assert.strictEqual(version, '1.0.1-alpha.0');
assert.strictEqual(version, '1.1.0-alpha.0');
});

test('should ignore recommended bump (prelease continuation)', async t => {
test('should use provided pre-release id (prelease continuation)', async t => {
const options = { preRelease: 'alpha', [namespace]: { preset }, git };
const plugin = factory(Plugin, { namespace, options });
const stub = sinon.stub(plugin, 'getLatestVersion').returns('1.0.1-alpha.0');
const stub = sinon.stub(plugin, 'getLatestVersion').returns('1.1.0-alpha.0');
await runTasks(plugin);
const { version } = plugin.config.getContext();
assert.strictEqual(version, '1.0.1-alpha.1');
assert.strictEqual(version, '1.1.0-alpha.1');
stub.restore();
});

test('should ignore recommended bump (next prelease)', async t => {
test('should use provided pre-release id (next pre-release)', async t => {
const options = { preRelease: 'beta', [namespace]: { preset }, git };
const plugin = factory(Plugin, { namespace, options });
const stub = sinon.stub(plugin, 'getLatestVersion').returns('1.0.1-alpha.1');
const stub = sinon.stub(plugin, 'getLatestVersion').returns('1.1.0-alpha.1');
await runTasks(plugin);
const { version } = plugin.config.getContext();
assert.strictEqual(version, '1.0.1-beta.0');
assert.strictEqual(version, '1.1.0-beta.0');
stub.restore();
});

test('should use recommended bump (from prelease)', async t => {
test('should use recommended bump (after pre-rerelease)', async t => {
const options = { [namespace]: { preset }, git };
const plugin = factory(Plugin, { namespace, options });
const stub = sinon.stub(plugin, 'getLatestVersion').returns('1.0.1-beta.0');
Expand Down

0 comments on commit b2b1275

Please sign in to comment.