-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: clean up all cases for releaseType (#631)
- Loading branch information
Eunjae Lee
authored
Jan 22, 2020
1 parent
81e30b1
commit 89e5d73
Showing
2 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
26 changes: 24 additions & 2 deletions
26
packages/shipjs-lib/src/lib/util/__tests__/getReleaseType.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |