wrangler 0.0.0-e9ab55a → 0.0.0-ed4f2ef
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/README.md +3 -3
- package/bin/wrangler.js +12 -3
- package/miniflare-dist/index.mjs +79 -0
- package/miniflare-dist/index.mjs.map +7 -0
- package/package.json +33 -16
- package/pages/functions/buildWorker.ts +1 -1
- package/pages/functions/filepath-routing.test.ts +212 -28
- package/pages/functions/filepath-routing.ts +83 -130
- package/pages/functions/routes.ts +11 -18
- package/pages/functions/template-worker.ts +3 -9
- package/src/__tests__/configuration.test.ts +2874 -0
- package/src/__tests__/dev.test.tsx +582 -61
- package/src/__tests__/guess-worker-format.test.ts +83 -0
- package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
- package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
- package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +48 -0
- package/src/__tests__/helpers/mock-bin.ts +36 -0
- package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +52 -16
- package/src/__tests__/helpers/mock-console.ts +70 -0
- package/src/__tests__/{mock-dialogs.ts → helpers/mock-dialogs.ts} +1 -1
- package/src/__tests__/helpers/mock-kv.ts +33 -0
- package/src/__tests__/helpers/mock-oauth-flow.ts +178 -0
- package/src/__tests__/helpers/mock-stdin.ts +103 -0
- package/src/__tests__/helpers/mock-web-socket.ts +29 -0
- package/src/__tests__/helpers/run-in-tmp.ts +32 -0
- package/src/__tests__/helpers/run-wrangler.ts +16 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
- package/src/__tests__/https-options.test.ts +127 -0
- package/src/__tests__/index.test.ts +777 -77
- package/src/__tests__/jest.setup.ts +58 -6
- package/src/__tests__/kv.test.ts +716 -462
- package/src/__tests__/package-manager.test.ts +206 -0
- package/src/__tests__/pages.test.ts +180 -0
- package/src/__tests__/parse.test.ts +322 -0
- package/src/__tests__/publish.test.ts +3915 -71
- package/src/__tests__/r2.test.ts +198 -0
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +425 -0
- package/src/__tests__/sentry.test.ts +146 -0
- package/src/__tests__/tail.test.ts +638 -0
- package/src/__tests__/user.test.ts +83 -0
- package/src/__tests__/whoami.test.tsx +95 -0
- package/src/bundle.ts +155 -0
- package/src/cfetch/index.ts +21 -19
- package/src/cfetch/internal.ts +92 -22
- package/src/cli.ts +14 -2
- package/src/config/README.md +107 -0
- package/src/config/config.ts +229 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +371 -0
- package/src/config/index.ts +62 -0
- package/src/config/validation-helpers.ts +557 -0
- package/src/config/validation.ts +1240 -0
- package/src/{api/preview.ts → create-worker-preview.ts} +69 -24
- package/src/create-worker-upload-form.ts +240 -0
- package/src/dev/dev.tsx +413 -0
- package/src/dev/local.tsx +287 -0
- package/src/dev/remote.tsx +209 -0
- package/src/dev/use-esbuild.ts +109 -0
- package/src/dialogs.tsx +2 -2
- package/src/entry.ts +256 -0
- package/src/environment-variables.ts +33 -0
- package/src/errors.ts +11 -0
- package/src/https-options.ts +122 -0
- package/src/index.tsx +1310 -849
- package/src/inspect.ts +102 -21
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv.tsx → kv.ts} +104 -61
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +38 -0
- package/src/module-collection.ts +228 -35
- package/src/open-in-browser.ts +25 -0
- package/src/package-manager.ts +126 -0
- package/src/pages.tsx +214 -48
- package/src/parse.ts +183 -0
- package/src/paths.ts +26 -0
- package/src/proxy.ts +192 -39
- package/src/publish.ts +321 -318
- package/src/r2.ts +50 -0
- package/src/reporting.ts +131 -0
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +224 -62
- package/src/tail/filters.ts +279 -0
- package/src/tail/index.ts +299 -0
- package/src/tail/printing.ts +62 -0
- package/src/user.tsx +317 -178
- package/src/whoami.tsx +69 -0
- package/src/{api/worker.ts → worker.ts} +54 -37
- package/templates/new-worker.js +15 -0
- package/templates/new-worker.ts +15 -0
- package/{static-asset-facade.js → templates/static-asset-facade.js} +1 -1
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +131262 -112648
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/run-in-tmp.ts +0 -19
- package/src/__tests__/run-wrangler.ts +0 -32
- package/src/api/form_data.ts +0 -131
- package/src/config.ts +0 -646
- package/src/dev.tsx +0 -784
- package/src/tail.tsx +0 -73
|
@@ -1,76 +1,100 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
1
2
|
import * as fsp from "node:fs/promises";
|
|
2
3
|
import * as TOML from "@iarna/toml";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
4
|
+
import { parseConfigFileTextToJson } from "typescript";
|
|
5
|
+
import { version as wranglerVersion } from "../../package.json";
|
|
6
|
+
import { getPackageManager } from "../package-manager";
|
|
7
|
+
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
8
|
+
import { mockConfirm } from "./helpers/mock-dialogs";
|
|
9
|
+
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
10
|
+
import { runWrangler } from "./helpers/run-wrangler";
|
|
11
|
+
import type { PackageManager } from "../package-manager";
|
|
7
12
|
|
|
8
13
|
describe("wrangler", () => {
|
|
14
|
+
let mockPackageManager: PackageManager;
|
|
9
15
|
runInTempDir();
|
|
10
16
|
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
mockPackageManager = {
|
|
19
|
+
cwd: process.cwd(),
|
|
20
|
+
// @ts-expect-error we're making a fake package manager here
|
|
21
|
+
type: "mockpm",
|
|
22
|
+
addDevDeps: jest.fn(),
|
|
23
|
+
install: jest.fn(),
|
|
24
|
+
};
|
|
25
|
+
(getPackageManager as jest.Mock).mockResolvedValue(mockPackageManager);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const std = mockConsoleMethods();
|
|
29
|
+
|
|
11
30
|
describe("no command", () => {
|
|
12
31
|
it("should display a list of available commands", async () => {
|
|
13
|
-
|
|
32
|
+
await runWrangler();
|
|
14
33
|
|
|
15
|
-
expect(
|
|
34
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
16
35
|
"wrangler
|
|
17
36
|
|
|
18
37
|
Commands:
|
|
19
38
|
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
20
|
-
wrangler dev
|
|
39
|
+
wrangler dev [script] 👂 Start a local server for developing your worker
|
|
21
40
|
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
22
|
-
wrangler tail [name] 🦚 Starts a log tailing session for a
|
|
41
|
+
wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
|
|
23
42
|
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
|
|
24
43
|
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
|
|
25
44
|
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
|
|
26
45
|
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
27
46
|
wrangler pages ⚡️ Configure Cloudflare Pages
|
|
47
|
+
wrangler r2 📦 Interact with an R2 store
|
|
48
|
+
wrangler login 🔓 Login to Cloudflare
|
|
49
|
+
wrangler logout 🚪 Logout from Cloudflare
|
|
50
|
+
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
28
51
|
|
|
29
52
|
Flags:
|
|
30
|
-
-c, --config
|
|
31
|
-
-h, --help
|
|
32
|
-
-v, --version
|
|
33
|
-
|
|
34
|
-
Options:
|
|
35
|
-
-l, --local Run on my machine [boolean] [default: false]"
|
|
53
|
+
-c, --config Path to .toml configuration file [string]
|
|
54
|
+
-h, --help Show help [boolean]
|
|
55
|
+
-v, --version Show version number [boolean]
|
|
56
|
+
--legacy-env Use legacy environments [boolean]"
|
|
36
57
|
`);
|
|
37
58
|
|
|
38
|
-
expect(
|
|
59
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
39
60
|
});
|
|
40
61
|
});
|
|
41
62
|
|
|
42
63
|
describe("invalid command", () => {
|
|
43
64
|
it("should display an error", async () => {
|
|
44
|
-
|
|
65
|
+
await expect(
|
|
66
|
+
runWrangler("invalid-command")
|
|
67
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
68
|
+
`"Unknown argument: invalid-command"`
|
|
69
|
+
);
|
|
45
70
|
|
|
46
|
-
expect(
|
|
47
|
-
expect(
|
|
71
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
72
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
48
73
|
"wrangler
|
|
49
74
|
|
|
50
75
|
Commands:
|
|
51
76
|
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
52
|
-
wrangler dev
|
|
77
|
+
wrangler dev [script] 👂 Start a local server for developing your worker
|
|
53
78
|
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
54
|
-
wrangler tail [name] 🦚 Starts a log tailing session for a
|
|
79
|
+
wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
|
|
55
80
|
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
|
|
56
81
|
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
|
|
57
82
|
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
|
|
58
83
|
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
59
84
|
wrangler pages ⚡️ Configure Cloudflare Pages
|
|
85
|
+
wrangler r2 📦 Interact with an R2 store
|
|
86
|
+
wrangler login 🔓 Login to Cloudflare
|
|
87
|
+
wrangler logout 🚪 Logout from Cloudflare
|
|
88
|
+
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
60
89
|
|
|
61
90
|
Flags:
|
|
62
|
-
-c, --config
|
|
63
|
-
-h, --help
|
|
64
|
-
-v, --version
|
|
91
|
+
-c, --config Path to .toml configuration file [string]
|
|
92
|
+
-h, --help Show help [boolean]
|
|
93
|
+
-v, --version Show version number [boolean]
|
|
94
|
+
--legacy-env Use legacy environments [boolean]
|
|
65
95
|
|
|
66
|
-
|
|
67
|
-
-l, --local Run on my machine [boolean] [default: false]
|
|
68
|
-
|
|
69
|
-
Unknown command: invalid-command."
|
|
96
|
+
Unknown argument: invalid-command"
|
|
70
97
|
`);
|
|
71
|
-
expect(error).toMatchInlineSnapshot(
|
|
72
|
-
`[Error: Unknown command: invalid-command.]`
|
|
73
|
-
);
|
|
74
98
|
});
|
|
75
99
|
});
|
|
76
100
|
|
|
@@ -83,24 +107,79 @@ describe("wrangler", () => {
|
|
|
83
107
|
await runWrangler("init");
|
|
84
108
|
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
85
109
|
expect(typeof parsed.compatibility_date).toBe("string");
|
|
110
|
+
expect(parsed.name).toContain("wrangler-tests");
|
|
86
111
|
expect(fs.existsSync("./package.json")).toBe(false);
|
|
87
112
|
expect(fs.existsSync("./tsconfig.json")).toBe(false);
|
|
88
113
|
});
|
|
89
114
|
|
|
115
|
+
it("should create a wrangler.toml and a directory for a named Worker ", async () => {
|
|
116
|
+
mockConfirm({
|
|
117
|
+
text: "No package.json found. Would you like to create one?",
|
|
118
|
+
result: false,
|
|
119
|
+
});
|
|
120
|
+
await runWrangler("init my-worker");
|
|
121
|
+
const parsed = TOML.parse(
|
|
122
|
+
await fsp.readFile("./my-worker/wrangler.toml", "utf-8")
|
|
123
|
+
);
|
|
124
|
+
expect(typeof parsed.compatibility_date).toBe("string");
|
|
125
|
+
expect(parsed.name).toBe("my-worker");
|
|
126
|
+
expect(fs.existsSync("./my-worker/package.json")).toBe(false);
|
|
127
|
+
expect(fs.existsSync("./my-worker/tsconfig.json")).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
|
|
90
130
|
it("should display warning when wrangler.toml already exists, and exit if user does not want to carry on", async () => {
|
|
91
|
-
fs.writeFileSync(
|
|
131
|
+
fs.writeFileSync(
|
|
132
|
+
"./wrangler.toml",
|
|
133
|
+
'compatibility_date="something-else"', // use a fake value to make sure the file is not overwritten
|
|
134
|
+
"utf-8"
|
|
135
|
+
);
|
|
92
136
|
mockConfirm({
|
|
93
137
|
text: "Do you want to continue initializing this project?",
|
|
94
138
|
result: false,
|
|
95
139
|
});
|
|
96
|
-
|
|
97
|
-
expect(
|
|
140
|
+
await runWrangler("init");
|
|
141
|
+
expect(std.warn).toContain("wrangler.toml file already exists!");
|
|
98
142
|
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
99
|
-
expect(
|
|
143
|
+
expect(parsed.compatibility_date).toBe("something-else");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("should not overwrite an existing wrangler.toml, after agreeing to other prompts", async () => {
|
|
147
|
+
fs.writeFileSync(
|
|
148
|
+
"./wrangler.toml",
|
|
149
|
+
'compatibility_date="something-else"', // use a fake value to make sure the file is not overwritten
|
|
150
|
+
"utf-8"
|
|
151
|
+
);
|
|
152
|
+
mockConfirm(
|
|
153
|
+
{
|
|
154
|
+
text: "Do you want to continue initializing this project?",
|
|
155
|
+
result: true,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
text: "No package.json found. Would you like to create one?",
|
|
159
|
+
result: true,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
text: "Would you like to use TypeScript?",
|
|
163
|
+
result: true,
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
167
|
+
result: true,
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
await runWrangler("init");
|
|
172
|
+
expect(fs.readFileSync("./wrangler.toml", "utf-8")).toMatchInlineSnapshot(
|
|
173
|
+
`"compatibility_date=\\"something-else\\""`
|
|
174
|
+
);
|
|
100
175
|
});
|
|
101
176
|
|
|
102
177
|
it("should display warning when wrangler.toml already exists, but continue if user does want to carry on", async () => {
|
|
103
|
-
fs.writeFileSync(
|
|
178
|
+
fs.writeFileSync(
|
|
179
|
+
"./wrangler.toml",
|
|
180
|
+
`compatibility_date="something-else"`,
|
|
181
|
+
"utf-8"
|
|
182
|
+
);
|
|
104
183
|
mockConfirm(
|
|
105
184
|
{
|
|
106
185
|
text: "Do you want to continue initializing this project?",
|
|
@@ -111,10 +190,10 @@ describe("wrangler", () => {
|
|
|
111
190
|
result: false,
|
|
112
191
|
}
|
|
113
192
|
);
|
|
114
|
-
|
|
115
|
-
expect(
|
|
193
|
+
await runWrangler("init");
|
|
194
|
+
expect(std.warn).toContain("wrangler.toml file already exists!");
|
|
116
195
|
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
117
|
-
expect(
|
|
196
|
+
expect(parsed.compatibility_date).toBe("something-else");
|
|
118
197
|
});
|
|
119
198
|
|
|
120
199
|
it("should create a package.json if none is found and user confirms", async () => {
|
|
@@ -124,7 +203,11 @@ describe("wrangler", () => {
|
|
|
124
203
|
result: true,
|
|
125
204
|
},
|
|
126
205
|
{
|
|
127
|
-
text: "Would you like to use
|
|
206
|
+
text: "Would you like to use TypeScript?",
|
|
207
|
+
result: false,
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
128
211
|
result: false,
|
|
129
212
|
}
|
|
130
213
|
);
|
|
@@ -133,16 +216,82 @@ describe("wrangler", () => {
|
|
|
133
216
|
const packageJson = JSON.parse(
|
|
134
217
|
fs.readFileSync("./package.json", "utf-8")
|
|
135
218
|
);
|
|
136
|
-
expect(packageJson.name).
|
|
137
|
-
expect(packageJson.version).toEqual("0.0.
|
|
219
|
+
expect(packageJson.name).toContain("wrangler-tests");
|
|
220
|
+
expect(packageJson.version).toEqual("0.0.0");
|
|
221
|
+
expect(packageJson.devDependencies).toEqual({
|
|
222
|
+
wrangler: expect.any(String),
|
|
223
|
+
});
|
|
138
224
|
expect(fs.existsSync("./tsconfig.json")).toBe(false);
|
|
225
|
+
expect(mockPackageManager.install).toHaveBeenCalled();
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("should create a package.json, with the specified name, if none is found and user confirms", async () => {
|
|
229
|
+
mockConfirm(
|
|
230
|
+
{
|
|
231
|
+
text: "No package.json found. Would you like to create one?",
|
|
232
|
+
result: true,
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
text: "Would you like to use TypeScript?",
|
|
236
|
+
result: false,
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
240
|
+
result: false,
|
|
241
|
+
}
|
|
242
|
+
);
|
|
243
|
+
await runWrangler("init my-worker");
|
|
244
|
+
const packageJson = JSON.parse(
|
|
245
|
+
fs.readFileSync("./my-worker/package.json", "utf-8")
|
|
246
|
+
);
|
|
247
|
+
expect(packageJson.name).toBe("my-worker");
|
|
139
248
|
});
|
|
140
249
|
|
|
141
250
|
it("should not touch an existing package.json in the same directory", async () => {
|
|
142
|
-
mockConfirm(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
251
|
+
mockConfirm(
|
|
252
|
+
{
|
|
253
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
254
|
+
result: false,
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
text: "Would you like to use TypeScript?",
|
|
258
|
+
result: false,
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
262
|
+
result: false,
|
|
263
|
+
}
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
fs.writeFileSync(
|
|
267
|
+
"./package.json",
|
|
268
|
+
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
269
|
+
"utf-8"
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
await runWrangler("init");
|
|
273
|
+
const packageJson = JSON.parse(
|
|
274
|
+
fs.readFileSync("./package.json", "utf-8")
|
|
275
|
+
);
|
|
276
|
+
expect(packageJson.name).toEqual("test");
|
|
277
|
+
expect(packageJson.version).toEqual("1.0.0");
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("should offer to install wrangler into an existing package.json", async () => {
|
|
281
|
+
mockConfirm(
|
|
282
|
+
{
|
|
283
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
284
|
+
result: true,
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
text: "Would you like to use TypeScript?",
|
|
288
|
+
result: false,
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
292
|
+
result: false,
|
|
293
|
+
}
|
|
294
|
+
);
|
|
146
295
|
|
|
147
296
|
fs.writeFileSync(
|
|
148
297
|
"./package.json",
|
|
@@ -156,13 +305,26 @@ describe("wrangler", () => {
|
|
|
156
305
|
);
|
|
157
306
|
expect(packageJson.name).toEqual("test");
|
|
158
307
|
expect(packageJson.version).toEqual("1.0.0");
|
|
308
|
+
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
309
|
+
`wrangler@${wranglerVersion}`
|
|
310
|
+
);
|
|
159
311
|
});
|
|
160
312
|
|
|
161
313
|
it("should not touch an existing package.json in an ancestor directory", async () => {
|
|
162
|
-
mockConfirm(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
314
|
+
mockConfirm(
|
|
315
|
+
{
|
|
316
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
317
|
+
result: false,
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
text: "Would you like to use TypeScript?",
|
|
321
|
+
result: false,
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
325
|
+
result: false,
|
|
326
|
+
}
|
|
327
|
+
);
|
|
166
328
|
|
|
167
329
|
fs.writeFileSync(
|
|
168
330
|
"./package.json",
|
|
@@ -180,8 +342,292 @@ describe("wrangler", () => {
|
|
|
180
342
|
const packageJson = JSON.parse(
|
|
181
343
|
fs.readFileSync("../../package.json", "utf-8")
|
|
182
344
|
);
|
|
183
|
-
expect(packageJson
|
|
184
|
-
|
|
345
|
+
expect(packageJson).toMatchInlineSnapshot(`
|
|
346
|
+
Object {
|
|
347
|
+
"name": "test",
|
|
348
|
+
"version": "1.0.0",
|
|
349
|
+
}
|
|
350
|
+
`);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it("should offer to create a worker in a non-typescript project", async () => {
|
|
354
|
+
mockConfirm(
|
|
355
|
+
{
|
|
356
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
357
|
+
result: false,
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
text: "Would you like to use TypeScript?",
|
|
361
|
+
result: false,
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
365
|
+
result: true,
|
|
366
|
+
}
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
fs.writeFileSync(
|
|
370
|
+
"./package.json",
|
|
371
|
+
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
372
|
+
"utf-8"
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
await runWrangler("init");
|
|
376
|
+
expect(fs.existsSync("./src/index.js")).toBe(true);
|
|
377
|
+
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
it("should offer to create a worker in a typescript project", async () => {
|
|
381
|
+
mockConfirm(
|
|
382
|
+
{
|
|
383
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
384
|
+
result: false,
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
text: "Would you like to use TypeScript?",
|
|
388
|
+
result: true,
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
392
|
+
result: true,
|
|
393
|
+
}
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
fs.writeFileSync(
|
|
397
|
+
"./package.json",
|
|
398
|
+
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
399
|
+
"utf-8"
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
await runWrangler("init");
|
|
403
|
+
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
404
|
+
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it("should add scripts for a typescript project with .ts extension", async () => {
|
|
408
|
+
mockConfirm(
|
|
409
|
+
{
|
|
410
|
+
text: "No package.json found. Would you like to create one?",
|
|
411
|
+
result: true,
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
415
|
+
result: false,
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
text: "Would you like to use TypeScript?",
|
|
419
|
+
result: true,
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
423
|
+
result: true,
|
|
424
|
+
}
|
|
425
|
+
);
|
|
426
|
+
await runWrangler("init");
|
|
427
|
+
|
|
428
|
+
expect(fs.existsSync("./package.json")).toBe(true);
|
|
429
|
+
const packageJson = JSON.parse(
|
|
430
|
+
fs.readFileSync("./package.json", "utf-8")
|
|
431
|
+
);
|
|
432
|
+
|
|
433
|
+
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
434
|
+
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
435
|
+
|
|
436
|
+
expect(packageJson.scripts.start).toBe("wrangler dev");
|
|
437
|
+
expect(packageJson.scripts.publish).toBe("wrangler publish");
|
|
438
|
+
expect(packageJson.name).toContain("wrangler-tests");
|
|
439
|
+
expect(packageJson.version).toEqual("0.0.0");
|
|
440
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
441
|
+
"✨ Successfully created wrangler.toml
|
|
442
|
+
✨ Created package.json
|
|
443
|
+
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
444
|
+
✨ Created src/index.ts
|
|
445
|
+
|
|
446
|
+
To start developing your Worker, run \`npm start\`
|
|
447
|
+
To publish your Worker to the Internet, run \`npm run publish\`"
|
|
448
|
+
`);
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it("should not overwrite package.json scripts for a typescript project", async () => {
|
|
452
|
+
mockConfirm(
|
|
453
|
+
{
|
|
454
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
455
|
+
result: false,
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
text: "Would you like to use TypeScript?",
|
|
459
|
+
result: true,
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
463
|
+
result: true,
|
|
464
|
+
}
|
|
465
|
+
);
|
|
466
|
+
await fsp.writeFile(
|
|
467
|
+
"./package.json",
|
|
468
|
+
JSON.stringify({
|
|
469
|
+
scripts: {
|
|
470
|
+
start: "test-start",
|
|
471
|
+
publish: "test-publish",
|
|
472
|
+
},
|
|
473
|
+
})
|
|
474
|
+
);
|
|
475
|
+
const packageJson = JSON.parse(
|
|
476
|
+
fs.readFileSync("./package.json", "utf-8")
|
|
477
|
+
);
|
|
478
|
+
await runWrangler("init");
|
|
479
|
+
|
|
480
|
+
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
481
|
+
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
482
|
+
|
|
483
|
+
expect(packageJson.scripts.start).toBe("test-start");
|
|
484
|
+
expect(packageJson.scripts.publish).toBe("test-publish");
|
|
485
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
486
|
+
"✨ Successfully created wrangler.toml
|
|
487
|
+
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
488
|
+
✨ Created src/index.ts
|
|
489
|
+
|
|
490
|
+
To start developing your Worker, run \`npx wrangler dev\`
|
|
491
|
+
To publish your Worker to the Internet, run \`npx wrangler publish\`"
|
|
492
|
+
`);
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
it("should add missing scripts for a non-ts project with .js extension", async () => {
|
|
496
|
+
mockConfirm(
|
|
497
|
+
{
|
|
498
|
+
text: "No package.json found. Would you like to create one?",
|
|
499
|
+
result: true,
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
503
|
+
result: false,
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
text: "Would you like to use TypeScript?",
|
|
507
|
+
result: false,
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
511
|
+
result: true,
|
|
512
|
+
}
|
|
513
|
+
);
|
|
514
|
+
await runWrangler("init");
|
|
515
|
+
|
|
516
|
+
expect(fs.existsSync("./package.json")).toBe(true);
|
|
517
|
+
const packageJson = JSON.parse(
|
|
518
|
+
fs.readFileSync("./package.json", "utf-8")
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
expect(fs.existsSync("./src/index.js")).toBe(true);
|
|
522
|
+
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
523
|
+
|
|
524
|
+
expect(packageJson.scripts.start).toBe("wrangler dev");
|
|
525
|
+
expect(packageJson.scripts.publish).toBe("wrangler publish");
|
|
526
|
+
expect(packageJson.name).toContain("wrangler-tests");
|
|
527
|
+
expect(packageJson.version).toEqual("0.0.0");
|
|
528
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
529
|
+
"✨ Successfully created wrangler.toml
|
|
530
|
+
✨ Created package.json
|
|
531
|
+
✨ Created src/index.js
|
|
532
|
+
|
|
533
|
+
To start developing your Worker, run \`npm start\`
|
|
534
|
+
To publish your Worker to the Internet, run \`npm run publish\`"
|
|
535
|
+
`);
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
it("should not overwrite package.json scripts for a non-ts project with .js extension", async () => {
|
|
539
|
+
mockConfirm(
|
|
540
|
+
{
|
|
541
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
542
|
+
result: false,
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
text: "Would you like to use TypeScript?",
|
|
546
|
+
result: false,
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
550
|
+
result: true,
|
|
551
|
+
}
|
|
552
|
+
);
|
|
553
|
+
await fsp.writeFile(
|
|
554
|
+
"./package.json",
|
|
555
|
+
JSON.stringify({
|
|
556
|
+
scripts: {
|
|
557
|
+
start: "test-start",
|
|
558
|
+
publish: "test-publish",
|
|
559
|
+
},
|
|
560
|
+
})
|
|
561
|
+
);
|
|
562
|
+
const packageJson = JSON.parse(
|
|
563
|
+
fs.readFileSync("./package.json", "utf-8")
|
|
564
|
+
);
|
|
565
|
+
await runWrangler("init");
|
|
566
|
+
|
|
567
|
+
expect(fs.existsSync("./src/index.js")).toBe(true);
|
|
568
|
+
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
569
|
+
|
|
570
|
+
expect(packageJson.scripts.start).toBe("test-start");
|
|
571
|
+
expect(packageJson.scripts.publish).toBe("test-publish");
|
|
572
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
573
|
+
"✨ Successfully created wrangler.toml
|
|
574
|
+
✨ Created src/index.js
|
|
575
|
+
|
|
576
|
+
To start developing your Worker, run \`npx wrangler dev\`
|
|
577
|
+
To publish your Worker to the Internet, run \`npx wrangler publish\`"
|
|
578
|
+
`);
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
it("should not offer to create a worker in a non-ts project if a file already exists at the location", async () => {
|
|
582
|
+
mockConfirm(
|
|
583
|
+
{
|
|
584
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
585
|
+
result: false,
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
text: "Would you like to use TypeScript?",
|
|
589
|
+
result: false,
|
|
590
|
+
}
|
|
591
|
+
);
|
|
592
|
+
|
|
593
|
+
fs.writeFileSync(
|
|
594
|
+
"./package.json",
|
|
595
|
+
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
596
|
+
"utf-8"
|
|
597
|
+
);
|
|
598
|
+
fs.mkdirSync("./src", { recursive: true });
|
|
599
|
+
const PLACEHOLDER = "/* placeholder text */";
|
|
600
|
+
fs.writeFileSync("./src/index.js", PLACEHOLDER, "utf-8");
|
|
601
|
+
|
|
602
|
+
await runWrangler("init");
|
|
603
|
+
expect(fs.readFileSync("./src/index.js", "utf-8")).toBe(PLACEHOLDER);
|
|
604
|
+
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
it("should not offer to create a worker in a ts project if a file already exists at the location", async () => {
|
|
608
|
+
mockConfirm(
|
|
609
|
+
{
|
|
610
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
611
|
+
result: false,
|
|
612
|
+
},
|
|
613
|
+
{
|
|
614
|
+
text: "Would you like to use TypeScript?",
|
|
615
|
+
result: true,
|
|
616
|
+
}
|
|
617
|
+
);
|
|
618
|
+
|
|
619
|
+
fs.writeFileSync(
|
|
620
|
+
"./package.json",
|
|
621
|
+
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
622
|
+
"utf-8"
|
|
623
|
+
);
|
|
624
|
+
fs.mkdirSync("./src", { recursive: true });
|
|
625
|
+
const PLACEHOLDER = "/* placeholder text */";
|
|
626
|
+
fs.writeFileSync("./src/index.ts", PLACEHOLDER, "utf-8");
|
|
627
|
+
|
|
628
|
+
await runWrangler("init");
|
|
629
|
+
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
630
|
+
expect(fs.readFileSync("./src/index.ts", "utf-8")).toBe(PLACEHOLDER);
|
|
185
631
|
});
|
|
186
632
|
|
|
187
633
|
it("should create a tsconfig.json and install `workers-types` if none is found and user confirms", async () => {
|
|
@@ -191,30 +637,42 @@ describe("wrangler", () => {
|
|
|
191
637
|
result: true,
|
|
192
638
|
},
|
|
193
639
|
{
|
|
194
|
-
text: "Would you like to use
|
|
640
|
+
text: "Would you like to use TypeScript?",
|
|
195
641
|
result: true,
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
645
|
+
result: false,
|
|
196
646
|
}
|
|
197
647
|
);
|
|
198
648
|
await runWrangler("init");
|
|
199
649
|
expect(fs.existsSync("./tsconfig.json")).toBe(true);
|
|
200
|
-
const tsconfigJson =
|
|
201
|
-
|
|
202
|
-
|
|
650
|
+
const { config: tsconfigJson, error: tsConfigParseError } =
|
|
651
|
+
parseConfigFileTextToJson(
|
|
652
|
+
"./tsconfig.json",
|
|
653
|
+
fs.readFileSync("./tsconfig.json", "utf-8")
|
|
654
|
+
);
|
|
655
|
+
expect(tsConfigParseError).toBeUndefined();
|
|
203
656
|
expect(tsconfigJson.compilerOptions.types).toEqual([
|
|
204
657
|
"@cloudflare/workers-types",
|
|
205
658
|
]);
|
|
206
|
-
|
|
207
|
-
|
|
659
|
+
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
660
|
+
"@cloudflare/workers-types",
|
|
661
|
+
"typescript"
|
|
208
662
|
);
|
|
209
|
-
expect(packageJson.devDependencies).toEqual({
|
|
210
|
-
"@cloudflare/workers-types": expect.any(String),
|
|
211
|
-
});
|
|
212
663
|
});
|
|
213
664
|
|
|
214
665
|
it("should not touch an existing tsconfig.json in the same directory", async () => {
|
|
215
666
|
fs.writeFileSync(
|
|
216
667
|
"./package.json",
|
|
217
|
-
JSON.stringify({
|
|
668
|
+
JSON.stringify({
|
|
669
|
+
name: "test",
|
|
670
|
+
version: "1.0.0",
|
|
671
|
+
devDependencies: {
|
|
672
|
+
wrangler: "0.0.0",
|
|
673
|
+
"@cloudflare/workers-types": "0.0.0",
|
|
674
|
+
},
|
|
675
|
+
}),
|
|
218
676
|
"utf-8"
|
|
219
677
|
);
|
|
220
678
|
fs.writeFileSync(
|
|
@@ -230,10 +688,57 @@ describe("wrangler", () => {
|
|
|
230
688
|
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
231
689
|
});
|
|
232
690
|
|
|
233
|
-
it("should
|
|
691
|
+
it("should offer to install type definitions in an existing typescript project", async () => {
|
|
692
|
+
mockConfirm(
|
|
693
|
+
{
|
|
694
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
695
|
+
result: false,
|
|
696
|
+
},
|
|
697
|
+
{
|
|
698
|
+
text: "Would you like to install the type definitions for Workers into your package.json?",
|
|
699
|
+
result: true,
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
703
|
+
result: false,
|
|
704
|
+
}
|
|
705
|
+
);
|
|
234
706
|
fs.writeFileSync(
|
|
235
707
|
"./package.json",
|
|
236
|
-
JSON.stringify({
|
|
708
|
+
JSON.stringify({
|
|
709
|
+
name: "test",
|
|
710
|
+
version: "1.0.0",
|
|
711
|
+
}),
|
|
712
|
+
"utf-8"
|
|
713
|
+
);
|
|
714
|
+
fs.writeFileSync(
|
|
715
|
+
"./tsconfig.json",
|
|
716
|
+
JSON.stringify({ compilerOptions: {} }),
|
|
717
|
+
"utf-8"
|
|
718
|
+
);
|
|
719
|
+
|
|
720
|
+
await runWrangler("init");
|
|
721
|
+
const tsconfigJson = JSON.parse(
|
|
722
|
+
fs.readFileSync("./tsconfig.json", "utf-8")
|
|
723
|
+
);
|
|
724
|
+
// unchanged tsconfig
|
|
725
|
+
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
726
|
+
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
727
|
+
"@cloudflare/workers-types"
|
|
728
|
+
);
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
it("should not touch an existing tsconfig.json in an ancestor directory", async () => {
|
|
732
|
+
fs.writeFileSync(
|
|
733
|
+
"./package.json",
|
|
734
|
+
JSON.stringify({
|
|
735
|
+
name: "test",
|
|
736
|
+
version: "1.0.0",
|
|
737
|
+
devDependencies: {
|
|
738
|
+
wrangler: "0.0.0",
|
|
739
|
+
"@cloudflare/workers-types": "0.0.0",
|
|
740
|
+
},
|
|
741
|
+
}),
|
|
237
742
|
"utf-8"
|
|
238
743
|
);
|
|
239
744
|
fs.writeFileSync(
|
|
@@ -255,33 +760,228 @@ describe("wrangler", () => {
|
|
|
255
760
|
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
256
761
|
});
|
|
257
762
|
|
|
258
|
-
it("should
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
763
|
+
it("should initialize with no interactive prompts if `--yes` is used", async () => {
|
|
764
|
+
await runWrangler("init --yes");
|
|
765
|
+
|
|
766
|
+
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
767
|
+
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
768
|
+
expect(fs.existsSync("./tsconfig.json")).toBe(true);
|
|
769
|
+
expect(fs.existsSync("./package.json")).toBe(true);
|
|
770
|
+
expect(fs.existsSync("./wrangler.toml")).toBe(true);
|
|
771
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
772
|
+
"✨ Successfully created wrangler.toml
|
|
773
|
+
✨ Created package.json
|
|
774
|
+
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
775
|
+
✨ Created src/index.ts
|
|
776
|
+
|
|
777
|
+
To start developing your Worker, run \`npm start\`
|
|
778
|
+
To publish your Worker to the Internet, run \`npm run publish\`"
|
|
779
|
+
`);
|
|
780
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
781
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
it("should initialize with no interactive prompts if `--yes` is used (named worker)", async () => {
|
|
785
|
+
await runWrangler("init my-worker --yes");
|
|
786
|
+
|
|
787
|
+
expect(fs.existsSync("./my-worker/src/index.js")).toBe(false);
|
|
788
|
+
expect(fs.existsSync("./my-worker/src/index.ts")).toBe(true);
|
|
789
|
+
expect(fs.existsSync("./my-worker/tsconfig.json")).toBe(true);
|
|
790
|
+
expect(fs.existsSync("./my-worker/package.json")).toBe(true);
|
|
791
|
+
expect(fs.existsSync("./my-worker/wrangler.toml")).toBe(true);
|
|
792
|
+
const parsedWranglerToml = TOML.parse(
|
|
793
|
+
fs.readFileSync("./my-worker/wrangler.toml", "utf-8")
|
|
262
794
|
);
|
|
795
|
+
expect(parsedWranglerToml.main).toEqual("src/index.ts");
|
|
796
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
797
|
+
"✨ Successfully created wrangler.toml
|
|
798
|
+
✨ Created package.json
|
|
799
|
+
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
800
|
+
✨ Created src/index.ts
|
|
801
|
+
|
|
802
|
+
To start developing your Worker, run \`cd my-worker && npm start\`
|
|
803
|
+
To publish your Worker to the Internet, run \`npm run publish\`"
|
|
804
|
+
`);
|
|
805
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
806
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
it("should initialize with no interactive prompts if `-y` is used", async () => {
|
|
810
|
+
await runWrangler("init -y");
|
|
811
|
+
|
|
812
|
+
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
813
|
+
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
814
|
+
expect(fs.existsSync("./tsconfig.json")).toBe(true);
|
|
815
|
+
expect(fs.existsSync("./package.json")).toBe(true);
|
|
816
|
+
expect(fs.existsSync("./wrangler.toml")).toBe(true);
|
|
263
817
|
});
|
|
264
818
|
|
|
265
819
|
it("should error if `--type javascript` is used", async () => {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
820
|
+
await expect(
|
|
821
|
+
runWrangler("init --type javascript")
|
|
822
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
823
|
+
`"The --type option is no longer supported."`
|
|
269
824
|
);
|
|
270
825
|
});
|
|
271
826
|
|
|
272
827
|
it("should error if `--type rust` is used", async () => {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
828
|
+
await expect(
|
|
829
|
+
runWrangler("init --type rust")
|
|
830
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
831
|
+
`"The --type option is no longer supported."`
|
|
276
832
|
);
|
|
277
833
|
});
|
|
278
834
|
|
|
279
835
|
it("should error if `--type webpack` is used", async () => {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
836
|
+
await expect(runWrangler("init --type webpack")).rejects
|
|
837
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
838
|
+
"The --type option is no longer supported.
|
|
839
|
+
If you wish to use webpack then you will need to create a custom build."
|
|
840
|
+
`);
|
|
841
|
+
});
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
describe("preview", () => {
|
|
845
|
+
it("should throw an error if the deprecated command is used with positional arguments", async () => {
|
|
846
|
+
await expect(runWrangler("preview GET")).rejects
|
|
847
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
848
|
+
"🦺 DEPRECATION:
|
|
849
|
+
The \`wrangler preview\` command has been deprecated.
|
|
850
|
+
Try using \`wrangler dev\` to to try out a worker during development.
|
|
851
|
+
"
|
|
852
|
+
`);
|
|
853
|
+
await expect(runWrangler(`preview GET "SomeBody"`)).rejects
|
|
854
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
855
|
+
"🦺 DEPRECATION:
|
|
856
|
+
The \`wrangler preview\` command has been deprecated.
|
|
857
|
+
Try using \`wrangler dev\` to to try out a worker during development.
|
|
858
|
+
"
|
|
859
|
+
`);
|
|
860
|
+
});
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
describe("subcommand implicit help ran on imcomplete command execution", () => {
|
|
864
|
+
function endEventLoop() {
|
|
865
|
+
return new Promise((resolve) => setImmediate(resolve));
|
|
866
|
+
}
|
|
867
|
+
it("no subcommand for 'secret' should display a list of available subcommands", async () => {
|
|
868
|
+
await runWrangler("secret");
|
|
869
|
+
await endEventLoop();
|
|
870
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
871
|
+
"wrangler secret
|
|
872
|
+
|
|
873
|
+
🤫 Generate a secret that can be referenced in the worker script
|
|
874
|
+
|
|
875
|
+
Commands:
|
|
876
|
+
wrangler secret put <key> Create or update a secret variable for a script
|
|
877
|
+
wrangler secret delete <key> Delete a secret variable from a script
|
|
878
|
+
wrangler secret list List all secrets for a script
|
|
879
|
+
|
|
880
|
+
Flags:
|
|
881
|
+
-c, --config Path to .toml configuration file [string]
|
|
882
|
+
-h, --help Show help [boolean]
|
|
883
|
+
-v, --version Show version number [boolean]
|
|
884
|
+
--legacy-env Use legacy environments [boolean]"
|
|
885
|
+
`);
|
|
886
|
+
});
|
|
887
|
+
|
|
888
|
+
it("no subcommand 'kv:namespace' should display a list of available subcommands", async () => {
|
|
889
|
+
await runWrangler("kv:namespace");
|
|
890
|
+
await endEventLoop();
|
|
891
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
892
|
+
"wrangler kv:namespace
|
|
893
|
+
|
|
894
|
+
🗂️ Interact with your Workers KV Namespaces
|
|
895
|
+
|
|
896
|
+
Commands:
|
|
897
|
+
wrangler kv:namespace create <namespace> Create a new namespace
|
|
898
|
+
wrangler kv:namespace list Outputs a list of all KV namespaces associated with your account id.
|
|
899
|
+
wrangler kv:namespace delete Deletes a given namespace.
|
|
900
|
+
|
|
901
|
+
Flags:
|
|
902
|
+
-c, --config Path to .toml configuration file [string]
|
|
903
|
+
-h, --help Show help [boolean]
|
|
904
|
+
-v, --version Show version number [boolean]
|
|
905
|
+
--legacy-env Use legacy environments [boolean]"
|
|
284
906
|
`);
|
|
285
907
|
});
|
|
908
|
+
|
|
909
|
+
it("no subcommand 'kv:key' should display a list of available subcommands", async () => {
|
|
910
|
+
await runWrangler("kv:key");
|
|
911
|
+
await endEventLoop();
|
|
912
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
913
|
+
"wrangler kv:key
|
|
914
|
+
|
|
915
|
+
🔑 Individually manage Workers KV key-value pairs
|
|
916
|
+
|
|
917
|
+
Commands:
|
|
918
|
+
wrangler kv:key put <key> [value] Writes a single key/value pair to the given namespace.
|
|
919
|
+
wrangler kv:key list Outputs a list of all keys in a given namespace.
|
|
920
|
+
wrangler kv:key get <key> Reads a single value by key from the given namespace.
|
|
921
|
+
wrangler kv:key delete <key> Removes a single key value pair from the given namespace.
|
|
922
|
+
|
|
923
|
+
Flags:
|
|
924
|
+
-c, --config Path to .toml configuration file [string]
|
|
925
|
+
-h, --help Show help [boolean]
|
|
926
|
+
-v, --version Show version number [boolean]
|
|
927
|
+
--legacy-env Use legacy environments [boolean]"
|
|
928
|
+
`);
|
|
929
|
+
});
|
|
930
|
+
|
|
931
|
+
it("no subcommand 'kv:bulk' should display a list of available subcommands", async () => {
|
|
932
|
+
await runWrangler("kv:bulk");
|
|
933
|
+
await endEventLoop();
|
|
934
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
935
|
+
"wrangler kv:bulk
|
|
936
|
+
|
|
937
|
+
💪 Interact with multiple Workers KV key-value pairs at once
|
|
938
|
+
|
|
939
|
+
Commands:
|
|
940
|
+
wrangler kv:bulk put <filename> Upload multiple key-value pairs to a namespace
|
|
941
|
+
wrangler kv:bulk delete <filename> Delete multiple key-value pairs from a namespace
|
|
942
|
+
|
|
943
|
+
Flags:
|
|
944
|
+
-c, --config Path to .toml configuration file [string]
|
|
945
|
+
-h, --help Show help [boolean]
|
|
946
|
+
-v, --version Show version number [boolean]
|
|
947
|
+
--legacy-env Use legacy environments [boolean]"
|
|
948
|
+
`);
|
|
949
|
+
});
|
|
950
|
+
it("no subcommand 'r2' should display a list of available subcommands", async () => {
|
|
951
|
+
await runWrangler("r2");
|
|
952
|
+
await endEventLoop();
|
|
953
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
954
|
+
"wrangler r2
|
|
955
|
+
|
|
956
|
+
📦 Interact with an R2 store
|
|
957
|
+
|
|
958
|
+
Commands:
|
|
959
|
+
wrangler r2 bucket Manage R2 buckets
|
|
960
|
+
|
|
961
|
+
Flags:
|
|
962
|
+
-c, --config Path to .toml configuration file [string]
|
|
963
|
+
-h, --help Show help [boolean]
|
|
964
|
+
-v, --version Show version number [boolean]
|
|
965
|
+
--legacy-env Use legacy environments [boolean]"
|
|
966
|
+
`);
|
|
967
|
+
});
|
|
968
|
+
});
|
|
969
|
+
describe("Deprecated commands", () => {
|
|
970
|
+
it("should print a deprecation message for 'generate'", async () => {
|
|
971
|
+
await runWrangler("generate").catch((err) => {
|
|
972
|
+
expect(err.message).toMatchInlineSnapshot(`
|
|
973
|
+
"🦺 DEPRECATION:
|
|
974
|
+
\`wrangler generate\` has been deprecated, please refer to https://github.com/cloudflare/wrangler2/blob/main/docs/deprecations.md#generate for alternatives"
|
|
975
|
+
`);
|
|
976
|
+
});
|
|
977
|
+
});
|
|
978
|
+
it("should print a deprecation message for 'build'", async () => {
|
|
979
|
+
await runWrangler("build").catch((err) => {
|
|
980
|
+
expect(err.message).toMatchInlineSnapshot(`
|
|
981
|
+
"🦺 DEPRECATION:
|
|
982
|
+
\`wrangler build\` has been deprecated, please refer to https://github.com/cloudflare/wrangler2/blob/main/docs/deprecations.md#build for alternatives"
|
|
983
|
+
`);
|
|
984
|
+
});
|
|
985
|
+
});
|
|
286
986
|
});
|
|
287
987
|
});
|