Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cool-pets-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: skip banner when using `--json` flag in `wrangler pages deployment` commands
58 changes: 57 additions & 1 deletion packages/wrangler/src/__tests__/pages/deployment-list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 () => {
Expand Down
Loading