mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
refactoring extensions/__tests__/is-compatible-extension.test.ts
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
c376b848c9
commit
52d16df45b
@ -9,108 +9,47 @@ import {
|
||||
} from "../extension-discovery/is-compatible-extension/is-compatible-extension";
|
||||
import type { LensExtensionManifest } from "../lens-extension";
|
||||
|
||||
describe("Extension/App versions compatibility check", () => {
|
||||
describe("Extension/App versions compatibility checks", () => {
|
||||
it("is compatible with exact version matching", () => {
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("5.5.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "5.5.0",
|
||||
}))).toBeTruthy();
|
||||
expect(isCompatible("5.5.0", "5.5.0")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("is compatible with upper %PATCH versions of base app", () => {
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("5.5.5"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "5.5.0",
|
||||
}))).toBeTruthy();
|
||||
expect(isCompatible("5.5.0", "5.5.5")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("is compatible with upper %MINOR version of base app", () => {
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("5.6.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "5.5.0",
|
||||
}))).toBeTruthy();
|
||||
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("5.5.0-alpha.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "^5.5.0",
|
||||
}))).toBeTruthy();
|
||||
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("5.5"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "^5.6.0",
|
||||
}))).toBeFalsy();
|
||||
it("is compatible with higher %MINOR version of base app", () => {
|
||||
expect(isCompatible("5.5.0", "5.6.0")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("is not compatible with upper %MAJOR version of base app", () => {
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("5.5.0"), // current lens-version
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "6.0.0",
|
||||
}))).toBeFalsy(); // extension with lens@6.0 is not compatible with app@5.5
|
||||
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("6.0.0"), // current lens-version
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "5.5.0",
|
||||
}))).toBeFalsy(); // extension with lens@5.5 is not compatible with app@6.0
|
||||
it("is not compatible with higher %MAJOR version of base app", () => {
|
||||
expect(isCompatible("5.6.0", "6.0.0")).toBeFalsy(); // extension for lens@5 not compatible with lens@6
|
||||
expect(isCompatible("6.0.0", "5.6.0")).toBeFalsy();
|
||||
});
|
||||
|
||||
it("is compatible with lensEngine with prerelease", () => {
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.parse("5.5.0-alpha.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "^5.4.0-alpha.0",
|
||||
}))).toBeTruthy();
|
||||
expect(isCompatible("^5.4.0-alpha.0", "5.5.0-alpha.0")).toBeTruthy();
|
||||
});
|
||||
|
||||
describe("supported formats for manifest.engines.lens", () => {
|
||||
it("short version format for engines.lens", () => {
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("5.5.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "5.5",
|
||||
}))).toBeTruthy();
|
||||
});
|
||||
it("supports short version format for manifest.engines.lens", () => {
|
||||
expect(isCompatible("5.5.0", "5.5")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("validates version and throws if incorrect format", () => {
|
||||
expect(() => isCompatibleExtension({
|
||||
appSemVer: semver.coerce("1.0.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "1.0",
|
||||
}))).not.toThrow();
|
||||
|
||||
expect(() => isCompatibleExtension({
|
||||
appSemVer: semver.coerce("1.0.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "^1.0",
|
||||
}))).not.toThrow();
|
||||
|
||||
expect(() => isCompatibleExtension({
|
||||
appSemVer: semver.coerce("1.0.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: ">=2.0",
|
||||
}))).toThrow(/Invalid format/i);
|
||||
});
|
||||
|
||||
it("'*' cannot be used for any version matching (at least in the prefix)", () => {
|
||||
expect(() => isCompatibleExtension({
|
||||
appSemVer: semver.coerce("1.0.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "*",
|
||||
}))).toThrowError(/Invalid format/i);
|
||||
});
|
||||
it("throws for incorrect or not supported version format", () => {
|
||||
expect(() => isCompatible(">=2.0", "2.0")).toThrow(/Invalid format/i);
|
||||
expect(() => isCompatible("~2.0", "2.0")).toThrow(/Invalid format/i);
|
||||
expect(() => isCompatible("*", "1.0")).toThrow(/Invalid format/i);
|
||||
});
|
||||
});
|
||||
|
||||
function getExtensionManifestMock(
|
||||
{
|
||||
lensEngine = "1.0",
|
||||
} = {}): LensExtensionManifest {
|
||||
function isCompatible(extensionLensEngine = "^1.0", appVersion = "1.0"): boolean {
|
||||
const appSemVer = semver.coerce(appVersion);
|
||||
const extensionManifestMock = getExtensionManifestMock(extensionLensEngine);
|
||||
|
||||
return isCompatibleExtension({ appSemVer })(extensionManifestMock);
|
||||
}
|
||||
|
||||
function getExtensionManifestMock(lensEngine = "1.0"): LensExtensionManifest {
|
||||
return {
|
||||
name: "some-extension",
|
||||
version: "1.0",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user