Vitest
import { beforeEach, describe, expect, it, vi } from "vitest";
describe("isVersionGreater", () => {
it("should correctly compare major versions", () => {
expect(isVersionGreater("2.0.0", "1.0.0")).toBe(true);
expect(isVersionGreater("1.0.0", "2.0.0")).toBe(false);
expect(isVersionGreater("1.0.0", "1.0.0")).toBe(false);
});
}
describe("getActiveExtensionId", () => {
it("should return the extension ID when only one extension responds", async () => {
const chromeId = "chrome-extension-id";
const version = "1.0.0";
mockChromeRuntime.sendMessage.mockImplementation(
(extensionId, message, callback) => {
if (extensionId === chromeId) {
callback(version);
}
},
);
const result = await getActiveExtensionId(chromeId, undefined);
expect(result).toBe(chromeId);
expect(mockChromeRuntime.sendMessage).toHaveBeenCalledWith(
chromeId,
{ type: ExtensionExternalMessageType.getVersion },
expect.any(Function),
);
});
}Last updated