wrangler 0.0.0-e3cab74 → 0.0.0-e452a35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cloudflare_CA.pem +18 -0
- package/README.md +27 -14
- package/bin/wrangler.js +49 -5
- package/miniflare-dist/index.mjs +4886 -0
- package/package.json +42 -28
- package/pages/functions/buildPlugin.ts +105 -0
- package/pages/functions/buildWorker.ts +93 -4
- package/pages/functions/filepath-routing.test.ts +136 -25
- package/pages/functions/filepath-routing.ts +14 -3
- package/pages/functions/routes.ts +6 -1
- package/pages/functions/template-plugin.ts +147 -0
- package/pages/functions/template-worker.ts +21 -8
- package/src/__tests__/config-cache.test.ts +36 -0
- package/src/__tests__/configuration.test.ts +1514 -367
- package/src/__tests__/dev.test.tsx +870 -84
- package/src/__tests__/guess-worker-format.test.ts +37 -18
- package/src/__tests__/helpers/mock-account-id.ts +22 -4
- package/src/__tests__/helpers/mock-cfetch.ts +8 -4
- package/src/__tests__/helpers/mock-console.ts +35 -10
- package/src/__tests__/helpers/mock-dialogs.ts +26 -1
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +27 -0
- package/src/__tests__/helpers/mock-kv.ts +9 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
- package/src/__tests__/helpers/mock-stdin.ts +103 -0
- package/src/__tests__/helpers/run-in-tmp.ts +10 -0
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/https-options.test.ts +130 -0
- package/src/__tests__/index.test.ts +137 -747
- package/src/__tests__/init.test.ts +1557 -0
- package/src/__tests__/jest.setup.ts +28 -8
- package/src/__tests__/kv.test.ts +598 -258
- package/src/__tests__/logger.test.ts +115 -0
- package/src/__tests__/pages.test.ts +657 -0
- package/src/__tests__/parse.test.ts +8 -0
- package/src/__tests__/publish.test.ts +4003 -941
- package/src/__tests__/r2.test.ts +69 -34
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +228 -73
- package/src/__tests__/tail.test.ts +146 -20
- package/src/__tests__/user.test.ts +131 -0
- package/src/__tests__/whoami.test.tsx +26 -7
- package/src/abort.d.ts +3 -0
- package/src/bundle.ts +74 -7
- package/src/cfetch/index.ts +21 -4
- package/src/cfetch/internal.ts +20 -14
- package/src/cli.ts +5 -11
- package/src/config/README.md +7 -7
- package/src/config/config.ts +69 -100
- package/src/config/environment.ts +119 -4
- package/src/config/index.ts +177 -4
- package/src/config/validation-helpers.ts +228 -23
- package/src/config/validation.ts +687 -174
- package/src/config-cache.ts +45 -0
- package/src/{api/preview.ts → create-worker-preview.ts} +74 -36
- package/src/{api/form_data.ts → create-worker-upload-form.ts} +55 -18
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +422 -0
- package/src/dev/local.tsx +318 -0
- package/src/dev/remote.tsx +227 -0
- package/src/dev/use-esbuild.ts +118 -0
- package/src/dialogs.tsx +16 -6
- package/src/durable.ts +102 -0
- package/src/entry.ts +279 -14
- package/src/environment-variables.ts +3 -1
- package/src/errors.ts +11 -0
- package/src/https-options.ts +123 -0
- package/src/index.tsx +1268 -806
- package/src/inspect.ts +64 -11
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv.tsx → kv.ts} +195 -62
- package/src/logger.ts +66 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +41 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +94 -6
- package/src/open-in-browser.ts +9 -3
- package/src/package-manager.ts +9 -8
- package/src/pages.tsx +1057 -75
- package/src/parse.ts +24 -5
- package/src/proxy.ts +143 -54
- package/src/publish.ts +444 -229
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +98 -44
- package/src/tail/index.ts +2 -2
- package/src/tail/printing.ts +13 -8
- package/src/update-check.ts +19 -0
- package/src/user.tsx +263 -109
- package/src/whoami.tsx +2 -1
- package/src/{api/worker.ts → worker.ts} +24 -30
- package/templates/gitignore +171 -0
- package/templates/new-worker.ts +16 -1
- package/templates/static-asset-facade.js +1 -1
- package/wrangler-dist/cli.js +55345 -69246
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/__tests__/logout.test.ts +0 -50
- package/src/__tests__/sentry.test.ts +0 -146
- package/src/dev.tsx +0 -961
- package/src/guess-worker-format.ts +0 -68
- package/src/reporting.ts +0 -115
- package/wrangler-dist/cli.js.map +0 -7
package/src/__tests__/r2.test.ts
CHANGED
|
@@ -17,6 +17,33 @@ describe("wrangler", () => {
|
|
|
17
17
|
|
|
18
18
|
describe("r2", () => {
|
|
19
19
|
describe("bucket", () => {
|
|
20
|
+
it("should show the correct help when an invalid command is passed", async () => {
|
|
21
|
+
await expect(() =>
|
|
22
|
+
runWrangler("r2 bucket foo")
|
|
23
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`"Unknown argument: foo"`);
|
|
24
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
25
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mUnknown argument: foo[0m
|
|
26
|
+
|
|
27
|
+
"
|
|
28
|
+
`);
|
|
29
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
30
|
+
"
|
|
31
|
+
wrangler r2 bucket
|
|
32
|
+
|
|
33
|
+
Manage R2 buckets
|
|
34
|
+
|
|
35
|
+
Commands:
|
|
36
|
+
wrangler r2 bucket create <name> Create a new R2 bucket
|
|
37
|
+
wrangler r2 bucket list List R2 buckets
|
|
38
|
+
wrangler r2 bucket delete <name> Delete an R2 bucket
|
|
39
|
+
|
|
40
|
+
Flags:
|
|
41
|
+
-c, --config Path to .toml configuration file [string]
|
|
42
|
+
-h, --help Show help [boolean]
|
|
43
|
+
-v, --version Show version number [boolean]"
|
|
44
|
+
`);
|
|
45
|
+
});
|
|
46
|
+
|
|
20
47
|
describe("list", () => {
|
|
21
48
|
function mockListRequest(buckets: R2BucketInfo[]) {
|
|
22
49
|
const requests = { count: 0 };
|
|
@@ -67,9 +94,9 @@ describe("wrangler", () => {
|
|
|
67
94
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
68
95
|
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
69
96
|
);
|
|
70
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
71
|
-
|
|
72
|
-
|
|
97
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
98
|
+
"
|
|
99
|
+
wrangler r2 bucket create <name>
|
|
73
100
|
|
|
74
101
|
Create a new R2 bucket
|
|
75
102
|
|
|
@@ -77,12 +104,14 @@ describe("wrangler", () => {
|
|
|
77
104
|
name The name of the new bucket [string] [required]
|
|
78
105
|
|
|
79
106
|
Flags:
|
|
80
|
-
-c, --config
|
|
81
|
-
-h, --help
|
|
82
|
-
-v, --version
|
|
83
|
-
|
|
107
|
+
-c, --config Path to .toml configuration file [string]
|
|
108
|
+
-h, --help Show help [boolean]
|
|
109
|
+
-v, --version Show version number [boolean]"
|
|
110
|
+
`);
|
|
111
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
112
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
84
113
|
|
|
85
|
-
|
|
114
|
+
"
|
|
86
115
|
`);
|
|
87
116
|
});
|
|
88
117
|
|
|
@@ -90,11 +119,11 @@ describe("wrangler", () => {
|
|
|
90
119
|
await expect(
|
|
91
120
|
runWrangler("r2 bucket create abc def ghi")
|
|
92
121
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
93
|
-
`"
|
|
122
|
+
`"Unknown arguments: def, ghi"`
|
|
94
123
|
);
|
|
95
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
96
|
-
|
|
97
|
-
|
|
124
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
125
|
+
"
|
|
126
|
+
wrangler r2 bucket create <name>
|
|
98
127
|
|
|
99
128
|
Create a new R2 bucket
|
|
100
129
|
|
|
@@ -102,12 +131,14 @@ describe("wrangler", () => {
|
|
|
102
131
|
name The name of the new bucket [string] [required]
|
|
103
132
|
|
|
104
133
|
Flags:
|
|
105
|
-
-c, --config
|
|
106
|
-
-h, --help
|
|
107
|
-
-v, --version
|
|
108
|
-
|
|
134
|
+
-c, --config Path to .toml configuration file [string]
|
|
135
|
+
-h, --help Show help [boolean]
|
|
136
|
+
-v, --version Show version number [boolean]"
|
|
137
|
+
`);
|
|
138
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
139
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mUnknown arguments: def, ghi[0m
|
|
109
140
|
|
|
110
|
-
|
|
141
|
+
"
|
|
111
142
|
`);
|
|
112
143
|
});
|
|
113
144
|
|
|
@@ -143,9 +174,9 @@ describe("wrangler", () => {
|
|
|
143
174
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
144
175
|
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
145
176
|
);
|
|
146
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
147
|
-
|
|
148
|
-
|
|
177
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
178
|
+
"
|
|
179
|
+
wrangler r2 bucket delete <name>
|
|
149
180
|
|
|
150
181
|
Delete an R2 bucket
|
|
151
182
|
|
|
@@ -153,12 +184,14 @@ describe("wrangler", () => {
|
|
|
153
184
|
name The name of the bucket to delete [string] [required]
|
|
154
185
|
|
|
155
186
|
Flags:
|
|
156
|
-
-c, --config
|
|
157
|
-
-h, --help
|
|
158
|
-
-v, --version
|
|
159
|
-
|
|
187
|
+
-c, --config Path to .toml configuration file [string]
|
|
188
|
+
-h, --help Show help [boolean]
|
|
189
|
+
-v, --version Show version number [boolean]"
|
|
190
|
+
`);
|
|
191
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
192
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
160
193
|
|
|
161
|
-
|
|
194
|
+
"
|
|
162
195
|
`);
|
|
163
196
|
});
|
|
164
197
|
|
|
@@ -166,11 +199,11 @@ describe("wrangler", () => {
|
|
|
166
199
|
await expect(
|
|
167
200
|
runWrangler("r2 bucket delete abc def ghi")
|
|
168
201
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
169
|
-
`"
|
|
202
|
+
`"Unknown arguments: def, ghi"`
|
|
170
203
|
);
|
|
171
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
172
|
-
|
|
173
|
-
|
|
204
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
205
|
+
"
|
|
206
|
+
wrangler r2 bucket delete <name>
|
|
174
207
|
|
|
175
208
|
Delete an R2 bucket
|
|
176
209
|
|
|
@@ -178,12 +211,14 @@ describe("wrangler", () => {
|
|
|
178
211
|
name The name of the bucket to delete [string] [required]
|
|
179
212
|
|
|
180
213
|
Flags:
|
|
181
|
-
-c, --config
|
|
182
|
-
-h, --help
|
|
183
|
-
-v, --version
|
|
184
|
-
|
|
214
|
+
-c, --config Path to .toml configuration file [string]
|
|
215
|
+
-h, --help Show help [boolean]
|
|
216
|
+
-v, --version Show version number [boolean]"
|
|
217
|
+
`);
|
|
218
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
219
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mUnknown arguments: def, ghi[0m
|
|
185
220
|
|
|
186
|
-
|
|
221
|
+
"
|
|
187
222
|
`);
|
|
188
223
|
});
|
|
189
224
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
2
|
+
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
3
|
+
import { runWrangler } from "./helpers/run-wrangler";
|
|
4
|
+
|
|
5
|
+
describe("wrangler route", () => {
|
|
6
|
+
mockConsoleMethods();
|
|
7
|
+
runInTempDir();
|
|
8
|
+
|
|
9
|
+
it("shows a deprecation notice when `wrangler route` is run", async () => {
|
|
10
|
+
await expect(runWrangler("route")).rejects
|
|
11
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
12
|
+
"Deprecation:
|
|
13
|
+
\`wrangler route\` has been deprecated.
|
|
14
|
+
Please use wrangler.toml and/or \`wrangler publish --routes\` to modify routes"
|
|
15
|
+
`);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("shows a deprecation notice when `wrangler route delete` is run", async () => {
|
|
19
|
+
await expect(runWrangler("route delete")).rejects
|
|
20
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
21
|
+
"Deprecation:
|
|
22
|
+
\`wrangler route delete\` has been deprecated.
|
|
23
|
+
Remove the unwanted route(s) from wrangler.toml and run \`wrangler publish\` to remove your worker from those routes."
|
|
24
|
+
`);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("shows a deprecation notice when `wrangler route delete <id>` is run", async () => {
|
|
28
|
+
await expect(runWrangler("route delete some-zone-id")).rejects
|
|
29
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
30
|
+
"Deprecation:
|
|
31
|
+
\`wrangler route delete\` has been deprecated.
|
|
32
|
+
Remove the unwanted route(s) from wrangler.toml and run \`wrangler publish\` to remove your worker from those routes."
|
|
33
|
+
`);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("shows a deprecation notice when `wrangler route list` is run", async () => {
|
|
37
|
+
await expect(runWrangler("route list")).rejects
|
|
38
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
39
|
+
"Deprecation:
|
|
40
|
+
\`wrangler route list\` has been deprecated.
|
|
41
|
+
Refer to wrangler.toml for a list of routes the worker will be deployed to upon publishing.
|
|
42
|
+
Refer to the Cloudflare Dashboard to see the routes this worker is currently running on."
|
|
43
|
+
`);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -1,18 +1,31 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as TOML from "@iarna/toml";
|
|
1
3
|
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
2
4
|
import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
|
|
3
5
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
4
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
mockConfirm,
|
|
8
|
+
mockPrompt,
|
|
9
|
+
clearConfirmMocks,
|
|
10
|
+
clearPromptMocks,
|
|
11
|
+
} from "./helpers/mock-dialogs";
|
|
12
|
+
import { mockOAuthFlow } from "./helpers/mock-oauth-flow";
|
|
13
|
+
import { useMockStdin } from "./helpers/mock-stdin";
|
|
5
14
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
6
15
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
7
16
|
|
|
8
17
|
describe("wrangler secret", () => {
|
|
9
18
|
const std = mockConsoleMethods();
|
|
19
|
+
const { mockGetMemberships } = mockOAuthFlow();
|
|
20
|
+
|
|
10
21
|
runInTempDir();
|
|
11
22
|
mockAccountId();
|
|
12
23
|
mockApiToken();
|
|
13
24
|
|
|
14
25
|
afterEach(() => {
|
|
15
26
|
unsetAllMocks();
|
|
27
|
+
clearConfirmMocks();
|
|
28
|
+
clearPromptMocks();
|
|
16
29
|
});
|
|
17
30
|
|
|
18
31
|
describe("put", () => {
|
|
@@ -44,84 +57,222 @@ describe("wrangler secret", () => {
|
|
|
44
57
|
);
|
|
45
58
|
}
|
|
46
59
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
describe("interactive", () => {
|
|
61
|
+
useMockStdin({ isTTY: true });
|
|
62
|
+
|
|
63
|
+
it("should trim stdin secret value", async () => {
|
|
64
|
+
mockPrompt({
|
|
65
|
+
text: "Enter a secret value:",
|
|
66
|
+
type: "password",
|
|
67
|
+
result: `hunter2
|
|
68
|
+
`,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
mockPutRequest({ name: `secret-name`, text: `hunter2` });
|
|
72
|
+
await runWrangler("secret put secret-name --name script-name");
|
|
73
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
74
|
+
"🌀 Creating the secret for script script-name
|
|
75
|
+
✨ Success! Uploaded secret secret-name"
|
|
76
|
+
`);
|
|
52
77
|
});
|
|
53
78
|
|
|
54
|
-
|
|
55
|
-
|
|
79
|
+
it("should create a secret", async () => {
|
|
80
|
+
mockPrompt({
|
|
81
|
+
text: "Enter a secret value:",
|
|
82
|
+
type: "password",
|
|
83
|
+
result: "the-secret",
|
|
84
|
+
});
|
|
56
85
|
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
✨ Success! Uploaded secret the-key"
|
|
60
|
-
`);
|
|
61
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
62
|
-
});
|
|
86
|
+
mockPutRequest({ name: "the-key", text: "the-secret" });
|
|
87
|
+
await runWrangler("secret put the-key --name script-name");
|
|
63
88
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
89
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
90
|
+
"🌀 Creating the secret for script script-name
|
|
91
|
+
✨ Success! Uploaded secret the-key"
|
|
92
|
+
`);
|
|
93
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
69
94
|
});
|
|
70
95
|
|
|
71
|
-
|
|
72
|
-
{
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"secret put the-key --name script-name --env some-env --legacy-env"
|
|
78
|
-
);
|
|
96
|
+
it("should create a secret: legacy envs", async () => {
|
|
97
|
+
mockPrompt({
|
|
98
|
+
text: "Enter a secret value:",
|
|
99
|
+
type: "password",
|
|
100
|
+
result: "the-secret",
|
|
101
|
+
});
|
|
79
102
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
103
|
+
mockPutRequest(
|
|
104
|
+
{ name: "the-key", text: "the-secret" },
|
|
105
|
+
"some-env",
|
|
106
|
+
true
|
|
107
|
+
);
|
|
108
|
+
await runWrangler(
|
|
109
|
+
"secret put the-key --name script-name --env some-env --legacy-env"
|
|
110
|
+
);
|
|
86
111
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
112
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
113
|
+
"🌀 Creating the secret for script script-name-some-env
|
|
114
|
+
✨ Success! Uploaded secret the-key"
|
|
115
|
+
`);
|
|
116
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
92
117
|
});
|
|
93
118
|
|
|
94
|
-
|
|
95
|
-
{
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"secret put the-key --name script-name --env some-env --legacy-env false"
|
|
101
|
-
);
|
|
119
|
+
it("should create a secret: service envs", async () => {
|
|
120
|
+
mockPrompt({
|
|
121
|
+
text: "Enter a secret value:",
|
|
122
|
+
type: "password",
|
|
123
|
+
result: "the-secret",
|
|
124
|
+
});
|
|
102
125
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
126
|
+
mockPutRequest(
|
|
127
|
+
{ name: "the-key", text: "the-secret" },
|
|
128
|
+
"some-env",
|
|
129
|
+
false
|
|
130
|
+
);
|
|
131
|
+
await runWrangler(
|
|
132
|
+
"secret put the-key --name script-name --env some-env --legacy-env false"
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
136
|
+
"🌀 Creating the secret for script script-name (some-env)
|
|
137
|
+
✨ Success! Uploaded secret the-key"
|
|
138
|
+
`);
|
|
139
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("should error without a script name", async () => {
|
|
143
|
+
let error: Error | undefined;
|
|
144
|
+
try {
|
|
145
|
+
await runWrangler("secret put the-key");
|
|
146
|
+
} catch (e) {
|
|
147
|
+
error = e as Error;
|
|
148
|
+
}
|
|
149
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
150
|
+
"
|
|
151
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
152
|
+
`);
|
|
153
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
154
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mMissing script name[0m
|
|
155
|
+
|
|
156
|
+
"
|
|
157
|
+
`);
|
|
158
|
+
expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
|
|
159
|
+
});
|
|
108
160
|
});
|
|
109
161
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
try {
|
|
113
|
-
await runWrangler("secret put the-key");
|
|
114
|
-
} catch (e) {
|
|
115
|
-
error = e as Error;
|
|
116
|
-
}
|
|
117
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
118
|
-
expect(std.err).toMatchInlineSnapshot(`
|
|
119
|
-
"Missing script name
|
|
162
|
+
describe("non-interactive", () => {
|
|
163
|
+
const mockStdIn = useMockStdin({ isTTY: false });
|
|
120
164
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
165
|
+
it("should trim stdin secret value, from piped input", async () => {
|
|
166
|
+
mockPutRequest({ name: "the-key", text: "the-secret" });
|
|
167
|
+
// Pipe the secret in as three chunks to test that we reconstitute it correctly.
|
|
168
|
+
mockStdIn.send(
|
|
169
|
+
`the`,
|
|
170
|
+
`-`,
|
|
171
|
+
`secret
|
|
172
|
+
` // whitespace & newline being removed
|
|
173
|
+
);
|
|
174
|
+
await runWrangler("secret put the-key --name script-name");
|
|
175
|
+
|
|
176
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
177
|
+
"🌀 Creating the secret for script script-name
|
|
178
|
+
✨ Success! Uploaded secret the-key"
|
|
179
|
+
`);
|
|
180
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
181
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("should create a secret, from piped input", async () => {
|
|
185
|
+
mockPutRequest({ name: "the-key", text: "the-secret" });
|
|
186
|
+
// Pipe the secret in as three chunks to test that we reconstitute it correctly.
|
|
187
|
+
mockStdIn.send("the", "-", "secret");
|
|
188
|
+
await runWrangler("secret put the-key --name script-name");
|
|
189
|
+
|
|
190
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
191
|
+
"🌀 Creating the secret for script script-name
|
|
192
|
+
✨ Success! Uploaded secret the-key"
|
|
193
|
+
`);
|
|
194
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
195
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("should error if the piped input fails", async () => {
|
|
199
|
+
mockPutRequest({ name: "the-key", text: "the-secret" });
|
|
200
|
+
mockStdIn.throwError(new Error("Error in stdin stream"));
|
|
201
|
+
await expect(
|
|
202
|
+
runWrangler("secret put the-key --name script-name")
|
|
203
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`"Error in stdin stream"`);
|
|
204
|
+
|
|
205
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
206
|
+
"
|
|
207
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
208
|
+
`);
|
|
209
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
describe("with accountId", () => {
|
|
213
|
+
mockAccountId({ accountId: null });
|
|
214
|
+
|
|
215
|
+
it("should error if a user has no account", async () => {
|
|
216
|
+
mockGetMemberships({
|
|
217
|
+
success: false,
|
|
218
|
+
result: [],
|
|
219
|
+
});
|
|
220
|
+
await expect(
|
|
221
|
+
runWrangler("secret put the-key --name script-name")
|
|
222
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
223
|
+
`"Failed to automatically retrieve account IDs for the logged in user. In a non-interactive environment, it is mandatory to specify an account ID, either by assigning its value to CLOUDFLARE_ACCOUNT_ID, or as \`account_id\` in your \`wrangler.toml\` file."`
|
|
224
|
+
);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("should use the account from wrangler.toml", async () => {
|
|
228
|
+
fs.writeFileSync(
|
|
229
|
+
"wrangler.toml",
|
|
230
|
+
TOML.stringify({
|
|
231
|
+
account_id: "some-account-id",
|
|
232
|
+
}),
|
|
233
|
+
"utf-8"
|
|
234
|
+
);
|
|
235
|
+
mockStdIn.send("the-secret");
|
|
236
|
+
mockPutRequest({ name: "the-key", text: "the-secret" });
|
|
237
|
+
await runWrangler("secret put the-key --name script-name");
|
|
238
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
239
|
+
"🌀 Creating the secret for script script-name
|
|
240
|
+
✨ Success! Uploaded secret the-key"
|
|
241
|
+
`);
|
|
242
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
243
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("should error if a user has multiple accounts, and has not specified an account in wrangler.toml", async () => {
|
|
247
|
+
mockGetMemberships({
|
|
248
|
+
success: true,
|
|
249
|
+
result: [
|
|
250
|
+
{
|
|
251
|
+
id: "1",
|
|
252
|
+
account: { id: "account-id-1", name: "account-name-1" },
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
id: "2",
|
|
256
|
+
account: { id: "account-id-2", name: "account-name-2" },
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
id: "3",
|
|
260
|
+
account: { id: "account-id-3", name: "account-name-3" },
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
await expect(runWrangler("secret put the-key --name script-name"))
|
|
266
|
+
.rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
267
|
+
"More than one account available but unable to select one in non-interactive mode.
|
|
268
|
+
Please set the appropriate \`account_id\` in your \`wrangler.toml\` file.
|
|
269
|
+
Available accounts are (\\"<name>\\" - \\"<id>\\"):
|
|
270
|
+
\\"account-name-1\\" - \\"account-id-1\\")
|
|
271
|
+
\\"account-name-2\\" - \\"account-id-2\\")
|
|
272
|
+
\\"account-name-3\\" - \\"account-id-3\\")"
|
|
273
|
+
`);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
125
276
|
});
|
|
126
277
|
});
|
|
127
278
|
|
|
@@ -219,12 +370,14 @@ describe("wrangler secret", () => {
|
|
|
219
370
|
} catch (e) {
|
|
220
371
|
error = e as Error;
|
|
221
372
|
}
|
|
222
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
373
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
374
|
+
"
|
|
375
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
376
|
+
`);
|
|
223
377
|
expect(std.err).toMatchInlineSnapshot(`
|
|
224
|
-
"
|
|
378
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mMissing script name[0m
|
|
225
379
|
|
|
226
|
-
|
|
227
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
380
|
+
"
|
|
228
381
|
`);
|
|
229
382
|
expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
|
|
230
383
|
});
|
|
@@ -313,12 +466,14 @@ describe("wrangler secret", () => {
|
|
|
313
466
|
} catch (e) {
|
|
314
467
|
error = e as Error;
|
|
315
468
|
}
|
|
316
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
469
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
470
|
+
"
|
|
471
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
472
|
+
`);
|
|
317
473
|
expect(std.err).toMatchInlineSnapshot(`
|
|
318
|
-
"
|
|
474
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mMissing script name[0m
|
|
319
475
|
|
|
320
|
-
|
|
321
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
476
|
+
"
|
|
322
477
|
`);
|
|
323
478
|
expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
|
|
324
479
|
});
|