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