Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
test: Refactor Hashicorp and Hex versioning (#11684)
- Loading branch information
Showing
2 changed files
with
163 additions
and
343 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 |
---|---|---|
@@ -1,125 +1,77 @@ | ||
import { api as semver } from '.'; | ||
|
||
describe('versioning/hashicorp/index', () => { | ||
describe('semver.matches()', () => { | ||
it('handles tilde greater than', () => { | ||
expect(semver.matches('4.2.0', '~> 4.0')).toBe(true); | ||
expect(semver.matches('4.2.0', '~> 4.0.0')).toBe(false); | ||
}); | ||
}); | ||
describe('semver.getSatisfyingVersion()', () => { | ||
it('handles tilde greater than', () => { | ||
expect( | ||
semver.getSatisfyingVersion( | ||
['0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0'], | ||
'~> 4.0' | ||
) | ||
).toBe('4.2.0'); | ||
expect( | ||
semver.getSatisfyingVersion( | ||
['0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0'], | ||
'~> 4.0.0' | ||
) | ||
).toBe('4.0.0'); | ||
}); | ||
}); | ||
describe('semver.isValid()', () => { | ||
it('handles comma', () => { | ||
expect(semver.isValid('>= 1.0.0, <= 2.0.0')).toBeTruthy(); | ||
}); | ||
}); | ||
describe('semver.isLessThanRange()', () => { | ||
it('handles comma', () => { | ||
expect(semver.isLessThanRange('0.9.0', '>= 1.0.0, <= 2.0.0')).toBe(true); | ||
expect(semver.isLessThanRange('1.9.0', '>= 1.0.0, <= 2.0.0')).toBe(false); | ||
}); | ||
}); | ||
describe('semver.minSatisfyingVersion()', () => { | ||
it('handles tilde greater than', () => { | ||
expect( | ||
semver.minSatisfyingVersion( | ||
['0.4.0', '0.5.0', '4.2.0', '5.0.0'], | ||
'~> 4.0' | ||
) | ||
).toBe('4.2.0'); | ||
expect( | ||
semver.minSatisfyingVersion( | ||
['0.4.0', '0.5.0', '4.2.0', '5.0.0'], | ||
'~> 4.0.0' | ||
) | ||
).toBeNull(); | ||
}); | ||
}); | ||
describe('semver.getNewValue()', () => { | ||
it('handles tilde greater than', () => { | ||
expect( | ||
semver.getNewValue({ | ||
currentValue: '~> 1.2', | ||
rangeStrategy: 'replace', | ||
currentVersion: '1.2.3', | ||
newVersion: '2.0.7', | ||
}) | ||
).toEqual('~> 2.0'); | ||
expect( | ||
semver.getNewValue({ | ||
currentValue: '~> 1.2.0', | ||
rangeStrategy: 'replace', | ||
currentVersion: '1.2.3', | ||
newVersion: '2.0.7', | ||
}) | ||
).toEqual('~> 2.0.0'); | ||
expect( | ||
semver.getNewValue({ | ||
currentValue: '~> 0.14.0', | ||
rangeStrategy: 'replace', | ||
currentVersion: '0.14.1', | ||
newVersion: '0.15.0', | ||
}) | ||
).toEqual('~> 0.15.0'); | ||
expect( | ||
semver.getNewValue({ | ||
currentValue: '~> 0.14.0', | ||
rangeStrategy: 'replace', | ||
currentVersion: '0.14.1', | ||
newVersion: '0.15.1', | ||
}) | ||
).toEqual('~> 0.15.0'); | ||
expect( | ||
semver.getNewValue({ | ||
currentValue: '~> 0.14.6', | ||
rangeStrategy: 'replace', | ||
currentVersion: '0.14.6', | ||
newVersion: '0.15.0', | ||
}) | ||
).toEqual('~> 0.15.0'); | ||
}); | ||
it('handles comma dividers', () => { | ||
expect( | ||
semver.getNewValue({ | ||
currentValue: '>= 1.0.0, <= 2.0.0', | ||
rangeStrategy: 'widen', | ||
currentVersion: '1.2.3', | ||
newVersion: '2.0.7', | ||
}) | ||
).toEqual('>= 1.0.0, <= 2.0.7'); | ||
}); | ||
it('updates short ranges', () => { | ||
expect( | ||
semver.getNewValue({ | ||
currentValue: '0.14', | ||
rangeStrategy: 'replace', | ||
currentVersion: '0.14.2', | ||
newVersion: '0.15.0', | ||
}) | ||
).toEqual('0.15'); | ||
expect( | ||
semver.getNewValue({ | ||
currentValue: '~> 0.14', | ||
rangeStrategy: 'replace', | ||
currentVersion: '0.14.2', | ||
newVersion: '0.15.0', | ||
}) | ||
).toEqual('~> 0.15'); | ||
}); | ||
test.each` | ||
version | range | expected | ||
${'4.2.0'} | ${'~> 4.0'} | ${true} | ||
${'4.2.0'} | ${'~> 4.0.0'} | ${false} | ||
`( | ||
'matches("$version", "$range") === $expected', | ||
({ version, range, expected }) => { | ||
expect(semver.matches(version, range)).toBe(expected); | ||
} | ||
); | ||
test.each` | ||
versions | range | expected | ||
${['0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0']} | ${'~> 4.0'} | ${'4.2.0'} | ||
${['0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0']} | ${'~> 4.0.0'} | ${'4.0.0'} | ||
`( | ||
'getSatisfyingVersion($versions, "$range") === $expected', | ||
({ versions, range, expected }) => { | ||
expect(semver.getSatisfyingVersion(versions, range)).toBe(expected); | ||
} | ||
); | ||
|
||
test.each` | ||
input | expected | ||
${'>= 1.0.0, <= 2.0.0'} | ${true} | ||
`('isValid("$input") === $expected', ({ input, expected }) => { | ||
const res = !!semver.isValid(input); | ||
expect(res).toBe(expected); | ||
}); | ||
|
||
test.each` | ||
version | range | expected | ||
${'0.9.0'} | ${'>= 1.0.0, <= 2.0.0'} | ${true} | ||
${'1.9.0'} | ${'>= 1.0.0, <= 2.0.0'} | ${false} | ||
`( | ||
'isLessThanRange($version, $range) === $expected', | ||
({ version, range, expected }) => { | ||
expect(semver.isLessThanRange(version, range)).toBe(expected); | ||
} | ||
); | ||
|
||
test.each` | ||
versions | range | expected | ||
${['0.4.0', '0.5.0', '4.2.0', '5.0.0']} | ${'~> 4.0'} | ${'4.2.0'} | ||
${['0.4.0', '0.5.0', '4.2.0', '5.0.0']} | ${'~> 4.0.0'} | ${null} | ||
`( | ||
'minSatisfyingVersion($versions, "$range") === $expected', | ||
({ versions, range, expected }) => { | ||
expect(semver.minSatisfyingVersion(versions, range)).toBe(expected); | ||
} | ||
); | ||
|
||
test.each` | ||
currentValue | rangeStrategy | currentVersion | newVersion | expected | ||
${'~> 1.2'} | ${'replace'} | ${'1.2.3'} | ${'2.0.7'} | ${'~> 2.0'} | ||
${'~> 1.2.0'} | ${'replace'} | ${'1.2.3'} | ${'2.0.7'} | ${'~> 2.0.0'} | ||
${'~> 0.14.0'} | ${'replace'} | ${'0.14.1'} | ${'0.15.0'} | ${'~> 0.15.0'} | ||
${'~> 0.14.0'} | ${'replace'} | ${'0.14.1'} | ${'0.15.1'} | ${'~> 0.15.0'} | ||
${'~> 0.14.6'} | ${'replace'} | ${'0.14.6'} | ${'0.15.0'} | ${'~> 0.15.0'} | ||
${'>= 1.0.0, <= 2.0.0'} | ${'widen'} | ${'1.2.3'} | ${'2.0.7'} | ${'>= 1.0.0, <= 2.0.7'} | ||
${'0.14'} | ${'replace'} | ${'0.14.2'} | ${'0.15.0'} | ${'0.15'} | ||
${'~> 0.14'} | ${'replace'} | ${'0.14.2'} | ${'0.15.0'} | ${'~> 0.15'} | ||
`( | ||
'getNewValue("$currentValue", "$rangeStrategy", "$currentVersion", "$newVersion") === "$expected"', | ||
({ currentValue, rangeStrategy, currentVersion, newVersion, expected }) => { | ||
const res = semver.getNewValue({ | ||
currentValue, | ||
rangeStrategy, | ||
currentVersion, | ||
newVersion, | ||
}); | ||
expect(res).toEqual(expected); | ||
} | ||
); | ||
}); |
Oops, something went wrong.