Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
import { readdir, readFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "@suaveplan/testing/runner";
const SRC_DIR = join(import.meta.dirname, "..", "src");
async function collectTsFiles(dir: string): Promise<string[]> {
const entries = await readdir(dir, { withFileTypes: true });
const files: string[] = [];
for (const entry of entries) {
const full = join(dir, entry.name);
if (entry.isDirectory()) {
files.push(...(await collectTsFiles(full)));
} else if (
entry.isFile() &&
entry.name.endsWith(".ts") &&
!entry.name.endsWith(".test.ts")
) {
files.push(full);
}
}
return files;
}
describe("source quality: no disallowed patterns", () => {
it("no vi.mock / jest.mock in src/", { timeout: 5000 }, async () => {
const files = await collectTsFiles(SRC_DIR);
const violations: string[] = [];
for (const file of files) {
const content = await readFile(file, "utf-8");
if (content.includes("vi.mock") || content.includes("jest.mock")) {
violations.push(file);
}
}
expect(violations).toEqual([]);
});
it("no TODO or FIXME in src/", { timeout: 5000 }, async () => {
const files = await collectTsFiles(SRC_DIR);
const violations: string[] = [];
for (const file of files) {
const content = await readFile(file, "utf-8");
if (/\bTODO\b|\bFIXME\b/.test(content)) {
violations.push(file);
}
}
expect(violations).toEqual([]);
});
it("no ts-ignore in src/", { timeout: 5000 }, async () => {
const files = await collectTsFiles(SRC_DIR);
const violations: string[] = [];
for (const file of files) {
const content = await readFile(file, "utf-8");
if (content.includes("@ts-ignore")) {
violations.push(file);
}
}
expect(violations).toEqual([]);
});
});

View File

@@ -0,0 +1,13 @@
import { webcrypto } from "node:crypto";
type WritableGlobal = { crypto?: Crypto; CryptoKey?: typeof CryptoKey };
const g = globalThis as WritableGlobal;
if (g.crypto === undefined) {
g.crypto = webcrypto as unknown as Crypto;
}
if (g.CryptoKey === undefined) {
// Node exposes CryptoKey on the webcrypto object
g.CryptoKey = (
webcrypto as unknown as { CryptoKey: typeof CryptoKey }
).CryptoKey;
}

View File

@@ -0,0 +1,49 @@
import { describe, expect, it } from "@suaveplan/testing/runner";
describe("tree-shake: selective imports work", () => {
it("importing only availability does not throw", {
timeout: 30000,
}, async () => {
const { isWebCryptoAvailable } = await import(
"../src/availability/availability.js"
);
expect(typeof isWebCryptoAvailable).toBe("function");
expect(isWebCryptoAvailable()).toBe(true);
});
it("importing only AEAD engine does not throw", {
timeout: 30000,
}, async () => {
const { webCryptoAeadEngine } = await import(
"../src/engines/webcrypto-aead-engine/webcrypto-aead-engine.js"
);
expect(typeof webCryptoAeadEngine.encrypt).toBe("function");
expect(typeof webCryptoAeadEngine.decrypt).toBe("function");
});
it("importing only errors does not throw", { timeout: 30000 }, async () => {
const { BrowserCryptoError, BROWSER_CRYPTO_CODES } = await import(
"../src/errors/index.js"
);
expect(BrowserCryptoError).toBeDefined();
expect(BROWSER_CRYPTO_CODES["NOT_AVAILABLE"]).toBe(
"BROWSER_CRYPTO.NOT_AVAILABLE"
);
});
it("barrel index exports all expected symbols", {
timeout: 30000,
}, async () => {
const mod = await import("../src/index.js");
expect(typeof mod.isWebCryptoAvailable).toBe("function");
expect(typeof mod.webCryptoAeadEngine).toBe("object");
expect(typeof mod.webCryptoSignEngine).toBe("object");
expect(typeof mod.webCryptoAgreeEngine).toBe("object");
expect(typeof mod.rsa).toBe("object");
expect(typeof mod.aesKw).toBe("object");
expect(typeof mod.ecdsaP384).toBe("object");
expect(typeof mod.ecdhP384).toBe("object");
expect(typeof mod.nonExtractableKey).toBe("function");
expect(mod.BrowserCryptoError).toBeDefined();
});
});