|
| 1 | +import { experimental_AstroContainer as AstroContainer } from "astro/container"; |
| 2 | +import { expect, test, describe } from "vitest"; |
| 3 | +import WranglerCLI from "./WranglerCLI.astro"; |
| 4 | + |
| 5 | +type Options = Parameters<(typeof container)["renderToString"]>[1]; |
| 6 | + |
| 7 | +const container = await AstroContainer.create(); |
| 8 | + |
| 9 | +const renderWithOptions = (options?: Options) => { |
| 10 | + return container.renderToString(WranglerCLI, options); |
| 11 | +}; |
| 12 | + |
| 13 | +describe("WranglerCLI", () => { |
| 14 | + test("succeeds with valid input", async () => { |
| 15 | + await expect( |
| 16 | + renderWithOptions({ |
| 17 | + props: { |
| 18 | + command: "deploy", |
| 19 | + }, |
| 20 | + }), |
| 21 | + ).resolves.toContain("pnpm wrangler deploy"); |
| 22 | + }); |
| 23 | + |
| 24 | + test("errors with no props", async () => { |
| 25 | + await expect(renderWithOptions()).rejects |
| 26 | + .toThrowErrorMatchingInlineSnapshot(` |
| 27 | + [ZodError: [ |
| 28 | + { |
| 29 | + "code": "invalid_type", |
| 30 | + "expected": "string", |
| 31 | + "received": "undefined", |
| 32 | + "path": [ |
| 33 | + "command" |
| 34 | + ], |
| 35 | + "message": "Required" |
| 36 | + } |
| 37 | + ]] |
| 38 | + `); |
| 39 | + }); |
| 40 | + |
| 41 | + test("errors with non-existent command", async () => { |
| 42 | + await expect( |
| 43 | + renderWithOptions({ |
| 44 | + props: { |
| 45 | + command: "not-a-valid-command", |
| 46 | + }, |
| 47 | + }), |
| 48 | + ).rejects.toThrowErrorMatchingInlineSnapshot( |
| 49 | + `[Error: [wrangler.ts] Command "not-a-valid-command" not found]`, |
| 50 | + ); |
| 51 | + }); |
| 52 | + |
| 53 | + test("errors with bad flags for 'deploy'", async () => { |
| 54 | + await expect( |
| 55 | + renderWithOptions({ |
| 56 | + props: { |
| 57 | + command: "deploy", |
| 58 | + flags: { |
| 59 | + foo: "bar", |
| 60 | + }, |
| 61 | + }, |
| 62 | + }), |
| 63 | + ).rejects.toThrowErrorMatchingInlineSnapshot( |
| 64 | + `[Error: [WranglerCLI] Received "foo" for "deploy" but no such arg exists]`, |
| 65 | + ); |
| 66 | + }); |
| 67 | + |
| 68 | + test("errors with bad value for 'container-rollout' flag", async () => { |
| 69 | + await expect( |
| 70 | + renderWithOptions({ |
| 71 | + props: { |
| 72 | + command: "deploy", |
| 73 | + flags: { |
| 74 | + "containers-rollout": "not-a-valid-option", |
| 75 | + }, |
| 76 | + }, |
| 77 | + }), |
| 78 | + ).rejects.toThrowErrorMatchingInlineSnapshot( |
| 79 | + `[Error: [WranglerCLI] Expected "immediate,gradual" for "containers-rollout" but got "string"]`, |
| 80 | + ); |
| 81 | + }); |
| 82 | +}); |
0 commit comments