wrangler 0.0.0-e2a26a0 → 0.0.0-e3cab74
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/package.json +16 -7
- package/pages/functions/filepath-routing.test.ts +112 -36
- package/pages/functions/filepath-routing.ts +66 -119
- package/pages/functions/routes.ts +8 -17
- package/pages/functions/template-worker.ts +3 -9
- package/src/__tests__/configuration.test.ts +2185 -0
- package/src/__tests__/dev.test.tsx +48 -6
- package/src/__tests__/guess-worker-format.test.ts +66 -0
- package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +6 -6
- package/src/__tests__/helpers/mock-bin.ts +4 -1
- package/src/__tests__/helpers/mock-cfetch.ts +2 -2
- package/src/__tests__/helpers/mock-console.ts +11 -5
- package/src/__tests__/helpers/mock-web-socket.ts +29 -0
- package/src/__tests__/helpers/run-wrangler.ts +5 -3
- package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
- package/src/__tests__/index.test.ts +343 -20
- package/src/__tests__/jest.setup.ts +21 -1
- package/src/__tests__/kv.test.ts +82 -80
- package/src/__tests__/package-manager.test.ts +2 -2
- package/src/__tests__/parse.test.ts +322 -0
- package/src/__tests__/publish.test.ts +1428 -244
- package/src/__tests__/r2.test.ts +198 -0
- package/src/__tests__/secret.test.ts +176 -60
- package/src/__tests__/sentry.test.ts +146 -0
- package/src/__tests__/tail.test.ts +564 -0
- package/src/api/form_data.ts +106 -23
- package/src/api/preview.ts +32 -13
- package/src/api/worker.ts +49 -18
- package/src/bundle.ts +133 -0
- package/src/cfetch/index.ts +8 -6
- package/src/cfetch/internal.ts +49 -17
- package/src/cli.ts +10 -0
- package/src/config/README.md +107 -0
- package/src/config/config.ts +265 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +305 -0
- package/src/config/index.ts +52 -0
- package/src/config/validation-helpers.ts +370 -0
- package/src/config/validation.ts +1017 -0
- package/src/dev.tsx +338 -211
- package/src/entry.ts +57 -0
- package/src/environment-variables.ts +33 -0
- package/src/guess-worker-format.ts +68 -0
- package/src/index.tsx +860 -634
- package/src/inspect.ts +16 -3
- package/src/kv.tsx +20 -29
- package/src/module-collection.ts +141 -34
- package/src/open-in-browser.ts +13 -0
- package/src/package-manager.ts +21 -15
- package/src/pages.tsx +9 -10
- package/src/parse.ts +183 -0
- package/src/proxy.ts +11 -5
- package/src/publish.ts +272 -314
- package/src/r2.ts +50 -0
- package/src/reporting.ts +115 -0
- package/src/sites.tsx +16 -15
- 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 +74 -44
- 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 +51308 -36440
- package/wrangler-dist/cli.js.map +3 -3
- package/src/config.ts +0 -641
- 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(`""`);
|
|
@@ -70,22 +73,21 @@ 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
92
|
Unknown command: invalid-command."
|
|
91
93
|
`);
|
|
@@ -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,6 +756,62 @@ describe("wrangler", () => {
|
|
|
508
756
|
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
509
757
|
});
|
|
510
758
|
|
|
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")
|
|
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);
|
|
813
|
+
});
|
|
814
|
+
|
|
511
815
|
it("should error if `--type` is used", async () => {
|
|
512
816
|
await expect(
|
|
513
817
|
runWrangler("init --type")
|
|
@@ -540,4 +844,23 @@ describe("wrangler", () => {
|
|
|
540
844
|
`);
|
|
541
845
|
});
|
|
542
846
|
});
|
|
847
|
+
|
|
848
|
+
describe("preview", () => {
|
|
849
|
+
it("should throw an error if the deprecated command is used with positional arguments", async () => {
|
|
850
|
+
await expect(runWrangler("preview GET")).rejects
|
|
851
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
852
|
+
"DEPRECATION WARNING:
|
|
853
|
+
The \`wrangler preview\` command has been deprecated.
|
|
854
|
+
Try using \`wrangler dev\` to to try out a worker during development.
|
|
855
|
+
"
|
|
856
|
+
`);
|
|
857
|
+
await expect(runWrangler("preview GET 'Some Body'")).rejects
|
|
858
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
859
|
+
"DEPRECATION WARNING:
|
|
860
|
+
The \`wrangler preview\` command has been deprecated.
|
|
861
|
+
Try using \`wrangler dev\` to to try out a worker during development.
|
|
862
|
+
"
|
|
863
|
+
`);
|
|
864
|
+
});
|
|
865
|
+
});
|
|
543
866
|
});
|
|
@@ -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,6 +36,9 @@ 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
|
|