Skip to content

Commit

Permalink
Use version fallback (without Git plugin)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Aug 13, 2021
1 parent 7a8db8d commit 8f91941
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ConventionalChangelog extends Plugin {
const { version } = this.getContext();
const { isIncrement } = this.config;
const { latestTag, secondLatestTag, tagTemplate } = this.config.getContext();
const currentTag = isIncrement ? tagTemplate.replace('${version}', version) : latestTag;
const currentTag = isIncrement ? (tagTemplate ? tagTemplate.replace('${version}', version) : version) : latestTag;
const previousTag = isIncrement ? latestTag : secondLatestTag;
const releaseCount = opts.releaseCount === 0 ? 0 : isIncrement ? 1 : 2;
const options = Object.assign({}, { releaseCount }, this.options);
Expand Down
28 changes: 14 additions & 14 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,29 @@ const infile = 'CHANGES.md';
const git = { tagName: '${version}' };

test('should not throw', async t => {
const options = { [namespace]: { preset }, git, tagTemplate: '${version}' };
const options = { [namespace]: { preset }, git: false };
const plugin = factory(Plugin, { namespace, options });
await assert.doesNotReject(runTasks(plugin));
});

test('should set changelog', async t => {
const options = { [namespace]: { preset }, git, tagTemplate: '${version}' };
const options = { [namespace]: { preset }, git };
const plugin = factory(Plugin, { namespace, options });
await runTasks(plugin);
const { changelog } = plugin.config.getContext();
assert.strictEqual(changelog, 'The changelog');
});

test('should use recommended bump', async t => {
const options = { [namespace]: { preset }, git, tagTemplate: '${version}' };
const options = { [namespace]: { preset }, git };
const plugin = factory(Plugin, { namespace, options });
await runTasks(plugin);
const { version } = plugin.config.getContext();
assert.strictEqual(version, '1.1.0');
});

test('should ignore recommended bump (option)', async t => {
const options = { [namespace]: { preset, ignoreRecommendedBump: true }, git, tagTemplate: '${version}' };
const options = { [namespace]: { preset, ignoreRecommendedBump: true }, git };
const plugin = factory(Plugin, { namespace, options });
const spy = sinon.spy(plugin, 'generateChangelog');
await runTasks(plugin);
Expand All @@ -66,15 +66,15 @@ test('should ignore recommended bump (option)', async t => {
});

test('should ignore recommended bump (prelease)', async t => {
const options = { preRelease: 'alpha', [namespace]: { preset }, git, tagTemplate: '${version}' };
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');
});

test('should ignore recommended bump (prelease continuation)', async t => {
const options = { preRelease: 'alpha', [namespace]: { preset }, git, tagTemplate: '${version}' };
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');
await runTasks(plugin);
Expand All @@ -84,7 +84,7 @@ test('should ignore recommended bump (prelease continuation)', async t => {
});

test('should ignore recommended bump (next prelease)', async t => {
const options = { preRelease: 'beta', [namespace]: { preset }, git, tagTemplate: '${version}' };
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');
await runTasks(plugin);
Expand All @@ -94,7 +94,7 @@ test('should ignore recommended bump (next prelease)', async t => {
});

test('should use recommended bump (from prelease)', async t => {
const options = { [namespace]: { preset }, git, tagTemplate: '${version}' };
const options = { [namespace]: { preset }, git };
const plugin = factory(Plugin, { namespace, options });
const stub = sinon.stub(plugin, 'getLatestVersion').returns('1.0.1-beta.0');
await runTasks(plugin);
Expand All @@ -104,23 +104,23 @@ test('should use recommended bump (from prelease)', async t => {
});

test('should use provided increment', async t => {
const options = { increment: 'major', [namespace]: { preset }, git, tagTemplate: '${version}' };
const options = { increment: 'major', [namespace]: { preset }, git };
const plugin = factory(Plugin, { namespace, options });
await runTasks(plugin);
const { version } = plugin.config.getContext();
assert.strictEqual(version, '2.0.0');
});

test('should use provided version', async t => {
const options = { increment: '1.2.3', [namespace]: { preset }, git, tagTemplate: '${version}' };
const options = { increment: '1.2.3', [namespace]: { preset }, git };
const plugin = factory(Plugin, { namespace, options });
await runTasks(plugin);
const { version } = plugin.config.getContext();
assert.strictEqual(version, '1.2.3');
});

test(`should write and update infile (${infile})`, async t => {
const options = { [namespace]: { preset, infile }, git, tagTemplate: '${version}' };
const options = { [namespace]: { preset, infile }, git };
const plugin = factory(Plugin, { namespace, options });
await runTasks(plugin);
const changelog = fs.readFileSync(infile);
Expand All @@ -134,20 +134,20 @@ test(`should write and update infile (${infile})`, async t => {
});

test('should reject if conventional bump passes error', async t => {
const options = { [namespace]: { preset: 'what?' }, git, tagTemplate: '${version}' };
const options = { [namespace]: { preset: 'what?' }, git };
const plugin = factory(Plugin, { namespace, options });
await assert.rejects(runTasks(plugin), /Something went wrong/);
});

test('should reject if conventional changelog has error', async t => {
const options = { [namespace]: { preset, releaseCount: -1 }, git, tagTemplate: '${version}' };
const options = { [namespace]: { preset, releaseCount: -1 }, git };
const plugin = factory(Plugin, { namespace, options });
await assert.rejects(runTasks(plugin), /Something went wrong/);
});

test('should not write infile in dry run', async t => {
const infile = 'DRYRUN.md';
const options = { 'dry-run': true, [namespace]: { preset, infile }, git, tagTemplate: '${version}' };
const options = { 'dry-run': true, [namespace]: { preset, infile }, git };
const plugin = factory(Plugin, { namespace, options });
const spy = sinon.spy(plugin, 'writeChangelog');
await runTasks(plugin);
Expand Down

0 comments on commit 8f91941

Please sign in to comment.