2020-05-01 16:03:48 +00:00
|
|
|
import swift from '.';
|
2019-07-22 11:12:40 +00:00
|
|
|
|
2019-06-24 16:43:48 +00:00
|
|
|
const {
|
|
|
|
getNewValue,
|
|
|
|
isValid,
|
2020-04-08 09:05:40 +00:00
|
|
|
isVersion,
|
2019-06-24 16:43:48 +00:00
|
|
|
minSatisfyingVersion,
|
2020-12-10 08:25:04 +00:00
|
|
|
getSatisfyingVersion,
|
2019-06-24 16:43:48 +00:00
|
|
|
isLessThanRange,
|
|
|
|
matches,
|
2019-07-22 11:12:40 +00:00
|
|
|
} = swift;
|
2019-06-24 16:43:48 +00:00
|
|
|
|
2022-03-03 09:35:26 +00:00
|
|
|
describe('modules/versioning/swift/index', () => {
|
2023-04-28 04:33:15 +00:00
|
|
|
it.each`
|
2021-10-05 09:38:51 +00:00
|
|
|
version | expected
|
|
|
|
${'from: "1.2.3"'} | ${false}
|
|
|
|
${'1.2.3'} | ${true}
|
2024-05-03 13:02:07 +00:00
|
|
|
${'v1.2.3'} | ${true}
|
|
|
|
${'a'} | ${false}
|
2021-10-05 09:38:51 +00:00
|
|
|
`('isVersion("$version") === $expected', ({ version, expected }) => {
|
|
|
|
expect(!!isVersion(version)).toBe(expected);
|
|
|
|
});
|
2019-06-24 16:43:48 +00:00
|
|
|
|
2023-04-28 04:33:15 +00:00
|
|
|
it.each`
|
2021-10-05 09:38:51 +00:00
|
|
|
version | expected
|
|
|
|
${'from: "1.2.3"'} | ${true}
|
|
|
|
${'from : "1.2.3"'} | ${true}
|
2021-11-29 07:33:36 +00:00
|
|
|
${'from : "1.2.3.4.5"'} | ${false}
|
2021-10-05 09:38:51 +00:00
|
|
|
${'from:"1.2.3"'} | ${true}
|
|
|
|
${' from:"1.2.3" '} | ${true}
|
|
|
|
${' from : "1.2.3" '} | ${true}
|
|
|
|
${'"1.2.3"..."1.2.4"'} | ${true}
|
|
|
|
${' "1.2.3" ... "1.2.4" '} | ${true}
|
|
|
|
${'"1.2.3"...'} | ${true}
|
2021-11-29 07:33:36 +00:00
|
|
|
${'"1.2.3.4.5"...'} | ${false}
|
2021-10-05 09:38:51 +00:00
|
|
|
${' "1.2.3" ... '} | ${true}
|
|
|
|
${'..."1.2.4"'} | ${true}
|
|
|
|
${' ... "1.2.4" '} | ${true}
|
|
|
|
${'"1.2.3"..<"1.2.4"'} | ${true}
|
2021-11-29 07:33:36 +00:00
|
|
|
${'"1.2.3.4.5"..<"1.2.4"'} | ${false}
|
2021-10-05 09:38:51 +00:00
|
|
|
${' "1.2.3" ..< "1.2.4" '} | ${true}
|
|
|
|
${'..<"1.2.4"'} | ${true}
|
|
|
|
${' ..< "1.2.4" '} | ${true}
|
|
|
|
${'17.04.0'} | ${false}
|
|
|
|
${'1.2.3'} | ${true}
|
|
|
|
${'v1.2.3'} | ${true}
|
|
|
|
${'1.2.3-foo'} | ${true}
|
|
|
|
${'1.2.3foo'} | ${false}
|
|
|
|
${'~1.2.3'} | ${false}
|
|
|
|
${'^1.2.3'} | ${false}
|
|
|
|
${'from: "1.2.3"'} | ${true}
|
|
|
|
${'"1.2.3"..."1.2.4"'} | ${true}
|
|
|
|
${'"1.2.3"..."1.2.4"'} | ${true}
|
|
|
|
${'"1.2.3"..<"1.2.4"'} | ${true}
|
|
|
|
${'"1.2.3"..<"1.2.4"'} | ${true}
|
|
|
|
${'..."1.2.3"'} | ${true}
|
|
|
|
${'..<"1.2.4"'} | ${true}
|
|
|
|
`('isValid("$version") === $expected', ({ version, expected }) => {
|
|
|
|
expect(!!isValid(version)).toBe(expected);
|
|
|
|
});
|
2019-06-24 16:43:48 +00:00
|
|
|
|
2023-04-28 04:33:15 +00:00
|
|
|
it.each`
|
2021-10-05 09:38:51 +00:00
|
|
|
versions | range | expected
|
|
|
|
${['1.2.3', '1.2.4', '1.2.5']} | ${'..<"1.2.4"'} | ${'1.2.3'}
|
|
|
|
${['v1.2.3', 'v1.2.4', 'v1.2.5']} | ${'..<"1.2.4"'} | ${'1.2.3'}
|
2023-09-06 11:26:22 +00:00
|
|
|
${['v1.2.3', 'v1.2.4', 'v1.2.5']} | ${''} | ${null}
|
2021-10-05 09:38:51 +00:00
|
|
|
`(
|
|
|
|
'minSatisfyingVersion($versions, "$range") === "$expected"',
|
|
|
|
({ versions, range, expected }) => {
|
|
|
|
expect(minSatisfyingVersion(versions, range)).toBe(expected);
|
2023-11-07 15:50:29 +00:00
|
|
|
},
|
2021-10-05 09:38:51 +00:00
|
|
|
);
|
2019-06-24 16:43:48 +00:00
|
|
|
|
2023-04-28 04:33:15 +00:00
|
|
|
it.each`
|
2021-10-05 09:38:51 +00:00
|
|
|
versions | range | expected
|
|
|
|
${['1.2.3', '1.2.4', '1.2.5']} | ${'..<"1.2.4"'} | ${'1.2.3'}
|
|
|
|
${['v1.2.3', 'v1.2.4', 'v1.2.5']} | ${'..<"1.2.4"'} | ${'1.2.3'}
|
|
|
|
${['1.2.3', '1.2.4', '1.2.5']} | ${'..."1.2.4"'} | ${'1.2.4'}
|
2023-09-06 11:26:22 +00:00
|
|
|
${['1.2.3', '1.2.4', '1.2.5']} | ${''} | ${null}
|
2021-10-05 09:38:51 +00:00
|
|
|
`(
|
|
|
|
'getSatisfyingVersion($versions, "$range") === "$expected"',
|
|
|
|
({ versions, range, expected }) => {
|
|
|
|
expect(getSatisfyingVersion(versions, range)).toBe(expected);
|
2023-11-07 15:50:29 +00:00
|
|
|
},
|
2021-10-05 09:38:51 +00:00
|
|
|
);
|
2019-06-24 16:43:48 +00:00
|
|
|
|
2023-04-28 04:33:15 +00:00
|
|
|
it.each`
|
2021-10-05 09:38:51 +00:00
|
|
|
version | range | expected
|
|
|
|
${'1.2.3'} | ${'..."1.2.4"'} | ${false}
|
|
|
|
${'v1.2.3'} | ${'..."1.2.4"'} | ${false}
|
|
|
|
${'1.2.3'} | ${'"1.2.4"...'} | ${true}
|
|
|
|
${'v1.2.3'} | ${'"1.2.4"...'} | ${true}
|
2023-09-06 11:26:22 +00:00
|
|
|
${'v1.2.3'} | ${''} | ${false}
|
2021-10-05 09:38:51 +00:00
|
|
|
`(
|
|
|
|
'isLessThanRange("$version", "$range") === "$expected"',
|
|
|
|
({ version, range, expected }) => {
|
2021-11-29 07:33:36 +00:00
|
|
|
expect(isLessThanRange?.(version, range)).toBe(expected);
|
2023-11-07 15:50:29 +00:00
|
|
|
},
|
2021-10-05 09:38:51 +00:00
|
|
|
);
|
2019-06-24 16:43:48 +00:00
|
|
|
|
2023-04-28 04:33:15 +00:00
|
|
|
it.each`
|
2021-10-05 09:38:51 +00:00
|
|
|
version | range | expected
|
2024-03-08 19:35:03 +00:00
|
|
|
${'1.2.3'} | ${'1.2.3'} | ${true}
|
2024-05-03 13:02:07 +00:00
|
|
|
${'v1.2.3'} | ${'1.2.3'} | ${true}
|
2021-10-05 09:38:51 +00:00
|
|
|
${'1.2.4'} | ${'..."1.2.4"'} | ${true}
|
|
|
|
${'v1.2.4'} | ${'..."1.2.4"'} | ${true}
|
|
|
|
${'1.2.4'} | ${'..."1.2.3"'} | ${false}
|
|
|
|
${'v1.2.4'} | ${'..."1.2.3"'} | ${false}
|
2023-09-06 11:26:22 +00:00
|
|
|
${'v1.2.4'} | ${''} | ${false}
|
2021-10-05 09:38:51 +00:00
|
|
|
`(
|
|
|
|
'matches("$version", "$range") === "$expected"',
|
|
|
|
({ version, range, expected }) => {
|
|
|
|
expect(matches(version, range)).toBe(expected);
|
2023-11-07 15:50:29 +00:00
|
|
|
},
|
2021-10-05 09:38:51 +00:00
|
|
|
);
|
2020-01-29 11:23:19 +00:00
|
|
|
|
2023-04-28 04:33:15 +00:00
|
|
|
it.each`
|
2021-10-05 09:38:51 +00:00
|
|
|
currentValue | rangeStrategy | currentVersion | newVersion | expected
|
2023-08-22 18:56:06 +00:00
|
|
|
${'1.2.3'} | ${'auto'} | ${'1.2.3'} | ${'1.2.4'} | ${'1.2.4'}
|
|
|
|
${'1.2.3'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.4'} | ${'1.2.4'}
|
2021-10-05 09:38:51 +00:00
|
|
|
${'from: "1.2.3"'} | ${'auto'} | ${'1.2.3'} | ${'1.2.4'} | ${'from: "1.2.4"'}
|
2023-08-22 17:08:28 +00:00
|
|
|
${'from: "1.2.3"'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.4'} | ${'from: "1.2.4"'}
|
2021-10-05 09:38:51 +00:00
|
|
|
${'from: "1.2.2"'} | ${'auto'} | ${'1.2.3'} | ${'1.2.4'} | ${'from: "1.2.4"'}
|
2023-08-22 17:08:28 +00:00
|
|
|
${'from: "1.2.2"'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.4'} | ${'from: "1.2.4"'}
|
2021-10-05 09:38:51 +00:00
|
|
|
${'"1.2.3"...'} | ${'auto'} | ${'1.2.3'} | ${'1.2.4'} | ${'"1.2.4"...'}
|
2023-08-22 17:08:28 +00:00
|
|
|
${'"1.2.3"...'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.4'} | ${'"1.2.4"...'}
|
2021-10-05 09:38:51 +00:00
|
|
|
${'"1.2.3"..."1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'1.2.5'} | ${'"1.2.3"..."1.2.5"'}
|
2023-08-22 17:08:28 +00:00
|
|
|
${'"1.2.3"..."1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.5'} | ${'"1.2.3"..."1.2.5"'}
|
2021-10-05 09:38:51 +00:00
|
|
|
${'"1.2.3"..<"1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'1.2.5'} | ${'"1.2.3"..<"1.2.5"'}
|
2023-08-22 17:08:28 +00:00
|
|
|
${'"1.2.3"..<"1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.5'} | ${'"1.2.3"..<"1.2.5"'}
|
2021-10-05 09:38:51 +00:00
|
|
|
${'..."1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'1.2.5'} | ${'..."1.2.5"'}
|
2023-08-22 17:08:28 +00:00
|
|
|
${'..."1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.5'} | ${'..."1.2.5"'}
|
2021-10-05 09:38:51 +00:00
|
|
|
${'..<"1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'1.2.5'} | ${'..<"1.2.5"'}
|
2023-08-22 17:08:28 +00:00
|
|
|
${'..<"1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.5'} | ${'..<"1.2.5"'}
|
2021-10-05 09:38:51 +00:00
|
|
|
`(
|
|
|
|
'getNewValue("$currentValue", "$rangeStrategy", "$currentVersion", "$newVersion") === "$expected"',
|
|
|
|
({ currentValue, rangeStrategy, currentVersion, newVersion, expected }) => {
|
|
|
|
expect(
|
|
|
|
getNewValue({
|
|
|
|
currentValue,
|
|
|
|
rangeStrategy,
|
|
|
|
currentVersion,
|
|
|
|
newVersion,
|
2023-11-07 15:50:29 +00:00
|
|
|
}),
|
2021-10-05 09:38:51 +00:00
|
|
|
).toBe(expected);
|
2023-11-07 15:50:29 +00:00
|
|
|
},
|
2021-10-05 09:38:51 +00:00
|
|
|
);
|
2019-06-24 16:43:48 +00:00
|
|
|
});
|