The root .gitignore's bare `dist` pattern matches at any depth, which was also silently excluding sdk/js/test/dist/ -- a real, hand-written test suite (cjs.dist.ts/esm.dist.ts/types.dist-d.ts/helpers.ts) that verifies the published package's actual compiled exports, not build output. `git log --all` shows zero commits ever touched this path: it has been untracked since the repo's initial commit, so a fresh clone (CI, another machine, a contributor) silently never had these tests. Un-ignore sdk/js/test/dist/ explicitly while leaving the real build output (sdk/js/dist/) ignored. Also fixed the EXPECTED_VALUE_EXPORTS list in helpers.ts, which had drifted from src/index.ts's deprecated OpenTypeSafeClient/OpenTypeSafeError aliases and was failing both dist tests the moment they actually ran. This also resolves the "biome: command not found" report from the 2026-11-09 npm publish --dry-run attempt: @biomejs/biome was already a correct devDependency, the real missing step was `npm install` (never run that session). Verified live: fresh npm install + npm run check (lint/typecheck/test:coverage/build/test:dist/check:package) + npm publish --dry-run all pass clean end to end now. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
60 lines
2.2 KiB
TypeScript
60 lines
2.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import * as sdk from "../../dist/index.mjs";
|
|
import { BASE_URL, cannedFetch, EXPECTED_VALUE_EXPORTS, pkg, SYSTEM_ONE_BODY } from "./helpers";
|
|
|
|
describe("dist/index.mjs (ESM build)", () => {
|
|
it("exposes exactly the documented value exports", () => {
|
|
expect(Object.keys(sdk).sort()).toEqual(EXPECTED_VALUE_EXPORTS);
|
|
});
|
|
|
|
it("reports the package.json version", () => {
|
|
expect(sdk.VERSION).toBe(pkg.version);
|
|
});
|
|
|
|
it("makes a typed round trip through the bundle", async () => {
|
|
const { fetch, calls } = cannedFetch(SYSTEM_ONE_BODY);
|
|
const client = new sdk.TypeSafeClient({
|
|
apiKey: "k",
|
|
baseURL: BASE_URL,
|
|
fetch,
|
|
retry: { maxRetries: 0 },
|
|
});
|
|
const { data, requestId } = await client
|
|
.systemOne({
|
|
state: "hi",
|
|
questions: { ok: sdk.noul("ok?"), tone: sdk.choice("tone?", { warm: null, cold: null }) },
|
|
})
|
|
.withResponse();
|
|
|
|
expect(requestId).toBe("req_dist");
|
|
expect(data.answers.ok.noul).toBe(0.9);
|
|
expect(data.answers.tone.choice).toBe("warm");
|
|
expect(calls[0]?.url).toBe(`${BASE_URL}/v1/systemone`);
|
|
const headers = calls[0]?.init?.headers as Record<string, string>;
|
|
expect(headers["X-OpenJev-SDK"]).toBe(`openjev-sdk/${pkg.version}`);
|
|
expect(headers["X-TypeSafe-SDK"]).toBe(`openjev-sdk/${pkg.version}`); // back-compat
|
|
});
|
|
|
|
it("throws the bundle's own error classes", async () => {
|
|
const fetch = async () => new Response("{}", { status: 429, headers: { "retry-after": "1" } });
|
|
const client = new sdk.TypeSafeClient({
|
|
apiKey: "k",
|
|
baseURL: BASE_URL,
|
|
fetch,
|
|
retry: { maxRetries: 0 },
|
|
});
|
|
const err = await client.models.list().catch((e: unknown) => e);
|
|
expect(err).toBeInstanceOf(sdk.RateLimitError);
|
|
expect(err).toBeInstanceOf(sdk.APIError);
|
|
expect(err).toBeInstanceOf(sdk.TypeSafeError);
|
|
expect((err as sdk.RateLimitError).retryAfterMs).toBe(1000);
|
|
});
|
|
|
|
it("does not pull in Node built-ins", async () => {
|
|
const { readFileSync } = await import("node:fs");
|
|
const source = readFileSync(new URL("../../dist/index.mjs", import.meta.url), "utf8");
|
|
expect(source).not.toMatch(/from\s+["']node:/);
|
|
expect(source).not.toMatch(/require\(["']node:/);
|
|
});
|
|
});
|