Skip to content

Commit

Permalink
[enzyme-adapter-react-helper] [patch] Consolidate version-tweaking lo…
Browse files Browse the repository at this point in the history
…gic into a single function
  • Loading branch information
ahuth authored and ljharb committed Jul 30, 2019
1 parent f8897d1 commit 67ad7dc
Showing 1 changed file with 9 additions and 5 deletions.
@@ -1,13 +1,17 @@
import semver from 'semver';

function removePreRelease(version) {
return semver.inc(version, 'patch');
function getValidRange(version) {
return semver.prerelease(version)
// Remove pre-release versions by incrementing them. This works because a pre-release is less
// than the corresponding non-pre-prelease version.
? semver.inc(version, 'patch')
// Convert partial versions, such as 16 or 16.8, to their corresponding range notation, so that
// they work with the rest of the semver functions.
: semver.validRange(version);
}

export default function getAdapterForReactVersion(reactVersion) {
const versionRange = semver.prerelease(reactVersion)
? removePreRelease(reactVersion)
: semver.validRange(reactVersion);
const versionRange = getValidRange(reactVersion);

if (semver.intersects(versionRange, '^16.4.0')) {
return 'enzyme-adapter-react-16';
Expand Down

0 comments on commit 67ad7dc

Please sign in to comment.