feat(ZooMigration): add test for extension already installed

This commit is contained in:
Elliott de Launay 2026-05-09 13:46:09 +00:00
parent e6c6688024
commit 1be8a40884
No known key found for this signature in database
GPG key ID: 1F579AB92ABAA926
2 changed files with 26 additions and 4 deletions

View file

@ -202,10 +202,13 @@ export async function showZooMigrationNotice(
export async function installOrShowZooExtension(): Promise<void> {
try {
await vscode.commands.executeCommand("workbench.extensions.installExtension", ZOO_EXTENSION_ID)
} catch {
await vscode.commands.executeCommand("workbench.extensions.search", ZOO_EXTENSION_ID)
await vscode.window.showInformationMessage(t("common:zooMigration.installUnavailable"))
}
if (vscode.extensions.getExtension(ZOO_EXTENSION_ID)) {
return
}
} catch {}
await vscode.commands.executeCommand("workbench.extensions.search", ZOO_EXTENSION_ID)
await vscode.window.showInformationMessage(t("common:zooMigration.installUnavailable"))
}
export async function promptAndCreateZooMigrationHandoff(options: {

View file

@ -207,6 +207,7 @@ describe("installOrShowZooExtension", () => {
it("installs the published Zoo Code marketplace extension", async () => {
const executeCommand = vi.spyOn(vscode.commands, "executeCommand").mockResolvedValue(undefined)
vi.spyOn(vscode.extensions, "getExtension").mockReturnValue({} as any)
await installOrShowZooExtension()
@ -214,6 +215,7 @@ describe("installOrShowZooExtension", () => {
"workbench.extensions.installExtension",
"ZooCodeOrganization.zoo-code",
)
expect(executeCommand).toHaveBeenCalledTimes(1)
})
it("falls back to extension search when the configured gallery cannot install Zoo Code yet", async () => {
@ -233,6 +235,23 @@ describe("installOrShowZooExtension", () => {
expect(executeCommand).toHaveBeenNthCalledWith(2, "workbench.extensions.search", "ZooCodeOrganization.zoo-code")
expect(showInformationMessage).toHaveBeenCalled()
})
it("falls back to extension search when install resolves without installing Zoo Code", async () => {
const executeCommand = vi.spyOn(vscode.commands, "executeCommand").mockResolvedValue(undefined)
vi.spyOn(vscode.extensions, "getExtension").mockReturnValue(undefined)
const showInformationMessage = vi.spyOn(vscode.window, "showInformationMessage").mockResolvedValue(undefined)
await installOrShowZooExtension()
expect(executeCommand).toHaveBeenNthCalledWith(
1,
"workbench.extensions.installExtension",
"ZooCodeOrganization.zoo-code",
)
expect(vscode.extensions.getExtension).toHaveBeenCalledWith("ZooCodeOrganization.zoo-code")
expect(executeCommand).toHaveBeenNthCalledWith(2, "workbench.extensions.search", "ZooCodeOrganization.zoo-code")
expect(showInformationMessage).toHaveBeenCalled()
})
})
function makeContext(globalStoragePath: string): vscode.ExtensionContext {