Fix Safari TP and regular versions comparison (#8132)
This commit is contained in:
committed by
Henry Zhu
parent
119db23ee3
commit
9e4c56f990
@@ -74,21 +74,31 @@ const getLowestVersions = (browsers: Array<string>): Targets => {
|
||||
try {
|
||||
// Browser version can return as "10.0-10.2"
|
||||
const splitVersion = browserVersion.split("-")[0].toLowerCase();
|
||||
const isSplitUnreleased = isUnreleasedVersion(splitVersion, browserName);
|
||||
|
||||
if (isUnreleasedVersion(splitVersion, browserName)) {
|
||||
if (!all[normalizedBrowserName]) {
|
||||
all[normalizedBrowserName] = isSplitUnreleased
|
||||
? splitVersion
|
||||
: semverify(splitVersion);
|
||||
return all;
|
||||
}
|
||||
|
||||
const version = all[normalizedBrowserName];
|
||||
const isUnreleased = isUnreleasedVersion(version, browserName);
|
||||
|
||||
if (isUnreleased && isSplitUnreleased) {
|
||||
all[normalizedBrowserName] = getLowestUnreleased(
|
||||
all[normalizedBrowserName],
|
||||
version,
|
||||
splitVersion,
|
||||
browserName,
|
||||
);
|
||||
} else if (isUnreleased) {
|
||||
all[normalizedBrowserName] = semverify(splitVersion);
|
||||
} else if (!isUnreleased && !isSplitUnreleased) {
|
||||
const parsedBrowserVersion = semverify(splitVersion);
|
||||
|
||||
all[normalizedBrowserName] = semverMin(version, parsedBrowserVersion);
|
||||
}
|
||||
|
||||
const parsedBrowserVersion = semverify(splitVersion);
|
||||
|
||||
all[normalizedBrowserName] = semverMin(
|
||||
all[normalizedBrowserName],
|
||||
parsedBrowserVersion,
|
||||
);
|
||||
} catch (e) {}
|
||||
|
||||
return all;
|
||||
|
||||
@@ -75,6 +75,16 @@ describe("getTargets", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("prefers released version over TP", () => {
|
||||
expect(
|
||||
getTargets({
|
||||
browsers: "safari tp, safari 11",
|
||||
}),
|
||||
).toEqual({
|
||||
safari: "11.0.0",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns TP version in lower case", () => {
|
||||
expect(
|
||||
getTargets({
|
||||
@@ -84,6 +94,41 @@ describe("getTargets", () => {
|
||||
safari: "tp",
|
||||
});
|
||||
});
|
||||
|
||||
it("works with android", () => {
|
||||
expect(
|
||||
getTargets({
|
||||
browsers: "Android 4",
|
||||
}),
|
||||
).toEqual({
|
||||
android: "4.0.0",
|
||||
});
|
||||
});
|
||||
|
||||
it("works with inequalities", () => {
|
||||
expect(
|
||||
getTargets({
|
||||
browsers: "Android >= 4",
|
||||
}),
|
||||
).toEqual({
|
||||
android: "4.0.0",
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores invalid", () => {
|
||||
expect(
|
||||
getTargets({
|
||||
browsers: 59,
|
||||
chrome: "49",
|
||||
firefox: "55",
|
||||
ie: "11",
|
||||
}),
|
||||
).toEqual({
|
||||
chrome: "49.0.0",
|
||||
firefox: "55.0.0",
|
||||
ie: "11.0.0",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("esmodules", () => {
|
||||
|
||||
Reference in New Issue
Block a user