| 1 | import { expect, it } from "@effect/vitest"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import { ChildProcessSpawner } from "effect/process"; |
| 4 | import { vi } from "vite-plus/test"; |
| 5 | |
| 6 | vi.mock("@napi-rs/keyring", () => { |
| 7 | throw new Error("Cannot find native binding"); |
| 8 | }); |
| 9 | |
| 10 | it.effect("reports an unavailable keychain when the macOS binding cannot load", () => |
| 11 | Effect.gen(function* () { |
| 12 | const { ChromiumKeyError, resolveChromiumKeys } = yield* Effect.promise( |
| 13 | () => import("./ChromiumKeys.ts"), |
| 14 | ); |
| 15 | const error = yield* resolveChromiumKeys({ |
| 16 | platform: "darwin", |
| 17 | keychainService: "Chrome Safe Storage", |
| 18 | keychainAccount: "Chrome", |
| 19 | linuxSecretApplication: undefined, |
| 20 | }).pipe(Effect.flip); |
| 21 | |
| 22 | expect(error).toBeInstanceOf(ChromiumKeyError); |
| 23 | expect(error.reason).toBe("keychainUnavailable"); |
| 24 | expect(error.cause).toBeInstanceOf(Error); |
| 25 | }).pipe( |
| 26 | Effect.provideService( |
| 27 | ChildProcessSpawner.ChildProcessSpawner, |
| 28 | ChildProcessSpawner.make(() => Effect.die("must not spawn")), |
| 29 | ), |
| 30 | ), |
| 31 | ); |