Files
quak/test/crypto/init.test.ts
sneak d8a4b0291e Rename quack to quak
German for 'quack', matching the Ente (German for 'duck') naming. All
references updated: package name, CLI binary, X-Client-Package header,
test descriptions, temp dir prefixes, README, Makefile docker tag.
2026-05-13 18:02:55 -07:00

39 lines
1.3 KiB
TypeScript

/**
* 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();
});
});