-
Notifications
You must be signed in to change notification settings - Fork 758
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
Implement versions list
+ versions view
commands
#5208
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c414dc8
move versions subcommand registration into versions directory
RamIdeas d9cc438
implement versions list command
RamIdeas 60523e1
refactor to use shared util
RamIdeas 043c1a1
implement versions view command
RamIdeas 8553916
add `versions view` tests
RamIdeas cb33b10
add `versions list` tests
RamIdeas 887f47a
remove unused imports
RamIdeas e6d37d5
only normalizeOutput in snapshot tests if necessary
RamIdeas 3c3d744
port Source display logic from legacy deployments command
RamIdeas efd3514
add changeset
RamIdeas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": minor | ||
--- | ||
|
||
feature: Implement `wrangler versions list` and `wrangler versions view` commands behind the `--experimental-gradual-rollouts` flag. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
packages/wrangler/src/__tests__/versions/versions.list.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { normalizeOutput } from "../../../e2e/helpers/normalize"; | ||
import { mockAccountId, mockApiToken } from "../helpers/mock-account-id"; | ||
import { mockConsoleMethods } from "../helpers/mock-console"; | ||
import { msw, mswListVersions } from "../helpers/msw"; | ||
import { runInTempDir } from "../helpers/run-in-tmp"; | ||
import { runWrangler } from "../helpers/run-wrangler"; | ||
import writeWranglerToml from "../helpers/write-wrangler-toml"; | ||
|
||
describe("versions list", () => { | ||
mockAccountId(); | ||
mockApiToken(); | ||
runInTempDir(); | ||
const std = mockConsoleMethods(); | ||
|
||
beforeEach(() => { | ||
msw.use(mswListVersions); | ||
}); | ||
|
||
describe("without wrangler.toml", () => { | ||
test("fails with no args", async () => { | ||
const result = runWrangler( | ||
"versions list --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).rejects.toMatchInlineSnapshot( | ||
`[Error: You need to provide a name when deploying a 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( | ||
`"X [ERROR] You need to provide a name when deploying a worker. Either pass it as a cli arg with \`--name <name>\` or in your config file as \`name = \\"<name>\\"\`"` | ||
); | ||
}); | ||
|
||
test("prints versions to stdout", async () => { | ||
const result = runWrangler( | ||
"versions list --name test-name --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).resolves.toBeUndefined(); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
"Version ID: 40000000-0000-0000-0000-000000000000 | ||
Created: 1/1/2021, 12:00:00 AM | ||
Author: Jean-Luc-Picard@federation.org | ||
Source: Upload | ||
Tag: - | ||
Message: - | ||
|
||
Version ID: 30000000-0000-0000-0000-000000000000 | ||
Created: 2/2/2021, 12:00:00 AM | ||
Author: Kathryn-Janeway@federation.org | ||
Source: Rollback | ||
Tag: - | ||
Message: Rolled back for this version | ||
|
||
Version ID: 20000000-0000-0000-0000-000000000000 | ||
Created: 2/3/2021, 12:00:00 AM | ||
Author: Kathryn-Janeway@federation.org | ||
Source: Wrangler 🤠 | ||
Tag: - | ||
Message: - | ||
|
||
Version ID: 10000000-0000-0000-0000-000000000000 | ||
Created: 1/4/2021, 12:00:00 AM | ||
Author: Jean-Luc-Picard@federation.org | ||
Source: Rollback | ||
Tag: - | ||
Message: - | ||
" | ||
`); | ||
|
||
expect(std.err).toMatchInlineSnapshot(`""`); | ||
}); | ||
}); | ||
|
||
describe("with wrangler.toml", () => { | ||
beforeEach(writeWranglerToml); | ||
|
||
test("prints versions to stdout", async () => { | ||
const result = runWrangler( | ||
"versions list --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).resolves.toBeUndefined(); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
"Version ID: 40000000-0000-0000-0000-000000000000 | ||
Created: 1/1/2021, 12:00:00 AM | ||
Author: Jean-Luc-Picard@federation.org | ||
Source: Upload | ||
Tag: - | ||
Message: - | ||
|
||
Version ID: 30000000-0000-0000-0000-000000000000 | ||
Created: 2/2/2021, 12:00:00 AM | ||
Author: Kathryn-Janeway@federation.org | ||
Source: Rollback | ||
Tag: - | ||
Message: Rolled back for this version | ||
|
||
Version ID: 20000000-0000-0000-0000-000000000000 | ||
Created: 2/3/2021, 12:00:00 AM | ||
Author: Kathryn-Janeway@federation.org | ||
Source: Wrangler 🤠 | ||
Tag: - | ||
Message: - | ||
|
||
Version ID: 10000000-0000-0000-0000-000000000000 | ||
Created: 1/4/2021, 12:00:00 AM | ||
Author: Jean-Luc-Picard@federation.org | ||
Source: Rollback | ||
Tag: - | ||
Message: - | ||
" | ||
`); | ||
|
||
expect(std.err).toMatchInlineSnapshot(`""`); | ||
}); | ||
}); | ||
}); |
200 changes: 200 additions & 0 deletions
200
packages/wrangler/src/__tests__/versions/versions.view.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
import { normalizeOutput } from "../../../e2e/helpers/normalize"; | ||
import { mockAccountId, mockApiToken } from "../helpers/mock-account-id"; | ||
import { mockConsoleMethods } from "../helpers/mock-console"; | ||
import { msw, mswGetVersion } from "../helpers/msw"; | ||
import { runInTempDir } from "../helpers/run-in-tmp"; | ||
import { runWrangler } from "../helpers/run-wrangler"; | ||
import writeWranglerToml from "../helpers/write-wrangler-toml"; | ||
|
||
describe("versions view", () => { | ||
mockAccountId(); | ||
mockApiToken(); | ||
runInTempDir(); | ||
const std = mockConsoleMethods(); | ||
|
||
beforeEach(() => { | ||
msw.use(mswGetVersion); | ||
}); | ||
|
||
describe("without wrangler.toml", () => { | ||
test("fails with no args", async () => { | ||
const result = runWrangler( | ||
"versions view --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).rejects.toMatchInlineSnapshot( | ||
`[Error: Not enough non-option arguments: got 0, need at least 1]` | ||
); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
" | ||
wrangler versions view <version-id> | ||
|
||
View the details of a specific version of your Worker [beta] | ||
|
||
Positionals: | ||
version-id The Worker Version ID to view [string] [required] | ||
|
||
Flags: | ||
-j, --experimental-json-config Experimental: Support wrangler.json [boolean] | ||
-c, --config Path to .toml configuration file [string] | ||
-e, --env Environment to use for operations and .env files [string] | ||
-h, --help Show help [boolean] | ||
-v, --version Show version number [boolean] | ||
|
||
Options: | ||
--name Name of the worker [string]" | ||
`); | ||
|
||
expect(normalizeOutput(std.err)).toMatchInlineSnapshot( | ||
`"X [ERROR] Not enough non-option arguments: got 0, need at least 1"` | ||
); | ||
}); | ||
|
||
test("fails with --name arg only", async () => { | ||
const result = runWrangler( | ||
"versions view --name test-name --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).rejects.toMatchInlineSnapshot( | ||
`[Error: Not enough non-option arguments: got 0, need at least 1]` | ||
); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
" | ||
wrangler versions view <version-id> | ||
|
||
View the details of a specific version of your Worker [beta] | ||
|
||
Positionals: | ||
version-id The Worker Version ID to view [string] [required] | ||
|
||
Flags: | ||
-j, --experimental-json-config Experimental: Support wrangler.json [boolean] | ||
-c, --config Path to .toml configuration file [string] | ||
-e, --env Environment to use for operations and .env files [string] | ||
-h, --help Show help [boolean] | ||
-v, --version Show version number [boolean] | ||
|
||
Options: | ||
--name Name of the worker [string]" | ||
`); | ||
|
||
expect(normalizeOutput(std.err)).toMatchInlineSnapshot( | ||
`"X [ERROR] Not enough non-option arguments: got 0, need at least 1"` | ||
); | ||
}); | ||
|
||
test("fails with positional version-id arg only", async () => { | ||
const result = runWrangler( | ||
"versions view 10000000-0000-0000-0000-000000000000 --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).rejects.toMatchInlineSnapshot( | ||
`[Error: You need to provide a name when deploying a 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( | ||
`"X [ERROR] You need to provide a name when deploying a worker. Either pass it as a cli arg with \`--name <name>\` or in your config file as \`name = \\"<name>\\"\`"` | ||
); | ||
}); | ||
|
||
test("succeeds with positional version-id arg and --name arg", async () => { | ||
const result = runWrangler( | ||
"versions view 10000000-0000-0000-0000-000000000000 --name test-name --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).resolves.toBeUndefined(); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
"Version ID: 10000000-0000-0000-0000-000000000000 | ||
Created: 1/1/2021, 12:00:00 AM | ||
Author: Jean-Luc-Picard@federation.org | ||
Source: Upload | ||
Tag: - | ||
Message: - | ||
" | ||
`); | ||
|
||
expect(normalizeOutput(std.err)).toMatchInlineSnapshot(`""`); | ||
}); | ||
}); | ||
|
||
describe("with wrangler.toml", () => { | ||
beforeEach(writeWranglerToml); | ||
|
||
test("fails with no args", async () => { | ||
const result = runWrangler( | ||
"versions view --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).rejects.toMatchInlineSnapshot( | ||
`[Error: Not enough non-option arguments: got 0, need at least 1]` | ||
); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
" | ||
wrangler versions view <version-id> | ||
|
||
View the details of a specific version of your Worker [beta] | ||
|
||
Positionals: | ||
version-id The Worker Version ID to view [string] [required] | ||
|
||
Flags: | ||
-j, --experimental-json-config Experimental: Support wrangler.json [boolean] | ||
-c, --config Path to .toml configuration file [string] | ||
-e, --env Environment to use for operations and .env files [string] | ||
-h, --help Show help [boolean] | ||
-v, --version Show version number [boolean] | ||
|
||
Options: | ||
--name Name of the worker [string]" | ||
`); | ||
|
||
expect(normalizeOutput(std.err)).toMatchInlineSnapshot( | ||
`"X [ERROR] Not enough non-option arguments: got 0, need at least 1"` | ||
); | ||
}); | ||
|
||
test("succeeds with positional version-id arg only", async () => { | ||
const result = runWrangler( | ||
"versions view 10000000-0000-0000-0000-000000000000 --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).resolves.toBeUndefined(); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
"Version ID: 10000000-0000-0000-0000-000000000000 | ||
Created: 1/1/2021, 12:00:00 AM | ||
Author: Jean-Luc-Picard@federation.org | ||
Source: Upload | ||
Tag: - | ||
Message: - | ||
" | ||
`); | ||
|
||
expect(normalizeOutput(std.err)).toMatchInlineSnapshot(`""`); | ||
}); | ||
|
||
test("fails with non-existent version-id", async () => { | ||
const result = runWrangler( | ||
"versions view ffffffff-ffff-ffff-ffff-ffffffffffff --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).rejects.toMatchInlineSnapshot( | ||
`[APIError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions/ffffffff-ffff-ffff-ffff-ffffffffffff) failed.]` | ||
); | ||
|
||
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(` | ||
"X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions/00000000-0000-0000-0000-000000000000) failed. | ||
If you think this is a bug, please open an issue at: | ||
https://github.com/cloudflare/workers-sdk/issues/new/choose" | ||
`); | ||
|
||
expect(normalizeOutput(std.err)).toMatchInlineSnapshot(`""`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this not be logged to stderr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. This is just the fetchResult call rejecting. Which should bubble up to the main() try..catch error handling. Does wrangler log errors to stdout??