From 3ca9c0e4d669ca0433ba79e9fff20a3ff9e8037a Mon Sep 17 00:00:00 2001 From: Edmund Hung Date: Wed, 1 Oct 2025 13:43:39 +0100 Subject: [PATCH] fix(wrangler): wrangler pages deployment list --json should skip the banner --- .changeset/cool-pets-notice.md | 5 ++ .../__tests__/pages/deployment-list.test.ts | 58 ++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 .changeset/cool-pets-notice.md diff --git a/.changeset/cool-pets-notice.md b/.changeset/cool-pets-notice.md new file mode 100644 index 00000000000..4900171c866 --- /dev/null +++ b/.changeset/cool-pets-notice.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +fix: skip banner when using `--json` flag in `wrangler pages deployment` commands diff --git a/packages/wrangler/src/__tests__/pages/deployment-list.test.ts b/packages/wrangler/src/__tests__/pages/deployment-list.test.ts index 8d86f743288..5691147c392 100644 --- a/packages/wrangler/src/__tests__/pages/deployment-list.test.ts +++ b/packages/wrangler/src/__tests__/pages/deployment-list.test.ts @@ -8,10 +8,11 @@ import { runWrangler } from "./../helpers/run-wrangler"; import type { Deployment } from "./../../pages/types"; describe("pages deployment list", () => { + vi.unmock("../../wrangler-banner"); runInTempDir(); mockAccountId(); mockApiToken(); - mockConsoleMethods(); + const std = mockConsoleMethods(); afterEach(async () => { // Force a tick to ensure that all promises resolve @@ -46,6 +47,61 @@ describe("pages deployment list", () => { await runWrangler("pages deployment list --project-name=images"); expect(requests.count).toBe(1); + expect(std.out).toMatchInlineSnapshot(` + " + ⛅️ wrangler x.x.x + ────────────────── + ┌─┬─┬─┬─┬─┬─┬─┐ + │ Id │ Environment │ Branch │ Source │ Deployment │ Status │ Build │ + ├─┼─┼─┼─┼─┼─┼─┤ + │ 87bbc8fe-16be-45cd-81e0-63d722e82cdf │ Preview │ main │ c764936 │ https://87bbc8fe.images.pages.dev │ 3 years ago │ https://dash.cloudflare.com/some-account-id/pages/view/images/87bbc8fe-16be-45cd-81e0-63d722e82cdf │ + └─┴─┴─┴─┴─┴─┴─┘" + `); + }); + + it("should make request to list deployments and return result as json", async () => { + const deployments: Deployment[] = [ + { + id: "87bbc8fe-16be-45cd-81e0-63d722e82cdf", + url: "https://87bbc8fe.images.pages.dev", + environment: "preview", + created_on: "2021-11-17T14:52:26.133835Z", + latest_stage: { + ended_on: "2021-11-17T14:52:26.133835Z", + status: "success", + }, + deployment_trigger: { + metadata: { + branch: "main", + commit_hash: "c7649364c4cb32ad4f65b530b9424e8be5bec9d6", + }, + }, + project_name: "images", + }, + ]; + + const requests = mockDeploymentListRequest(deployments); + await runWrangler("pages deployment list --project-name=images --json"); + + expect(requests.count).toBe(1); + const output = JSON.parse(std.out); + + expect(output[0].Status).toBeTypeOf("string"); + output[0].Status = "SNAPSHOT_VALUE"; // This value would drift from snapshot if not hardcoded as is + + expect(JSON.stringify(output, null, 2)).toMatchInlineSnapshot(` + "[ + { + \\"Id\\": \\"87bbc8fe-16be-45cd-81e0-63d722e82cdf\\", + \\"Environment\\": \\"Preview\\", + \\"Branch\\": \\"main\\", + \\"Source\\": \\"c764936\\", + \\"Deployment\\": \\"https://87bbc8fe.images.pages.dev\\", + \\"Status\\": \\"SNAPSHOT_VALUE\\", + \\"Build\\": \\"https://dash.cloudflare.com/some-account-id/pages/view/images/87bbc8fe-16be-45cd-81e0-63d722e82cdf\\" + } + ]" + `); }); it("should pass no environment", async () => {