Skip to content

Commit

Permalink
fix: fix getNextVersion resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Nov 23, 2020
1 parent bcb40d5 commit 7275ae7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/updateDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const semver = require("semver");
const getNextVersion = (pkg) => {
const lastVersion = pkg._lastRelease && pkg._lastRelease.version;

return lastVersion && typeof pkg._nextType === "string" ? semver.inc(lastVersion, pkg._nextType) : "1.0.0";
return lastVersion && typeof pkg._nextType === "string"
? semver.inc(lastVersion, pkg._nextType)
: lastVersion || "1.0.0";
};

/**
Expand Down
21 changes: 20 additions & 1 deletion test/lib/updateDeps.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { resolveReleaseType, resolveNextVersion } = require("../../lib/updateDeps");
const { resolveReleaseType, resolveNextVersion, getNextVersion } = require("../../lib/updateDeps");

describe("resolveNextVersion()", () => {
// prettier-ignore
Expand Down Expand Up @@ -140,3 +140,22 @@ describe("resolveReleaseType()", () => {
});
});
});

describe("getNextVersion()", () => {
// prettier-ignore
const cases = [
[undefined, "patch", "1.0.0"],
["1.0.0", "patch", "1.0.1"],
["2.0.0", undefined, "2.0.0"],
]

cases.forEach(([lastVersion, releaseType, nextVersion]) => {
it(`${lastVersion} and ${releaseType} gives ${nextVersion}`, () => {
// prettier-ignore
expect(getNextVersion({
_nextType: releaseType,
_lastRelease: {version: lastVersion}
})).toBe(nextVersion);
});
});
});

0 comments on commit 7275ae7

Please sign in to comment.