Files
llmx/codex-cli/tests/api-key.test.ts
Ilan Bigio 59a180ddec Initial commit
Signed-off-by: Ilan Bigio <ilan@openai.com>
2025-04-16 12:56:08 -04:00

36 lines
987 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, it, expect, beforeEach, afterEach } from "vitest";
// We import the module *lazily* inside each test so that we can control the
// OPENAI_API_KEY env var independently per test case. Node's module cache
// would otherwise capture the value present during the first import.
const ORIGINAL_ENV_KEY = process.env["OPENAI_API_KEY"];
beforeEach(() => {
delete process.env["OPENAI_API_KEY"];
});
afterEach(() => {
if (ORIGINAL_ENV_KEY !== undefined) {
process.env["OPENAI_API_KEY"] = ORIGINAL_ENV_KEY;
} else {
delete process.env["OPENAI_API_KEY"];
}
});
describe("config.setApiKey", () => {
it("overrides the exported OPENAI_API_KEY at runtime", async () => {
const { setApiKey, OPENAI_API_KEY } = await import(
"../src/utils/config.js"
);
expect(OPENAI_API_KEY).toBe("");
setApiKey("mykey");
const { OPENAI_API_KEY: liveRef } = await import("../src/utils/config.js");
expect(liveRef).toBe("mykey");
});
});