Initial Commit
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import { readdirSync, readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
|
||||
const PACKAGE_ROOT = join(__dirname, "..");
|
||||
|
||||
interface PackageJson {
|
||||
readonly name: string;
|
||||
readonly version: string;
|
||||
readonly dependencies?: Readonly<Record<string, string>>;
|
||||
readonly devDependencies?: Readonly<Record<string, string>>;
|
||||
readonly peerDependencies?: Readonly<Record<string, string>>;
|
||||
readonly sideEffects?: boolean;
|
||||
}
|
||||
|
||||
const pkg = JSON.parse(
|
||||
readFileSync(join(PACKAGE_ROOT, "package.json"), "utf8")
|
||||
) as PackageJson;
|
||||
|
||||
describe("package metadata", () => {
|
||||
it("name is @suaveplan/api-auth-provider", { timeout: 5000 }, () => {
|
||||
expect(pkg.name).toBe("@suaveplan/api-auth-provider");
|
||||
});
|
||||
it("version is 0.1.0 (genesis stage-1)", { timeout: 5000 }, () => {
|
||||
expect(pkg.version).toBe("0.1.0");
|
||||
});
|
||||
it("sideEffects is false", { timeout: 5000 }, () => {
|
||||
expect(pkg.sideEffects).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("dependencies", () => {
|
||||
it("depends on @suaveplan/api-types via workspace range", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
expect(pkg.dependencies?.["@suaveplan/api-types"]).toBe("workspace:^");
|
||||
});
|
||||
it("depends on @suaveplan/error via workspace range", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
expect(pkg.dependencies?.["@suaveplan/error"]).toBe("workspace:^");
|
||||
});
|
||||
it("depends on tslib via catalog:build", { timeout: 5000 }, () => {
|
||||
expect(pkg.dependencies?.tslib).toBe("catalog:build");
|
||||
});
|
||||
it("depends on zod via catalog:forms", { timeout: 5000 }, () => {
|
||||
expect(pkg.dependencies?.zod).toBe("catalog:forms");
|
||||
});
|
||||
});
|
||||
|
||||
function walkTsFiles(root: string): string[] {
|
||||
const out: string[] = [];
|
||||
for (const entry of readdirSync(root, { withFileTypes: true })) {
|
||||
const full = join(root, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
out.push(...walkTsFiles(full));
|
||||
} else if (entry.isFile() && entry.name.endsWith(".ts")) {
|
||||
out.push(full);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
describe("zod import form", () => {
|
||||
it("every src file uses default-import z", { timeout: 5000 }, () => {
|
||||
const files = walkTsFiles(join(PACKAGE_ROOT, "src"));
|
||||
const offenders: string[] = [];
|
||||
for (const file of files) {
|
||||
const text = readFileSync(file, "utf8");
|
||||
if (/from\s+['"]zod['"]/.test(text)) {
|
||||
if (!/import\s+z\s+from\s+['"]zod['"]/.test(text)) {
|
||||
offenders.push(file);
|
||||
}
|
||||
if (/import\s*\{\s*z\s*[,}]/.test(text)) {
|
||||
offenders.push(`${file} (named-import)`);
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("no static-analysis suppression comments", () => {
|
||||
it("no biome-ignore comments anywhere in src", { timeout: 5000 }, () => {
|
||||
const files = walkTsFiles(join(PACKAGE_ROOT, "src"));
|
||||
const offenders: string[] = [];
|
||||
for (const file of files) {
|
||||
const text = readFileSync(file, "utf8");
|
||||
if (
|
||||
/biome-ignore|eslint-disable|@ts-ignore|@ts-expect-error/.test(
|
||||
text
|
||||
)
|
||||
) {
|
||||
offenders.push(file);
|
||||
}
|
||||
}
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user