41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
|
|
describe("CLI module graph", () => {
|
|
test("does not resolve the Kubernetes client during CLI startup", () => {
|
|
const entry = join(import.meta.dir, "../../index.ts");
|
|
const probe = Bun.spawnSync([process.execPath, entry, "--help"], {
|
|
cwd: import.meta.dir,
|
|
env: process.env,
|
|
});
|
|
expect(probe.exitCode).toBe(0);
|
|
expect(new TextDecoder().decode(probe.stdout)).toContain("USAGE");
|
|
});
|
|
|
|
test("production build retains the passive updater's runtime environment guard", () => {
|
|
const root = join(import.meta.dir, "../..");
|
|
const { scripts } = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
const args = (scripts.build as string).split(/\s+/);
|
|
expect(args).toContain("--env");
|
|
expect(args[args.indexOf("--env") + 1]).toBe("disable");
|
|
|
|
const outdir = mkdtempSync(join(tmpdir(), "kuber-cli-build-"));
|
|
try {
|
|
args[args.indexOf("--outdir") + 1] = outdir;
|
|
const build = Bun.spawnSync(args, {
|
|
cwd: root,
|
|
env: { ...process.env, NODE_ENV: "production" },
|
|
});
|
|
expect(new TextDecoder().decode(build.stderr)).toBe("");
|
|
expect(build.exitCode).toBe(0);
|
|
const bundle = readFileSync(join(outdir, "index.js"), "utf8");
|
|
expect(bundle).toMatch(/process\.env\.NODE_ENV\s*===\s*["']test["']/);
|
|
expect(bundle).toMatch(/process\.env\.NODE_ENV\s*===\s*["']development["']/);
|
|
} finally {
|
|
rmSync(outdir, { recursive: true, force: true });
|
|
}
|
|
}, 20_000);
|
|
});
|