wrangler 0.0.0-e2a26a0 → 0.0.0-e2b7352
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 +10 -1
- package/miniflare-dist/index.mjs +79 -0
- package/miniflare-dist/index.mjs.map +7 -0
- package/package.json +24 -12
- package/pages/functions/filepath-routing.test.ts +212 -36
- package/pages/functions/filepath-routing.ts +69 -119
- package/pages/functions/routes.ts +8 -17
- package/pages/functions/template-worker.ts +3 -9
- package/src/__tests__/configuration.test.ts +2820 -0
- package/src/__tests__/dev.test.tsx +535 -65
- package/src/__tests__/guess-worker-format.test.ts +68 -0
- package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +26 -8
- package/src/__tests__/helpers/mock-bin.ts +4 -1
- package/src/__tests__/helpers/mock-cfetch.ts +5 -5
- package/src/__tests__/helpers/mock-console.ts +21 -7
- package/src/__tests__/helpers/mock-kv.ts +9 -16
- 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 +3 -0
- package/src/__tests__/helpers/run-wrangler.ts +5 -3
- 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 +467 -27
- package/src/__tests__/jest.setup.ts +37 -5
- package/src/__tests__/kv.test.ts +442 -201
- package/src/__tests__/logout.test.ts +15 -13
- package/src/__tests__/package-manager.test.ts +2 -2
- package/src/__tests__/pages.test.ts +82 -0
- package/src/__tests__/parse.test.ts +322 -0
- package/src/__tests__/publish.test.ts +2717 -430
- package/src/__tests__/r2.test.ts +198 -0
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +301 -86
- package/src/__tests__/sentry.test.ts +146 -0
- package/src/__tests__/tail.test.ts +638 -0
- package/src/__tests__/whoami.test.tsx +21 -7
- package/src/bundle.ts +155 -0
- package/src/cfetch/index.ts +8 -6
- package/src/cfetch/internal.ts +60 -22
- package/src/cli.ts +10 -0
- package/src/config/README.md +107 -0
- package/src/config/config.ts +218 -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 +554 -0
- package/src/config/validation.ts +1232 -0
- package/src/{api/preview.ts → create-worker-preview.ts} +59 -21
- package/src/create-worker-upload-form.ts +217 -0
- package/src/dev/dev.tsx +392 -0
- package/src/dev/local.tsx +232 -0
- package/src/dev/remote.tsx +203 -0
- package/src/dev/use-esbuild.ts +104 -0
- package/src/entry.ts +240 -0
- package/src/environment-variables.ts +33 -0
- package/src/https-options.ts +122 -0
- package/src/index.tsx +1068 -780
- package/src/inspect.ts +25 -4
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv.tsx → kv.ts} +95 -60
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +37 -0
- package/src/module-collection.ts +226 -31
- package/src/open-in-browser.ts +25 -0
- package/src/package-manager.ts +21 -15
- package/src/pages.tsx +35 -20
- package/src/parse.ts +183 -0
- package/src/proxy.ts +115 -45
- package/src/publish.ts +268 -328
- package/src/r2.ts +50 -0
- package/src/reporting.ts +131 -0
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +83 -43
- 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 +234 -126
- package/src/{api/worker.ts → worker.ts} +44 -36
- package/templates/new-worker.js +1 -1
- package/templates/new-worker.ts +1 -1
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +131202 -114243
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/api/form_data.ts +0 -134
- package/src/config.ts +0 -641
- package/src/dev.tsx +0 -834
- package/src/tail.tsx +0 -73
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as fsp from "node:fs/promises";
|
|
3
3
|
import * as TOML from "@iarna/toml";
|
|
4
|
+
import { parseConfigFileTextToJson } from "typescript";
|
|
4
5
|
import { version as wranglerVersion } from "../../package.json";
|
|
5
6
|
import { getPackageManager } from "../package-manager";
|
|
6
7
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
@@ -15,6 +16,9 @@ describe("wrangler", () => {
|
|
|
15
16
|
|
|
16
17
|
beforeEach(() => {
|
|
17
18
|
mockPackageManager = {
|
|
19
|
+
cwd: process.cwd(),
|
|
20
|
+
// @ts-expect-error we're making a fake package manager here
|
|
21
|
+
type: "mockpm",
|
|
18
22
|
addDevDeps: jest.fn(),
|
|
19
23
|
install: jest.fn(),
|
|
20
24
|
};
|
|
@@ -33,22 +37,21 @@ describe("wrangler", () => {
|
|
|
33
37
|
Commands:
|
|
34
38
|
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
35
39
|
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
36
|
-
wrangler dev
|
|
40
|
+
wrangler dev [script] 👂 Start a local server for developing your worker
|
|
37
41
|
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
38
|
-
wrangler tail [name] 🦚 Starts a log tailing session for a
|
|
42
|
+
wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
|
|
39
43
|
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
|
|
40
44
|
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
|
|
41
45
|
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
|
|
42
46
|
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
43
47
|
wrangler pages ⚡️ Configure Cloudflare Pages
|
|
48
|
+
wrangler r2 📦 Interact with an R2 store
|
|
44
49
|
|
|
45
50
|
Flags:
|
|
46
|
-
-c, --config
|
|
47
|
-
-h, --help
|
|
48
|
-
-v, --version
|
|
49
|
-
|
|
50
|
-
Options:
|
|
51
|
-
-l, --local Run on my machine [boolean] [default: false]"
|
|
51
|
+
-c, --config Path to .toml configuration file [string]
|
|
52
|
+
-h, --help Show help [boolean]
|
|
53
|
+
-v, --version Show version number [boolean]
|
|
54
|
+
--legacy-env Use legacy environments [boolean]"
|
|
52
55
|
`);
|
|
53
56
|
|
|
54
57
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
@@ -60,7 +63,7 @@ describe("wrangler", () => {
|
|
|
60
63
|
await expect(
|
|
61
64
|
runWrangler("invalid-command")
|
|
62
65
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
63
|
-
`"Unknown
|
|
66
|
+
`"Unknown argument: invalid-command"`
|
|
64
67
|
);
|
|
65
68
|
|
|
66
69
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
@@ -70,24 +73,23 @@ describe("wrangler", () => {
|
|
|
70
73
|
Commands:
|
|
71
74
|
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
72
75
|
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
73
|
-
wrangler dev
|
|
76
|
+
wrangler dev [script] 👂 Start a local server for developing your worker
|
|
74
77
|
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
75
|
-
wrangler tail [name] 🦚 Starts a log tailing session for a
|
|
78
|
+
wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
|
|
76
79
|
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
|
|
77
80
|
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
|
|
78
81
|
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
|
|
79
82
|
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
80
83
|
wrangler pages ⚡️ Configure Cloudflare Pages
|
|
84
|
+
wrangler r2 📦 Interact with an R2 store
|
|
81
85
|
|
|
82
86
|
Flags:
|
|
83
|
-
-c, --config
|
|
84
|
-
-h, --help
|
|
85
|
-
-v, --version
|
|
86
|
-
|
|
87
|
-
Options:
|
|
88
|
-
-l, --local Run on my machine [boolean] [default: false]
|
|
87
|
+
-c, --config Path to .toml configuration file [string]
|
|
88
|
+
-h, --help Show help [boolean]
|
|
89
|
+
-v, --version Show version number [boolean]
|
|
90
|
+
--legacy-env Use legacy environments [boolean]
|
|
89
91
|
|
|
90
|
-
Unknown
|
|
92
|
+
Unknown argument: invalid-command"
|
|
91
93
|
`);
|
|
92
94
|
});
|
|
93
95
|
});
|
|
@@ -101,10 +103,26 @@ describe("wrangler", () => {
|
|
|
101
103
|
await runWrangler("init");
|
|
102
104
|
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
103
105
|
expect(typeof parsed.compatibility_date).toBe("string");
|
|
106
|
+
expect(parsed.name).toContain("wrangler-tests");
|
|
104
107
|
expect(fs.existsSync("./package.json")).toBe(false);
|
|
105
108
|
expect(fs.existsSync("./tsconfig.json")).toBe(false);
|
|
106
109
|
});
|
|
107
110
|
|
|
111
|
+
it("should create a wrangler.toml and a directory for a named Worker ", async () => {
|
|
112
|
+
mockConfirm({
|
|
113
|
+
text: "No package.json found. Would you like to create one?",
|
|
114
|
+
result: false,
|
|
115
|
+
});
|
|
116
|
+
await runWrangler("init my-worker");
|
|
117
|
+
const parsed = TOML.parse(
|
|
118
|
+
await fsp.readFile("./my-worker/wrangler.toml", "utf-8")
|
|
119
|
+
);
|
|
120
|
+
expect(typeof parsed.compatibility_date).toBe("string");
|
|
121
|
+
expect(parsed.name).toBe("my-worker");
|
|
122
|
+
expect(fs.existsSync("./my-worker/package.json")).toBe(false);
|
|
123
|
+
expect(fs.existsSync("./my-worker/tsconfig.json")).toBe(false);
|
|
124
|
+
});
|
|
125
|
+
|
|
108
126
|
it("should display warning when wrangler.toml already exists, and exit if user does not want to carry on", async () => {
|
|
109
127
|
fs.writeFileSync(
|
|
110
128
|
"./wrangler.toml",
|
|
@@ -121,6 +139,37 @@ describe("wrangler", () => {
|
|
|
121
139
|
expect(parsed.compatibility_date).toBe("something-else");
|
|
122
140
|
});
|
|
123
141
|
|
|
142
|
+
it("should not overwrite an existing wrangler.toml, after agreeing to other prompts", async () => {
|
|
143
|
+
fs.writeFileSync(
|
|
144
|
+
"./wrangler.toml",
|
|
145
|
+
'compatibility_date="something-else"', // use a fake value to make sure the file is not overwritten
|
|
146
|
+
"utf-8"
|
|
147
|
+
);
|
|
148
|
+
mockConfirm(
|
|
149
|
+
{
|
|
150
|
+
text: "Do you want to continue initializing this project?",
|
|
151
|
+
result: true,
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
text: "No package.json found. Would you like to create one?",
|
|
155
|
+
result: true,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
text: "Would you like to use TypeScript?",
|
|
159
|
+
result: true,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
163
|
+
result: true,
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
await runWrangler("init");
|
|
168
|
+
expect(fs.readFileSync("./wrangler.toml", "utf-8")).toMatchInlineSnapshot(
|
|
169
|
+
`"compatibility_date=\\"something-else\\""`
|
|
170
|
+
);
|
|
171
|
+
});
|
|
172
|
+
|
|
124
173
|
it("should display warning when wrangler.toml already exists, but continue if user does want to carry on", async () => {
|
|
125
174
|
fs.writeFileSync(
|
|
126
175
|
"./wrangler.toml",
|
|
@@ -163,7 +212,7 @@ describe("wrangler", () => {
|
|
|
163
212
|
const packageJson = JSON.parse(
|
|
164
213
|
fs.readFileSync("./package.json", "utf-8")
|
|
165
214
|
);
|
|
166
|
-
expect(packageJson.name).
|
|
215
|
+
expect(packageJson.name).toContain("wrangler-tests");
|
|
167
216
|
expect(packageJson.version).toEqual("0.0.0");
|
|
168
217
|
expect(packageJson.devDependencies).toEqual({
|
|
169
218
|
wrangler: expect.any(String),
|
|
@@ -172,6 +221,28 @@ describe("wrangler", () => {
|
|
|
172
221
|
expect(mockPackageManager.install).toHaveBeenCalled();
|
|
173
222
|
});
|
|
174
223
|
|
|
224
|
+
it("should create a package.json, with the specified name, if none is found and user confirms", async () => {
|
|
225
|
+
mockConfirm(
|
|
226
|
+
{
|
|
227
|
+
text: "No package.json found. Would you like to create one?",
|
|
228
|
+
result: true,
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
text: "Would you like to use TypeScript?",
|
|
232
|
+
result: false,
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
236
|
+
result: false,
|
|
237
|
+
}
|
|
238
|
+
);
|
|
239
|
+
await runWrangler("init my-worker");
|
|
240
|
+
const packageJson = JSON.parse(
|
|
241
|
+
fs.readFileSync("./my-worker/package.json", "utf-8")
|
|
242
|
+
);
|
|
243
|
+
expect(packageJson.name).toBe("my-worker");
|
|
244
|
+
});
|
|
245
|
+
|
|
175
246
|
it("should not touch an existing package.json in the same directory", async () => {
|
|
176
247
|
mockConfirm(
|
|
177
248
|
{
|
|
@@ -329,6 +400,180 @@ describe("wrangler", () => {
|
|
|
329
400
|
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
330
401
|
});
|
|
331
402
|
|
|
403
|
+
it("should add scripts for a typescript project with .ts extension", async () => {
|
|
404
|
+
mockConfirm(
|
|
405
|
+
{
|
|
406
|
+
text: "No package.json found. Would you like to create one?",
|
|
407
|
+
result: true,
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
411
|
+
result: false,
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
text: "Would you like to use TypeScript?",
|
|
415
|
+
result: true,
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
419
|
+
result: true,
|
|
420
|
+
}
|
|
421
|
+
);
|
|
422
|
+
await runWrangler("init");
|
|
423
|
+
|
|
424
|
+
expect(fs.existsSync("./package.json")).toBe(true);
|
|
425
|
+
const packageJson = JSON.parse(
|
|
426
|
+
fs.readFileSync("./package.json", "utf-8")
|
|
427
|
+
);
|
|
428
|
+
|
|
429
|
+
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
430
|
+
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
431
|
+
|
|
432
|
+
expect(packageJson.scripts.start).toBe("wrangler dev");
|
|
433
|
+
expect(packageJson.scripts.publish).toBe("wrangler publish");
|
|
434
|
+
expect(packageJson.name).toContain("wrangler-tests");
|
|
435
|
+
expect(packageJson.version).toEqual("0.0.0");
|
|
436
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
437
|
+
"✨ Successfully created wrangler.toml
|
|
438
|
+
✨ Created package.json
|
|
439
|
+
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
440
|
+
✨ Created src/index.ts
|
|
441
|
+
|
|
442
|
+
To start developing your Worker, run \`npm start\`
|
|
443
|
+
To publish your Worker to the Internet, run \`npm run publish\`"
|
|
444
|
+
`);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it("should not overwrite package.json scripts for a typescript project", async () => {
|
|
448
|
+
mockConfirm(
|
|
449
|
+
{
|
|
450
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
451
|
+
result: false,
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
text: "Would you like to use TypeScript?",
|
|
455
|
+
result: true,
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
459
|
+
result: true,
|
|
460
|
+
}
|
|
461
|
+
);
|
|
462
|
+
await fsp.writeFile(
|
|
463
|
+
"./package.json",
|
|
464
|
+
JSON.stringify({
|
|
465
|
+
scripts: {
|
|
466
|
+
start: "test-start",
|
|
467
|
+
publish: "test-publish",
|
|
468
|
+
},
|
|
469
|
+
})
|
|
470
|
+
);
|
|
471
|
+
const packageJson = JSON.parse(
|
|
472
|
+
fs.readFileSync("./package.json", "utf-8")
|
|
473
|
+
);
|
|
474
|
+
await runWrangler("init");
|
|
475
|
+
|
|
476
|
+
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
477
|
+
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
478
|
+
|
|
479
|
+
expect(packageJson.scripts.start).toBe("test-start");
|
|
480
|
+
expect(packageJson.scripts.publish).toBe("test-publish");
|
|
481
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
482
|
+
"✨ Successfully created wrangler.toml
|
|
483
|
+
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
484
|
+
✨ Created src/index.ts
|
|
485
|
+
|
|
486
|
+
To start developing your Worker, run \`npx wrangler dev\`
|
|
487
|
+
To publish your Worker to the Internet, run \`npx wrangler publish\`"
|
|
488
|
+
`);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
it("should add missing scripts for a non-ts project with .js extension", async () => {
|
|
492
|
+
mockConfirm(
|
|
493
|
+
{
|
|
494
|
+
text: "No package.json found. Would you like to create one?",
|
|
495
|
+
result: true,
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
499
|
+
result: false,
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
text: "Would you like to use TypeScript?",
|
|
503
|
+
result: false,
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
507
|
+
result: true,
|
|
508
|
+
}
|
|
509
|
+
);
|
|
510
|
+
await runWrangler("init");
|
|
511
|
+
|
|
512
|
+
expect(fs.existsSync("./package.json")).toBe(true);
|
|
513
|
+
const packageJson = JSON.parse(
|
|
514
|
+
fs.readFileSync("./package.json", "utf-8")
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
expect(fs.existsSync("./src/index.js")).toBe(true);
|
|
518
|
+
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
519
|
+
|
|
520
|
+
expect(packageJson.scripts.start).toBe("wrangler dev");
|
|
521
|
+
expect(packageJson.scripts.publish).toBe("wrangler publish");
|
|
522
|
+
expect(packageJson.name).toContain("wrangler-tests");
|
|
523
|
+
expect(packageJson.version).toEqual("0.0.0");
|
|
524
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
525
|
+
"✨ Successfully created wrangler.toml
|
|
526
|
+
✨ Created package.json
|
|
527
|
+
✨ Created src/index.js
|
|
528
|
+
|
|
529
|
+
To start developing your Worker, run \`npm start\`
|
|
530
|
+
To publish your Worker to the Internet, run \`npm run publish\`"
|
|
531
|
+
`);
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
it("should not overwrite package.json scripts for a non-ts project with .js extension", async () => {
|
|
535
|
+
mockConfirm(
|
|
536
|
+
{
|
|
537
|
+
text: "Would you like to install wrangler into your package.json?",
|
|
538
|
+
result: false,
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
text: "Would you like to use TypeScript?",
|
|
542
|
+
result: false,
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
546
|
+
result: true,
|
|
547
|
+
}
|
|
548
|
+
);
|
|
549
|
+
await fsp.writeFile(
|
|
550
|
+
"./package.json",
|
|
551
|
+
JSON.stringify({
|
|
552
|
+
scripts: {
|
|
553
|
+
start: "test-start",
|
|
554
|
+
publish: "test-publish",
|
|
555
|
+
},
|
|
556
|
+
})
|
|
557
|
+
);
|
|
558
|
+
const packageJson = JSON.parse(
|
|
559
|
+
fs.readFileSync("./package.json", "utf-8")
|
|
560
|
+
);
|
|
561
|
+
await runWrangler("init");
|
|
562
|
+
|
|
563
|
+
expect(fs.existsSync("./src/index.js")).toBe(true);
|
|
564
|
+
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
565
|
+
|
|
566
|
+
expect(packageJson.scripts.start).toBe("test-start");
|
|
567
|
+
expect(packageJson.scripts.publish).toBe("test-publish");
|
|
568
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
569
|
+
"✨ Successfully created wrangler.toml
|
|
570
|
+
✨ Created src/index.js
|
|
571
|
+
|
|
572
|
+
To start developing your Worker, run \`npx wrangler dev\`
|
|
573
|
+
To publish your Worker to the Internet, run \`npx wrangler publish\`"
|
|
574
|
+
`);
|
|
575
|
+
});
|
|
576
|
+
|
|
332
577
|
it("should not offer to create a worker in a non-ts project if a file already exists at the location", async () => {
|
|
333
578
|
mockConfirm(
|
|
334
579
|
{
|
|
@@ -398,9 +643,12 @@ describe("wrangler", () => {
|
|
|
398
643
|
);
|
|
399
644
|
await runWrangler("init");
|
|
400
645
|
expect(fs.existsSync("./tsconfig.json")).toBe(true);
|
|
401
|
-
const tsconfigJson =
|
|
402
|
-
|
|
403
|
-
|
|
646
|
+
const { config: tsconfigJson, error: tsConfigParseError } =
|
|
647
|
+
parseConfigFileTextToJson(
|
|
648
|
+
"./tsconfig.json",
|
|
649
|
+
fs.readFileSync("./tsconfig.json", "utf-8")
|
|
650
|
+
);
|
|
651
|
+
expect(tsConfigParseError).toBeUndefined();
|
|
404
652
|
expect(tsconfigJson.compilerOptions.types).toEqual([
|
|
405
653
|
"@cloudflare/workers-types",
|
|
406
654
|
]);
|
|
@@ -508,12 +756,60 @@ describe("wrangler", () => {
|
|
|
508
756
|
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
509
757
|
});
|
|
510
758
|
|
|
511
|
-
it("should
|
|
512
|
-
await
|
|
513
|
-
|
|
514
|
-
).
|
|
515
|
-
|
|
759
|
+
it("should initialize with no interactive prompts if `--yes` is used", async () => {
|
|
760
|
+
await runWrangler("init --yes");
|
|
761
|
+
|
|
762
|
+
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
763
|
+
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
764
|
+
expect(fs.existsSync("./tsconfig.json")).toBe(true);
|
|
765
|
+
expect(fs.existsSync("./package.json")).toBe(true);
|
|
766
|
+
expect(fs.existsSync("./wrangler.toml")).toBe(true);
|
|
767
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
768
|
+
"✨ Successfully created wrangler.toml
|
|
769
|
+
✨ Created package.json
|
|
770
|
+
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
771
|
+
✨ Created src/index.ts
|
|
772
|
+
|
|
773
|
+
To start developing your Worker, run \`npm start\`
|
|
774
|
+
To publish your Worker to the Internet, run \`npm run publish\`"
|
|
775
|
+
`);
|
|
776
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
777
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
it("should initialize with no interactive prompts if `--yes` is used (named worker)", async () => {
|
|
781
|
+
await runWrangler("init my-worker --yes");
|
|
782
|
+
|
|
783
|
+
expect(fs.existsSync("./my-worker/src/index.js")).toBe(false);
|
|
784
|
+
expect(fs.existsSync("./my-worker/src/index.ts")).toBe(true);
|
|
785
|
+
expect(fs.existsSync("./my-worker/tsconfig.json")).toBe(true);
|
|
786
|
+
expect(fs.existsSync("./my-worker/package.json")).toBe(true);
|
|
787
|
+
expect(fs.existsSync("./my-worker/wrangler.toml")).toBe(true);
|
|
788
|
+
const parsedWranglerToml = TOML.parse(
|
|
789
|
+
fs.readFileSync("./my-worker/wrangler.toml", "utf-8")
|
|
516
790
|
);
|
|
791
|
+
expect(parsedWranglerToml.main).toEqual("src/index.ts");
|
|
792
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
793
|
+
"✨ Successfully created wrangler.toml
|
|
794
|
+
✨ Created package.json
|
|
795
|
+
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
796
|
+
✨ Created src/index.ts
|
|
797
|
+
|
|
798
|
+
To start developing your Worker, run \`cd my-worker && npm start\`
|
|
799
|
+
To publish your Worker to the Internet, run \`npm run publish\`"
|
|
800
|
+
`);
|
|
801
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
802
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
it("should initialize with no interactive prompts if `-y` is used", async () => {
|
|
806
|
+
await runWrangler("init -y");
|
|
807
|
+
|
|
808
|
+
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
809
|
+
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
810
|
+
expect(fs.existsSync("./tsconfig.json")).toBe(true);
|
|
811
|
+
expect(fs.existsSync("./package.json")).toBe(true);
|
|
812
|
+
expect(fs.existsSync("./wrangler.toml")).toBe(true);
|
|
517
813
|
});
|
|
518
814
|
|
|
519
815
|
it("should error if `--type javascript` is used", async () => {
|
|
@@ -540,4 +836,148 @@ describe("wrangler", () => {
|
|
|
540
836
|
`);
|
|
541
837
|
});
|
|
542
838
|
});
|
|
839
|
+
|
|
840
|
+
describe("preview", () => {
|
|
841
|
+
it("should throw an error if the deprecated command is used with positional arguments", async () => {
|
|
842
|
+
await expect(runWrangler("preview GET")).rejects
|
|
843
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
844
|
+
"DEPRECATION WARNING:
|
|
845
|
+
The \`wrangler preview\` command has been deprecated.
|
|
846
|
+
Try using \`wrangler dev\` to to try out a worker during development.
|
|
847
|
+
"
|
|
848
|
+
`);
|
|
849
|
+
await expect(runWrangler(`preview GET "SomeBody"`)).rejects
|
|
850
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
851
|
+
"DEPRECATION WARNING:
|
|
852
|
+
The \`wrangler preview\` command has been deprecated.
|
|
853
|
+
Try using \`wrangler dev\` to to try out a worker during development.
|
|
854
|
+
"
|
|
855
|
+
`);
|
|
856
|
+
});
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
describe("subcommand implicit help ran on imcomplete command execution", () => {
|
|
860
|
+
function endEventLoop() {
|
|
861
|
+
return new Promise((resolve) => setImmediate(resolve));
|
|
862
|
+
}
|
|
863
|
+
it("no subcommand for 'secret' should display a list of available subcommands", async () => {
|
|
864
|
+
await runWrangler("secret");
|
|
865
|
+
await endEventLoop();
|
|
866
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
867
|
+
"wrangler secret
|
|
868
|
+
|
|
869
|
+
🤫 Generate a secret that can be referenced in the worker script
|
|
870
|
+
|
|
871
|
+
Commands:
|
|
872
|
+
wrangler secret put <key> Create or update a secret variable for a script
|
|
873
|
+
wrangler secret delete <key> Delete a secret variable from a script
|
|
874
|
+
wrangler secret list List all secrets for a script
|
|
875
|
+
|
|
876
|
+
Flags:
|
|
877
|
+
-c, --config Path to .toml configuration file [string]
|
|
878
|
+
-h, --help Show help [boolean]
|
|
879
|
+
-v, --version Show version number [boolean]
|
|
880
|
+
--legacy-env Use legacy environments [boolean]"
|
|
881
|
+
`);
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
it("no subcommand 'kv:namespace' should display a list of available subcommands", async () => {
|
|
885
|
+
await runWrangler("kv:namespace");
|
|
886
|
+
await endEventLoop();
|
|
887
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
888
|
+
"wrangler kv:namespace
|
|
889
|
+
|
|
890
|
+
🗂️ Interact with your Workers KV Namespaces
|
|
891
|
+
|
|
892
|
+
Commands:
|
|
893
|
+
wrangler kv:namespace create <namespace> Create a new namespace
|
|
894
|
+
wrangler kv:namespace list Outputs a list of all KV namespaces associated with your account id.
|
|
895
|
+
wrangler kv:namespace delete Deletes a given namespace.
|
|
896
|
+
|
|
897
|
+
Flags:
|
|
898
|
+
-c, --config Path to .toml configuration file [string]
|
|
899
|
+
-h, --help Show help [boolean]
|
|
900
|
+
-v, --version Show version number [boolean]
|
|
901
|
+
--legacy-env Use legacy environments [boolean]"
|
|
902
|
+
`);
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
it("no subcommand 'kv:key' should display a list of available subcommands", async () => {
|
|
906
|
+
await runWrangler("kv:key");
|
|
907
|
+
await endEventLoop();
|
|
908
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
909
|
+
"wrangler kv:key
|
|
910
|
+
|
|
911
|
+
🔑 Individually manage Workers KV key-value pairs
|
|
912
|
+
|
|
913
|
+
Commands:
|
|
914
|
+
wrangler kv:key put <key> [value] Writes a single key/value pair to the given namespace.
|
|
915
|
+
wrangler kv:key list Outputs a list of all keys in a given namespace.
|
|
916
|
+
wrangler kv:key get <key> Reads a single value by key from the given namespace.
|
|
917
|
+
wrangler kv:key delete <key> Removes a single key value pair from the given namespace.
|
|
918
|
+
|
|
919
|
+
Flags:
|
|
920
|
+
-c, --config Path to .toml configuration file [string]
|
|
921
|
+
-h, --help Show help [boolean]
|
|
922
|
+
-v, --version Show version number [boolean]
|
|
923
|
+
--legacy-env Use legacy environments [boolean]"
|
|
924
|
+
`);
|
|
925
|
+
});
|
|
926
|
+
|
|
927
|
+
it("no subcommand 'kv:bulk' should display a list of available subcommands", async () => {
|
|
928
|
+
await runWrangler("kv:bulk");
|
|
929
|
+
await endEventLoop();
|
|
930
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
931
|
+
"wrangler kv:bulk
|
|
932
|
+
|
|
933
|
+
💪 Interact with multiple Workers KV key-value pairs at once
|
|
934
|
+
|
|
935
|
+
Commands:
|
|
936
|
+
wrangler kv:bulk put <filename> Upload multiple key-value pairs to a namespace
|
|
937
|
+
wrangler kv:bulk delete <filename> Delete multiple key-value pairs from a namespace
|
|
938
|
+
|
|
939
|
+
Flags:
|
|
940
|
+
-c, --config Path to .toml configuration file [string]
|
|
941
|
+
-h, --help Show help [boolean]
|
|
942
|
+
-v, --version Show version number [boolean]
|
|
943
|
+
--legacy-env Use legacy environments [boolean]"
|
|
944
|
+
`);
|
|
945
|
+
});
|
|
946
|
+
it("no subcommand 'r2' should display a list of available subcommands", async () => {
|
|
947
|
+
await runWrangler("r2");
|
|
948
|
+
await endEventLoop();
|
|
949
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
950
|
+
"wrangler r2
|
|
951
|
+
|
|
952
|
+
📦 Interact with an R2 store
|
|
953
|
+
|
|
954
|
+
Commands:
|
|
955
|
+
wrangler r2 bucket Manage R2 buckets
|
|
956
|
+
|
|
957
|
+
Flags:
|
|
958
|
+
-c, --config Path to .toml configuration file [string]
|
|
959
|
+
-h, --help Show help [boolean]
|
|
960
|
+
-v, --version Show version number [boolean]
|
|
961
|
+
--legacy-env Use legacy environments [boolean]"
|
|
962
|
+
`);
|
|
963
|
+
});
|
|
964
|
+
});
|
|
965
|
+
describe("Deprecated commands", () => {
|
|
966
|
+
it("should print a deprecation message for 'generate'", async () => {
|
|
967
|
+
await runWrangler("generate").catch((err) => {
|
|
968
|
+
expect(err.message).toMatchInlineSnapshot(`
|
|
969
|
+
"DEPRECATION WARNING:
|
|
970
|
+
\`wrangler generate\` has been deprecated, please refer to https://github.com/cloudflare/wrangler2/blob/main/docs/deprecations.md#generate for alternatives"
|
|
971
|
+
`);
|
|
972
|
+
});
|
|
973
|
+
});
|
|
974
|
+
it("should print a deprecation message for 'build'", async () => {
|
|
975
|
+
await runWrangler("build").catch((err) => {
|
|
976
|
+
expect(err.message).toMatchInlineSnapshot(`
|
|
977
|
+
"DEPRECATION WARNING:
|
|
978
|
+
\`wrangler build\` has been deprecated, please refer to https://github.com/cloudflare/wrangler2/blob/main/docs/deprecations.md#build for alternatives"
|
|
979
|
+
`);
|
|
980
|
+
});
|
|
981
|
+
});
|
|
982
|
+
});
|
|
543
983
|
});
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import fetchMock from "jest-fetch-mock";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
fetchInternal,
|
|
4
|
+
fetchKVGetValue,
|
|
5
|
+
getCloudflareAPIBaseURL,
|
|
6
|
+
} from "../cfetch/internal";
|
|
3
7
|
import { confirm, prompt } from "../dialogs";
|
|
4
8
|
import { mockFetchInternal, mockFetchKVGetValue } from "./helpers/mock-cfetch";
|
|
9
|
+
import { MockWebSocket } from "./helpers/mock-web-socket";
|
|
10
|
+
|
|
11
|
+
jest.mock("ws", () => {
|
|
12
|
+
return {
|
|
13
|
+
__esModule: true,
|
|
14
|
+
default: MockWebSocket,
|
|
15
|
+
};
|
|
16
|
+
});
|
|
5
17
|
|
|
6
18
|
jest.mock("undici", () => {
|
|
7
19
|
return {
|
|
@@ -9,6 +21,11 @@ jest.mock("undici", () => {
|
|
|
9
21
|
fetch: jest.requireActual("jest-fetch-mock"),
|
|
10
22
|
};
|
|
11
23
|
});
|
|
24
|
+
|
|
25
|
+
// Outside of the Sentry tests themselves, we mock Sentry to ensure that it doesn't actually send any data and
|
|
26
|
+
// that it doesn't interfere with the rest of the tests.
|
|
27
|
+
jest.mock("../reporting");
|
|
28
|
+
|
|
12
29
|
fetchMock.doMock(() => {
|
|
13
30
|
// Any un-mocked fetches should throw
|
|
14
31
|
throw new Error("Unexpected fetch request");
|
|
@@ -19,19 +36,34 @@ jest.mock("../package-manager");
|
|
|
19
36
|
jest.mock("../cfetch/internal");
|
|
20
37
|
(fetchInternal as jest.Mock).mockImplementation(mockFetchInternal);
|
|
21
38
|
(fetchKVGetValue as jest.Mock).mockImplementation(mockFetchKVGetValue);
|
|
39
|
+
(getCloudflareAPIBaseURL as jest.Mock).mockReturnValue(
|
|
40
|
+
"https://api.cloudflare.com/client/v4"
|
|
41
|
+
);
|
|
22
42
|
|
|
23
43
|
jest.mock("../dialogs");
|
|
24
44
|
|
|
25
45
|
// By default (if not configured by mockConfirm()) calls to `confirm()` should throw.
|
|
26
|
-
(confirm as jest.Mock).mockImplementation(() => {
|
|
46
|
+
(confirm as jest.Mock).mockImplementation((text: string) => {
|
|
27
47
|
throw new Error(
|
|
28
|
-
|
|
48
|
+
`Unexpected call to \`confirm("${text}")\`.\nYou should use \`mockConfirm()\` to mock calls to \`confirm()\` with expectations. Search the codebase for \`mockConfirm\` to learn more.`
|
|
29
49
|
);
|
|
30
50
|
});
|
|
31
51
|
|
|
32
52
|
// By default (if not configured by mockPrompt()) calls to `prompt()` should throw.
|
|
33
|
-
(prompt as jest.Mock).mockImplementation(() => {
|
|
53
|
+
(prompt as jest.Mock).mockImplementation((text: string) => {
|
|
34
54
|
throw new Error(
|
|
35
|
-
|
|
55
|
+
`Unexpected call to \`prompt(${text}, ...)\`.\nYou should use \`mockPrompt()\` to mock calls to \`prompt()\` with expectations. Search the codebase for \`mockPrompt\` to learn more.`
|
|
36
56
|
);
|
|
37
57
|
});
|
|
58
|
+
|
|
59
|
+
jest.mock("../dev/dev", () => {
|
|
60
|
+
const { useApp } = jest.requireActual("ink");
|
|
61
|
+
const { useEffect } = jest.requireActual("react");
|
|
62
|
+
return jest.fn().mockImplementation(() => {
|
|
63
|
+
const { exit } = useApp();
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
exit();
|
|
66
|
+
});
|
|
67
|
+
return null;
|
|
68
|
+
});
|
|
69
|
+
});
|