Files
“mkczarkowski” f05ee31634 fix(windows-compatibility): normalize path separators in test assertions
Use path.join() instead of hardcoded forward slashes for path assertions
that compare absolute paths on Windows (backslash vs forward slash).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-09 15:33:02 +02:00

57 lines
1.8 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { join } from "node:path";
import { ExitCodes, resolveContext } from "../src/lib/output";
import { authFilePath, configDir } from "../src/lib/config";
import { DEFAULT_API_BASE, resolveApiBase } from "../src/lib/api-client";
describe("output", () => {
it("exposes semantic exit codes", () => {
expect(ExitCodes.SUCCESS).toBe(0);
expect(ExitCodes.AUTH_REQUIRED).toBe(3);
expect(ExitCodes.FORBIDDEN).toBe(4);
expect(ExitCodes.NOT_FOUND).toBe(5);
});
it("forces json mode when stdout is not a TTY", () => {
const ctx = resolveContext({ json: false });
// bun test pipes stdout, so isTTY is falsy — json mode should be implicit.
expect(ctx.json).toBe(true);
});
it("honors explicit --json flag", () => {
const ctx = resolveContext({ json: true });
expect(ctx.json).toBe(true);
});
});
describe("config paths", () => {
it("resolves a config directory under the user home", () => {
const dir = configDir();
expect(dir).toContain("10x-cli");
expect(authFilePath()).toBe(join(dir, "auth.json"));
});
});
describe("api client", () => {
it("defaults to the production workers.dev host", () => {
const prior = process.env["API_BASE_URL"];
delete process.env["API_BASE_URL"];
try {
expect(resolveApiBase()).toBe(DEFAULT_API_BASE);
} finally {
if (prior !== undefined) process.env["API_BASE_URL"] = prior;
}
});
it("honors API_BASE_URL override", () => {
const prior = process.env["API_BASE_URL"];
process.env["API_BASE_URL"] = "http://localhost:8787";
try {
expect(resolveApiBase()).toBe("http://localhost:8787");
} finally {
if (prior === undefined) delete process.env["API_BASE_URL"];
else process.env["API_BASE_URL"] = prior;
}
});
});