diff --git a/classes/semver.js b/classes/semver.js index e1208fe6..84e84590 100644 --- a/classes/semver.js +++ b/classes/semver.js @@ -291,8 +291,10 @@ class SemVer { default: throw new Error(`invalid increment argument: ${release}`) } - this.format() - this.raw = this.version + this.raw = this.format() + if (this.build.length) { + this.raw += `+${this.build.join('.')}` + } return this } } diff --git a/test/classes/semver.js b/test/classes/semver.js index 6be0ac8f..1e4d48f8 100644 --- a/test/classes/semver.js +++ b/test/classes/semver.js @@ -90,11 +90,18 @@ test('incrementing', t => { id, base, ]) => t.test(`${version} ${inc} ${id || ''}`.trim(), t => { - t.plan(1) if (expect === null) { + t.plan(1) t.throws(() => new SemVer(version, options).inc(inc, id, base)) } else { - t.equal(new SemVer(version, options).inc(inc, id, base).version, expect) + t.plan(2) + const incremented = new SemVer(version, options).inc(inc, id, base) + t.equal(incremented.version, expect) + if (incremented.build.length) { + t.equal(incremented.raw, `${expect}+${incremented.build.join('.')}`) + } else { + t.equal(incremented.raw, expect) + } } })) }) diff --git a/test/fixtures/increments.js b/test/fixtures/increments.js index 1fbc4bc9..65e9530b 100644 --- a/test/fixtures/increments.js +++ b/test/fixtures/increments.js @@ -123,4 +123,5 @@ module.exports = [ ['1.2.0-dev', 'preminor', '1.3.0-beta', false, 'beta', false], ['1.2.0-dev', 'prepatch', '1.2.1-dev', false, 'dev', false], ['1.2.0', 'prerelease', null, false, '', false], + ['1.0.0-rc.1+build.4', 'prerelease', '1.0.0-rc.2', 'rc', false], ] diff --git a/test/functions/inc.js b/test/functions/inc.js index e2d0768c..2f6f9bb4 100644 --- a/test/functions/inc.js +++ b/test/functions/inc.js @@ -14,7 +14,15 @@ test('increment versions test', (t) => { if (wanted) { parsed.inc(what, id, base) t.equal(parsed.version, wanted, `${cmd} object version updated`) - t.equal(parsed.raw, wanted, `${cmd} object raw field updated`) + if (parsed.build.length) { + t.equal( + parsed.raw, + `${wanted}+${parsed.build.join('.')}`, + `${cmd} object raw field updated with build` + ) + } else { + t.equal(parsed.raw, wanted, `${cmd} object raw field updated`) + } const preIncObject = JSON.stringify(parsedAsInput) inc(parsedAsInput, what, options, id, base)