Skip to content

Commit

Permalink
Versions deployments commands (#5224)
Browse files Browse the repository at this point in the history
  • Loading branch information
RamIdeas committed Mar 13, 2024
1 parent 4730b6c commit 03484c2
Show file tree
Hide file tree
Showing 18 changed files with 993 additions and 443 deletions.
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(`""`);
});
});
});

0 comments on commit 03484c2

Please sign in to comment.