/** * Tests for `crypto.init()`. * * libsodium ships as WebAssembly. The bindings (`libsodium-wrappers-sumo`) * load asynchronously: the runtime must `await sodium.ready` once before any * crypto call is safe. quak hides that detail behind a single * `init()` function. * * Every other test in `test/crypto/**` calls `init()` in `beforeAll`. New * code that needs crypto should do the same. Calling it more than once is * cheap and intentional; the second call returns the same already-resolved * promise. */ import { beforeAll, describe, expect, it } from "vitest"; import { init } from "../../src/crypto/index.js"; describe("crypto.init", () => { beforeAll(async () => { await init(); }); it("resolves without throwing", async () => { // The success criterion is simply that the promise resolves. If // libsodium's WASM fails to load, `init()` rejects and this test // fails. await expect(init()).resolves.toBeUndefined(); }); it("is idempotent: repeated calls are safe", async () => { // Code paths in this library may call `init()` defensively (e.g. a // `Client` constructor that doesn't know whether the caller already // initialised). Repeated calls must therefore be harmless. await init(); await init(); await init(); }); });