|
| 1 | +import { mockConsoleMethods } from "./helpers/mock-console"; |
| 2 | +import { useMockIsTTY } from "./helpers/mock-istty"; |
| 3 | +import { runInTempDir } from "./helpers/run-in-tmp"; |
| 4 | +import { runWrangler } from "./helpers/run-wrangler"; |
| 5 | +import writeWranglerToml from "./helpers/write-wrangler-toml"; |
| 6 | + |
| 7 | +const ENV_COPY = process.env; |
| 8 | +mockConsoleMethods(); |
| 9 | +runInTempDir(); |
| 10 | + |
| 11 | +afterEach(() => { |
| 12 | + process.env = ENV_COPY; |
| 13 | +}); |
| 14 | + |
| 15 | +describe("CI", () => { |
| 16 | + const { setIsTTY } = useMockIsTTY(); |
| 17 | + setIsTTY(false); |
| 18 | + |
| 19 | + it("should not throw an error in CI if 'CLOUDFLARE_API_TOKEN' & 'account_id' are in scope", async () => { |
| 20 | + writeWranglerToml({ |
| 21 | + account_id: "IG-88", |
| 22 | + }); |
| 23 | + |
| 24 | + process.env = { |
| 25 | + CLOUDFLARE_API_TOKEN: "123456789", |
| 26 | + }; |
| 27 | + |
| 28 | + await runWrangler().catch((err) => { |
| 29 | + expect(err).toMatchInlineSnapshot(`""`); |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should not throw an error if 'CLOUDFLARE_ACCOUNT_ID' & 'CLOUDFLARE_API_TOKEN' are in scope", async () => { |
| 34 | + process.env = { |
| 35 | + CLOUDFLARE_API_TOKEN: "hunter2", |
| 36 | + CLOUDFLARE_ACCOUNT_ID: "IG-88", |
| 37 | + }; |
| 38 | + |
| 39 | + await runWrangler().catch((err) => { |
| 40 | + expect(err).toMatchInlineSnapshot(`""`); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should throw an error in CI if 'account_id' & 'CLOUDFLARE_ACCOUNT_ID' is missing", async () => { |
| 45 | + writeWranglerToml({ |
| 46 | + account_id: undefined, |
| 47 | + }); |
| 48 | + |
| 49 | + process.env = { |
| 50 | + CLOUDFLARE_API_TOKEN: "hunter2", |
| 51 | + CLOUDFLARE_ACCOUNT_ID: undefined, |
| 52 | + }; |
| 53 | + |
| 54 | + await runWrangler().catch((err) => { |
| 55 | + expect(err).toMatchInlineSnapshot( |
| 56 | + `[Error: Missing "account_id" from "wrangler.toml" and "CLOUDFLARE_ACCOUNT_ID" from CI environment, one is required, please see docs for more info: TBD]` |
| 57 | + ); |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + it("should throw error in CI if 'CLOUDFLARE_API_TOKEN' is missing", async () => { |
| 62 | + writeWranglerToml({ |
| 63 | + account_id: undefined, |
| 64 | + }); |
| 65 | + |
| 66 | + process.env = { |
| 67 | + CLOUDFLARE_API_TOKEN: undefined, |
| 68 | + CLOUDFLARE_ACCOUNT_ID: "badwolf", |
| 69 | + }; |
| 70 | + await runWrangler().catch((err) => { |
| 71 | + expect(err).toMatchInlineSnapshot( |
| 72 | + `[Error: Missing "CLOUDFLARE_API_TOKEN" from CI environment, please see docs for more info: TBD]` |
| 73 | + ); |
| 74 | + }); |
| 75 | + }); |
| 76 | + |
| 77 | + it("should throw errors in CI if 'CLOUDFLARE_API_TOKEN', 'account_id' & 'CLOUDFLARE_ACCOUNT_ID is missing", async () => { |
| 78 | + await runWrangler().catch((err) => { |
| 79 | + expect(err).toMatchInlineSnapshot( |
| 80 | + `[Error: Missing "account_id" from "wrangler.toml" and "CLOUDFLARE_ACCOUNT_ID" "CLOUDFLARE_API_TOKEN" from CI environment, please see docs for more info: TBD]` |
| 81 | + ); |
| 82 | + }); |
| 83 | + }); |
| 84 | +}); |
0 commit comments