57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
|
|
const PKG_ROOT = join(__dirname, "..");
|
|
const SRC_ROOT = join(PKG_ROOT, "src");
|
|
|
|
function walkTypescript(dir: string): string[] {
|
|
const entries = readdirSync(dir);
|
|
const files: string[] = [];
|
|
for (const entry of entries) {
|
|
const full = join(dir, entry);
|
|
const st = statSync(full);
|
|
if (st.isDirectory()) {
|
|
files.push(...walkTypescript(full));
|
|
} else if (
|
|
entry.endsWith(".ts") &&
|
|
!entry.endsWith(".test.ts") &&
|
|
!entry.endsWith(".spec.ts")
|
|
) {
|
|
files.push(full);
|
|
}
|
|
}
|
|
return files;
|
|
}
|
|
|
|
describe("universal dep graph", () => {
|
|
it("src contains no node/bun/fs/path/stream/net/http/crypto imports", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
const banned =
|
|
/from\s+['"](node:|bun:|fs|path|stream|net|http|crypto)['"]/;
|
|
const offenders: string[] = [];
|
|
for (const file of walkTypescript(SRC_ROOT)) {
|
|
const text = readFileSync(file, "utf8");
|
|
if (banned.test(text)) {
|
|
offenders.push(file);
|
|
}
|
|
}
|
|
expect(offenders).toEqual([]);
|
|
});
|
|
|
|
it("package.json exposes exactly the feature subpaths", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
const pkg = JSON.parse(
|
|
readFileSync(join(PKG_ROOT, "package.json"), "utf8")
|
|
) as { exports: Record<string, unknown> };
|
|
const featurePaths = Object.keys(pkg.exports).filter(
|
|
(k) => k.startsWith("./") && k !== "." && k !== "./package.json"
|
|
);
|
|
expect(featurePaths.sort()).toEqual(
|
|
["./adyen/adyen", "./types/adyen"].sort()
|
|
);
|
|
});
|
|
});
|