84 lines
2.5 KiB
TypeScript
84 lines
2.5 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
|
|
const PKG = resolve(__dirname, "..", "package.json");
|
|
const PACKAGE_JSON = JSON.parse(readFileSync(PKG, "utf8"));
|
|
|
|
const ALLOWED_RUNTIME_DEPS = new Set([
|
|
"@opentelemetry/api",
|
|
"@suaveplan/crypto-curve",
|
|
"@suaveplan/crypto-hash",
|
|
"@suaveplan/crypto-utils",
|
|
"@suaveplan/error",
|
|
"@suaveplan/types",
|
|
"tslib",
|
|
"zod",
|
|
]);
|
|
|
|
const REQUIRED_SUBPATHS = [
|
|
"./error-codes/error-codes",
|
|
"./constants/constants",
|
|
"./types/license",
|
|
"./codec/base32/base32",
|
|
"./codec/bitpack/bitpack",
|
|
"./codec/payload/payload",
|
|
"./codec/obfuscation/obfuscation",
|
|
"./time/time",
|
|
"./generate/generate",
|
|
"./validate/validate",
|
|
"./flags/flags",
|
|
"./manager/manager",
|
|
"./revocation/revocation-store/revocation-store",
|
|
"./otel/instruments",
|
|
"./schemas/schemas",
|
|
];
|
|
|
|
describe("dep-graph and subpath exports", () => {
|
|
it("dependencies match the universal allowlist", { timeout: 5000 }, () => {
|
|
const deps = Object.keys(
|
|
PACKAGE_JSON.dependencies as Record<string, string>
|
|
);
|
|
for (const dep of deps) {
|
|
expect(ALLOWED_RUNTIME_DEPS).toContain(dep);
|
|
}
|
|
// Every allowlisted dep with a runtime use must be present
|
|
for (const dep of ALLOWED_RUNTIME_DEPS) {
|
|
expect(deps).toContain(dep);
|
|
}
|
|
});
|
|
|
|
it("subpath exports cover every feature module", { timeout: 5000 }, () => {
|
|
const exports = PACKAGE_JSON.exports as Record<string, unknown>;
|
|
for (const subpath of REQUIRED_SUBPATHS) {
|
|
expect(exports).toHaveProperty(subpath);
|
|
}
|
|
expect(exports).toHaveProperty(".");
|
|
expect(exports).toHaveProperty("./package.json");
|
|
});
|
|
|
|
it("package is universal (no browser/Node-only deps)", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
const deps = Object.keys(
|
|
PACKAGE_JSON.dependencies as Record<string, string>
|
|
);
|
|
for (const dep of deps) {
|
|
expect(dep.startsWith("node:")).toBe(false);
|
|
expect(dep).not.toMatch(/^@?(react|vue|svelte|angular|expo)/);
|
|
}
|
|
});
|
|
|
|
it("sideEffects is false", { timeout: 5000 }, () => {
|
|
expect(PACKAGE_JSON.sideEffects).toBe(false);
|
|
});
|
|
|
|
it("type is module", { timeout: 5000 }, () => {
|
|
expect(PACKAGE_JSON.type).toBe("module");
|
|
});
|
|
|
|
it("version is 0.1.0", { timeout: 5000 }, () => {
|
|
expect(PACKAGE_JSON.version).toBe("0.1.0");
|
|
});
|
|
});
|