Skip to content

Commit

Permalink
fix: clean up all cases for releaseType (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunjae Lee authored Jan 22, 2020
1 parent 81e30b1 commit 89e5d73
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
26 changes: 24 additions & 2 deletions packages/shipjs-lib/src/lib/util/__tests__/getReleaseType.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
import getReleaseType from '../getReleaseType';

describe('getReleaseType', () => {
it('gets release type from current version and next version', () => {
expect(getReleaseType('1.0.0', '0.10.99')).toBe('major');
it('works', () => {
const list = [
['1.2.3', '2.0.0', 'major'],
['1.2.3', '1.3.0', 'minor'],
['1.2.3', '1.2.4', 'patch'],
['1.2.3', '1.2.4-alpha.0', 'prerelease'],

['1.2.4-alpha.0', '1.2.4-alpha.1', 'prerelease'],
['1.2.4-alpha.0', '1.2.4', 'patch'],
['1.2.4-alpha.0', '1.2.5', 'patch'],
['1.2.4-alpha.0', '1.3.0', 'minor'],
['1.2.4-alpha.0', '2.0.0', 'major'],

['1.3.0-alpha.0', '1.3.0', 'minor'],
];

list.forEach(([currentVersion, nextVersion, expected]) => {
const actual = getReleaseType(currentVersion, nextVersion);
expect({ currentVersion, nextVersion, result: actual }).toEqual({
currentVersion,
nextVersion,
result: expected,
});
});
});
});
16 changes: 15 additions & 1 deletion packages/shipjs-lib/src/lib/util/getReleaseType.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import { diff } from 'semver';
import { diff, prerelease, minor, patch } from 'semver';

export default function getReleaseType(currentVersion, nextVersion) {
if (prerelease(currentVersion) === null && prerelease(nextVersion) !== null) {
return 'prerelease';
}
if (prerelease(currentVersion) !== null && prerelease(nextVersion) === null) {
if (patch(nextVersion) === 0) {
if (minor(nextVersion) === 0) {
return 'major';
} else {
return 'minor';
}
} else {
return 'patch';
}
}
return diff(currentVersion, nextVersion);
}

0 comments on commit 89e5d73

Please sign in to comment.