Initial Commit
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
|
||||
const pkgPath = join(__dirname, "..", "package.json");
|
||||
const pkg = JSON.parse(readFileSync(pkgPath, "utf8")) as {
|
||||
name: string;
|
||||
version: string;
|
||||
sideEffects: boolean;
|
||||
dependencies: Record<string, string>;
|
||||
devDependencies: Record<string, string>;
|
||||
exports: Record<string, unknown>;
|
||||
files: string[];
|
||||
};
|
||||
|
||||
describe("@suaveplan/emailer package.json", () => {
|
||||
it("starts at 0.1.0", { timeout: 5000 }, () => {
|
||||
expect(pkg.version).toBe("0.1.0");
|
||||
});
|
||||
|
||||
it("is tree-shake friendly", { timeout: 5000 }, () => {
|
||||
expect(pkg.sideEffects).toBe(false);
|
||||
});
|
||||
|
||||
it("depends on declared workspace siblings only", { timeout: 5000 }, () => {
|
||||
for (const dep of [
|
||||
"@suaveplan/error",
|
||||
"@suaveplan/events",
|
||||
"@suaveplan/logger",
|
||||
"@suaveplan/queue",
|
||||
"@suaveplan/timing",
|
||||
"@suaveplan/types",
|
||||
]) {
|
||||
expect(pkg.dependencies[dep]).toBe("workspace:^");
|
||||
}
|
||||
// No nodemailer / googleapis hard deps.
|
||||
expect(pkg.dependencies["nodemailer"]).toBeUndefined();
|
||||
expect(pkg.dependencies["googleapis"]).toBeUndefined();
|
||||
});
|
||||
|
||||
it("declares subpath exports", { timeout: 5000 }, () => {
|
||||
for (const subpath of [
|
||||
".",
|
||||
"./error-codes",
|
||||
"./schemas/schemas",
|
||||
"./types/emailer",
|
||||
"./core/email-service",
|
||||
"./core/retry",
|
||||
"./core/validate",
|
||||
"./transports/dummy",
|
||||
"./transports/smtp",
|
||||
"./transports/gmail-rest",
|
||||
"./fakes/fake-smtp-client",
|
||||
"./otel/metrics",
|
||||
]) {
|
||||
expect(pkg.exports[subpath]).toBeDefined();
|
||||
}
|
||||
});
|
||||
|
||||
it("publishes dist, src, README.md", { timeout: 5000 }, () => {
|
||||
expect(pkg.files).toEqual(["dist", "src", "README.md"]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
import { readdirSync, readFileSync, statSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
|
||||
const SRC = join(__dirname, "..", "src");
|
||||
|
||||
function walk(dir: string): string[] {
|
||||
const out: string[] = [];
|
||||
for (const entry of readdirSync(dir)) {
|
||||
const full = join(dir, entry);
|
||||
if (statSync(full).isDirectory()) {
|
||||
out.push(...walk(full));
|
||||
} else if (full.endsWith(".ts")) {
|
||||
out.push(full);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function find(
|
||||
pattern: RegExp,
|
||||
options: { includeTests?: boolean; onlyIndex?: boolean } = {}
|
||||
): string[] {
|
||||
const files = walk(SRC).filter((f) => {
|
||||
if (options.includeTests !== true && f.endsWith(".test.ts"))
|
||||
return false;
|
||||
if (options.onlyIndex === true && !f.endsWith("index.ts")) return false;
|
||||
return true;
|
||||
});
|
||||
const hits: string[] = [];
|
||||
for (const f of files) {
|
||||
const content = readFileSync(f, "utf8");
|
||||
const lines = content.split("\n");
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (pattern.test(lines[i]!)) {
|
||||
hits.push(`${f}:${i + 1}: ${lines[i]!.trim()}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hits;
|
||||
}
|
||||
|
||||
describe("emailer no-disallowed patterns", () => {
|
||||
it("no vi.mock / jest.mock", { timeout: 5000 }, () => {
|
||||
expect(find(/\b(vi|jest)\.mock\(/, { includeTests: true })).toEqual([]);
|
||||
});
|
||||
|
||||
it("no console.log in production src", { timeout: 5000 }, () => {
|
||||
expect(find(/console\.log\(/)).toEqual([]);
|
||||
});
|
||||
|
||||
it("no biome-ignore comments", { timeout: 5000 }, () => {
|
||||
expect(find(/biome-ignore/, { includeTests: true })).toEqual([]);
|
||||
});
|
||||
|
||||
it("no direct vitest / bun:test imports in test files", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
expect(
|
||||
find(/from ['"](vitest|bun:test)['"]/, { includeTests: true })
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it("no export * in non-root barrels", { timeout: 5000 }, () => {
|
||||
const hits = find(/^\s*export\s+(type\s+)?\*\s+from/, {
|
||||
onlyIndex: true,
|
||||
includeTests: true,
|
||||
}).filter((h) => !h.includes(`${SRC}/index.ts:`));
|
||||
expect(hits).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Reference in New Issue
Block a user