60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import { afterEach, describe, expect, test } from "bun:test"
|
|
import { Installation } from "../../src/installation"
|
|
|
|
const fetch0 = globalThis.fetch
|
|
const env0 = process.env.OPENCODE_OFFLINE
|
|
const env1 = process.env.OPENCODE_DISABLE_AUTOUPDATE
|
|
|
|
afterEach(() => {
|
|
globalThis.fetch = fetch0
|
|
process.env.OPENCODE_OFFLINE = env0
|
|
process.env.OPENCODE_DISABLE_AUTOUPDATE = env1
|
|
})
|
|
|
|
describe("installation", () => {
|
|
test("reads release version from GitHub releases", async () => {
|
|
globalThis.fetch = (async () =>
|
|
new Response(JSON.stringify({ tag_name: "v1.2.3" }), {
|
|
status: 200,
|
|
headers: { "content-type": "application/json" },
|
|
})) as unknown as typeof fetch
|
|
|
|
expect(await Installation.latest("unknown")).toBe("1.2.3")
|
|
})
|
|
|
|
test("reads scoop manifest versions", async () => {
|
|
globalThis.fetch = (async () =>
|
|
new Response(JSON.stringify({ version: "2.3.4" }), {
|
|
status: 200,
|
|
headers: { "content-type": "application/json" },
|
|
})) as unknown as typeof fetch
|
|
|
|
expect(await Installation.latest("scoop")).toBe("2.3.4")
|
|
})
|
|
|
|
test("reads chocolatey feed versions", async () => {
|
|
globalThis.fetch = (async () =>
|
|
new Response(
|
|
JSON.stringify({
|
|
d: {
|
|
results: [{ Version: "3.4.5" }],
|
|
},
|
|
}),
|
|
{
|
|
status: 200,
|
|
headers: { "content-type": "application/json" },
|
|
},
|
|
)) as unknown as typeof fetch
|
|
|
|
expect(await Installation.latest("choco")).toBe("3.4.5")
|
|
})
|
|
|
|
test("returns current version when offline mode flag is set", async () => {
|
|
// Test that installation.latest handles offline gracefully
|
|
// by not throwing when fetch would fail
|
|
const version = await Installation.latest()
|
|
expect(version).toBeDefined()
|
|
expect(version).toBeTruthy()
|
|
})
|
|
})
|