Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Versions deployments commands #5224

Merged
merged 14 commits into from
Mar 13, 2024
5 changes: 5 additions & 0 deletions .changeset/grumpy-ghosts-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

feature: Implement `wrangler deployments list` and `wrangler deployments status` behind `--experimental-gradual-rollouts` flag.
21 changes: 21 additions & 0 deletions packages/wrangler/src/__tests__/helpers/collect-cli-output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { stderr, stdout } from "@cloudflare/cli/streams";

export function collectCLIOutput() {
const std = { out: "", err: "" };
const onStdOutData = (chunk: Buffer) => (std.out += chunk.toString());
const onStdErrData = (chunk: Buffer) => (std.err += chunk.toString());

beforeEach(() => {
stdout.on("data", onStdOutData);
stderr.on("data", onStdErrData);
});

afterEach(() => {
stdout.off("data", onStdOutData);
stderr.off("data", onStdErrData);
std.out = "";
std.err = "";
});

return std;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import { normalizeOutput } from "../../../../e2e/helpers/normalize";
import { collectCLIOutput } from "../../helpers/collect-cli-output";
import { mockAccountId, mockApiToken } from "../../helpers/mock-account-id";
import { msw, mswGetVersion, mswListNewDeployments } from "../../helpers/msw";
import { runInTempDir } from "../../helpers/run-in-tmp";
import { runWrangler } from "../../helpers/run-wrangler";
import writeWranglerToml from "../../helpers/write-wrangler-toml";

describe("deployments list", () => {
mockAccountId();
mockApiToken();
runInTempDir();
const std = collectCLIOutput();

beforeEach(() => {
msw.use(mswListNewDeployments, mswGetVersion);
});

describe("without wrangler.toml", () => {
test("fails with no args", async () => {
const result = runWrangler(
"deployments list --experimental-gradual-rollouts"
);

await expect(result).rejects.toMatchInlineSnapshot(
`[Error: You need to provide a name of your worker. Either pass it as a cli arg with \`--name <name>\` or in your config file as \`name = "<name>"\`]`
);

expect(std.out).toMatchInlineSnapshot(`""`);

expect(normalizeOutput(std.err)).toMatchInlineSnapshot(`""`);
});

test("prints deployments to stdout", async () => {
const result = runWrangler(
"deployments list --name test-name --experimental-gradual-rollouts"
);

await expect(result).resolves.toBeUndefined();

expect(std.out).toMatchInlineSnapshot(`
"Created: 2021-01-04T00:00:00.000Z
Author: Jean-Luc-Picard@federation.org
Source: Rollback
Message: -
Version(s): (10%) 10000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(90%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
Created: 2021-01-01T00:00:00.000Z
Author: Jean-Luc-Picard@federation.org
Source: Upload
Message: -
Version(s): (20%) 10000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(80%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
Created: 2021-02-02T00:00:00.000Z
Author: Kathryn-Janeway@federation.org
Source: Rollback
Message: Rolled back for this version
Version(s): (30%) 10000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(70%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
Created: 2021-02-03T00:00:00.000Z
Author: Kathryn-Janeway@federation.org
Source: Wrangler 🤠
Message: -
Version(s): (40%) 10000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(60%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
"
`);

expect(std.err).toMatchInlineSnapshot(`""`);
});
});

describe("with wrangler.toml", () => {
beforeEach(writeWranglerToml);

test("prints deployments to stdout", async () => {
const result = runWrangler(
"deployments list --experimental-gradual-rollouts"
);

await expect(result).resolves.toBeUndefined();

expect(std.out).toMatchInlineSnapshot(`
"Created: 2021-01-04T00:00:00.000Z
Author: Jean-Luc-Picard@federation.org
Source: Rollback
Message: -
Version(s): (10%) 10000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(90%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
Created: 2021-01-01T00:00:00.000Z
Author: Jean-Luc-Picard@federation.org
Source: Upload
Message: -
Version(s): (20%) 10000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(80%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
Created: 2021-02-02T00:00:00.000Z
Author: Kathryn-Janeway@federation.org
Source: Rollback
Message: Rolled back for this version
Version(s): (30%) 10000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(70%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
Created: 2021-02-03T00:00:00.000Z
Author: Kathryn-Janeway@federation.org
Source: Wrangler 🤠
Message: -
Version(s): (40%) 10000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(60%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
"
`);

expect(std.err).toMatchInlineSnapshot(`""`);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { normalizeOutput } from "../../../../e2e/helpers/normalize";
import { collectCLIOutput } from "../../helpers/collect-cli-output";
import { mockAccountId, mockApiToken } from "../../helpers/mock-account-id";
import { msw, mswGetVersion, mswListNewDeployments } from "../../helpers/msw";
import { runInTempDir } from "../../helpers/run-in-tmp";
import { runWrangler } from "../../helpers/run-wrangler";
import writeWranglerToml from "../../helpers/write-wrangler-toml";

describe("deployments list", () => {
mockAccountId();
mockApiToken();
runInTempDir();
const std = collectCLIOutput();

beforeEach(() => {
msw.use(mswListNewDeployments, mswGetVersion);
});

describe("without wrangler.toml", () => {
test("fails with no args", async () => {
const result = runWrangler(
"deployments status --experimental-gradual-rollouts"
);

await expect(result).rejects.toMatchInlineSnapshot(
`[Error: You need to provide a name of your worker. Either pass it as a cli arg with \`--name <name>\` or in your config file as \`name = "<name>"\`]`
);

expect(std.out).toMatchInlineSnapshot(`""`);

expect(normalizeOutput(std.err)).toMatchInlineSnapshot(`""`);
});

test("prints latest deployment to stdout", async () => {
const result = runWrangler(
"deployments status --name test-name --experimental-gradual-rollouts"
);

await expect(result).resolves.toBeUndefined();

expect(std.out).toMatchInlineSnapshot(`
"Created: 2021-01-04T00:00:00.000Z
Author: Jean-Luc-Picard@federation.org
Source: Rollback
Message: -
Version(s): (10%) 10000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(90%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
"
`);

expect(std.err).toMatchInlineSnapshot(`""`);
});
});

describe("with wrangler.toml", () => {
beforeEach(writeWranglerToml);

test("prints latest deployment to stdout", async () => {
const result = runWrangler(
"deployments status --experimental-gradual-rollouts"
);

await expect(result).resolves.toBeUndefined();

expect(std.out).toMatchInlineSnapshot(`
"Created: 2021-01-04T00:00:00.000Z
Author: Jean-Luc-Picard@federation.org
Source: Rollback
Message: -
Version(s): (10%) 10000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(90%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
"
`);

expect(std.err).toMatchInlineSnapshot(`""`);
});
});
});
Loading
Loading