Spaces:
Running
Running
File size: 987 Bytes
98c9143 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import { afterEach, expect, mock, test } from "bun:test"
import { getVSCodeDeviceId } from "../src/lib/deviceid"
const failingRegistryError = new Error("registry unavailable")
class FailingWinreg {
static HKCU = "HKCU"
static REG_SZ = "REG_SZ"
get(
_name: string,
callback: (error: Error | null, item: { value?: string } | null) => void,
) {
callback(failingRegistryError, null)
}
set(
...args: [
name: string,
type: string,
value: string,
callback: (error: Error | null) => void,
]
) {
const callback = args[3]
callback(failingRegistryError)
}
}
afterEach(() => {
mock.restore()
})
test("getVSCodeDeviceId falls back to an ephemeral UUID when persistence fails", async () => {
await mock.module("winreg", () => ({
default: FailingWinreg,
}))
const deviceId = await getVSCodeDeviceId()
expect(deviceId).toMatch(
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,
)
})
|