-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract version parsing from release script
Summary: Changelog: [Internal] - extract logic for parsing version in bump-oss-version and add tests Reviewed By: cortinico Differential Revision: D32196238 fbshipit-source-id: 6ea7af3d282eea1d876118f056bca94a151e6182
- Loading branch information
1 parent
636f614
commit cc1e3ab
Showing
3 changed files
with
77 additions
and
8 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
const {parseVersion} = require('../version-utils'); | ||
|
||
describe('version-utils', () => { | ||
describe('parseVersion', () => { | ||
it('should throw error if invalid match', () => { | ||
function testInvalidVersion() { | ||
parseVersion('<invalid version>'); | ||
} | ||
expect(testInvalidVersion).toThrowErrorMatchingInlineSnapshot( | ||
`"You must pass a correctly formatted version; couldn't parse <invalid version>"`, | ||
); | ||
}); | ||
|
||
it('should parse pre-release version with .', () => { | ||
const {major, minor, patch, prerelease} = parseVersion('0.66.0-rc.4'); | ||
expect(major).toBe('0'); | ||
expect(minor).toBe('66'); | ||
expect(patch).toBe('0'); | ||
expect(prerelease).toBe('rc.4'); | ||
}); | ||
|
||
it('should parse stable version', () => { | ||
const {major, minor, patch, prerelease} = parseVersion('0.66.0'); | ||
expect(major).toBe('0'); | ||
expect(minor).toBe('66'); | ||
expect(patch).toBe('0'); | ||
expect(prerelease).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
function parseVersion(version) { | ||
const match = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/); | ||
if (!match) { | ||
throw new Error( | ||
`You must pass a correctly formatted version; couldn't parse ${version}`, | ||
); | ||
} | ||
const [, major, minor, patch, prerelease] = match; | ||
return { | ||
major, | ||
minor, | ||
patch, | ||
prerelease, | ||
}; | ||
} | ||
|
||
module.exports = { | ||
parseVersion, | ||
}; |