feat: release authentication diagnostics 0.2.0

This commit is contained in:
2026-08-19 14:13:48 +02:00
parent 603559c540
commit 53cc91f2a5
41 changed files with 3472 additions and 154 deletions
+40
View File
@@ -0,0 +1,40 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { decodeQrImage } from "../../src/qr/decoder";
describe("QR image decoding", () => {
afterEach(() => vi.unstubAllGlobals());
it("uses native QR detection when available and closes the bitmap", async () => {
const close = vi.fn();
vi.stubGlobal(
"createImageBitmap",
vi.fn().mockResolvedValue({ width: 128, height: 128, close }),
);
vi.stubGlobal(
"BarcodeDetector",
class {
async detect() {
return [
{ rawValue: "otpauth://totp/Example?secret=JBSWY3DPEHPK3PXP" },
];
}
},
);
await expect(
decodeQrImage(new File([new Uint8Array(10)], "qr.png")),
).resolves.toMatch(/^otpauth:/u);
expect(close).toHaveBeenCalledOnce();
});
it("rejects oversized dimensions before pixel extraction", async () => {
const close = vi.fn();
vi.stubGlobal(
"createImageBitmap",
vi.fn().mockResolvedValue({ width: 4097, height: 1, close }),
);
await expect(
decodeQrImage(new File([new Uint8Array(10)], "huge.png")),
).rejects.toThrow(/dimensions/iu);
expect(close).toHaveBeenCalledOnce();
});
});