wrangler 2.0.12 → 2.0.16
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 +7 -1
- package/bin/wrangler.js +111 -57
- package/miniflare-dist/index.mjs +9 -2
- package/package.json +156 -154
- package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
- package/src/__tests__/config-cache.test.ts +30 -24
- package/src/__tests__/configuration.test.ts +3935 -3476
- package/src/__tests__/dev.test.tsx +1128 -979
- package/src/__tests__/guess-worker-format.test.ts +68 -68
- package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
- package/src/__tests__/helpers/faye-websocket.d.ts +4 -4
- package/src/__tests__/helpers/mock-account-id.ts +24 -24
- package/src/__tests__/helpers/mock-bin.ts +20 -20
- package/src/__tests__/helpers/mock-cfetch.ts +92 -92
- package/src/__tests__/helpers/mock-console.ts +49 -39
- package/src/__tests__/helpers/mock-dialogs.ts +94 -71
- package/src/__tests__/helpers/mock-http-server.ts +30 -30
- package/src/__tests__/helpers/mock-istty.ts +65 -18
- package/src/__tests__/helpers/mock-kv.ts +26 -26
- package/src/__tests__/helpers/mock-oauth-flow.ts +223 -228
- package/src/__tests__/helpers/mock-process.ts +39 -0
- package/src/__tests__/helpers/mock-stdin.ts +82 -77
- package/src/__tests__/helpers/mock-web-socket.ts +21 -21
- package/src/__tests__/helpers/run-in-tmp.ts +27 -27
- package/src/__tests__/helpers/run-wrangler.ts +8 -8
- package/src/__tests__/helpers/write-worker-source.ts +16 -16
- package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
- package/src/__tests__/https-options.test.ts +104 -104
- package/src/__tests__/index.test.ts +239 -234
- package/src/__tests__/init.test.ts +1605 -1250
- package/src/__tests__/jest.setup.ts +63 -33
- package/src/__tests__/kv.test.ts +1128 -1011
- package/src/__tests__/logger.test.ts +100 -74
- package/src/__tests__/package-manager.test.ts +303 -303
- package/src/__tests__/pages.test.ts +1152 -652
- package/src/__tests__/parse.test.ts +252 -252
- package/src/__tests__/publish.test.ts +6371 -5622
- package/src/__tests__/pubsub.test.ts +367 -0
- package/src/__tests__/r2.test.ts +133 -133
- package/src/__tests__/route.test.ts +18 -18
- package/src/__tests__/secret.test.ts +382 -377
- package/src/__tests__/tail.test.ts +530 -530
- package/src/__tests__/user.test.ts +123 -111
- package/src/__tests__/whoami.test.tsx +198 -117
- package/src/__tests__/worker-namespace.test.ts +327 -0
- package/src/abort.d.ts +1 -1
- package/src/api/dev.ts +49 -0
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +29 -0
- package/src/bundle.ts +157 -149
- package/src/cfetch/index.ts +80 -80
- package/src/cfetch/internal.ts +90 -83
- package/src/cli.ts +21 -7
- package/src/config/config.ts +204 -195
- package/src/config/diagnostics.ts +61 -61
- package/src/config/environment.ts +390 -357
- package/src/config/index.ts +206 -193
- package/src/config/validation-helpers.ts +366 -366
- package/src/config/validation.ts +1573 -1376
- package/src/config-cache.ts +79 -41
- package/src/create-worker-preview.ts +206 -136
- package/src/create-worker-upload-form.ts +247 -238
- package/src/dev/dev-vars.ts +13 -13
- package/src/dev/dev.tsx +329 -307
- package/src/dev/local.tsx +304 -275
- package/src/dev/remote.tsx +366 -224
- package/src/dev/use-esbuild.ts +126 -91
- package/src/dev.tsx +538 -0
- package/src/dialogs.tsx +97 -97
- package/src/durable.ts +87 -87
- package/src/entry.ts +234 -228
- package/src/environment-variables.ts +23 -23
- package/src/errors.ts +6 -6
- package/src/generate.ts +33 -0
- package/src/git-client.ts +42 -0
- package/src/https-options.ts +79 -79
- package/src/index.tsx +1775 -2763
- package/src/init.ts +549 -0
- package/src/inspect.ts +593 -593
- package/src/intl-polyfill.d.ts +123 -123
- package/src/is-interactive.ts +12 -0
- package/src/kv.ts +277 -277
- package/src/logger.ts +46 -39
- package/src/miniflare-cli/enum-keys.ts +8 -8
- package/src/miniflare-cli/index.ts +42 -31
- package/src/miniflare-cli/request-context.ts +18 -18
- package/src/module-collection.ts +212 -212
- package/src/open-in-browser.ts +4 -6
- package/src/package-manager.ts +123 -123
- package/src/pages/build.tsx +202 -0
- package/src/pages/constants.ts +7 -0
- package/src/pages/deployments.tsx +101 -0
- package/src/pages/dev.tsx +964 -0
- package/src/pages/functions/buildPlugin.ts +105 -0
- package/src/pages/functions/buildWorker.ts +151 -0
- package/{pages → src/pages}/functions/filepath-routing.test.ts +113 -113
- package/src/pages/functions/filepath-routing.ts +189 -0
- package/src/pages/functions/identifiers.ts +78 -0
- package/src/pages/functions/routes.ts +151 -0
- package/src/pages/index.tsx +84 -0
- package/src/pages/projects.tsx +157 -0
- package/src/pages/publish.tsx +335 -0
- package/src/pages/types.ts +40 -0
- package/src/pages/upload.tsx +384 -0
- package/src/pages/utils.ts +12 -0
- package/src/parse.ts +202 -138
- package/src/paths.ts +6 -6
- package/src/preview.ts +31 -0
- package/src/proxy.ts +400 -402
- package/src/publish.ts +667 -621
- package/src/pubsub/index.ts +286 -0
- package/src/pubsub/pubsub-commands.tsx +577 -0
- package/src/r2.ts +19 -19
- package/src/selfsigned.d.ts +23 -23
- package/src/sites.tsx +271 -225
- package/src/tail/filters.ts +108 -108
- package/src/tail/index.ts +217 -217
- package/src/tail/printing.ts +45 -45
- package/src/update-check.ts +11 -11
- package/src/user/choose-account.tsx +60 -0
- package/src/user/env-vars.ts +46 -0
- package/src/user/generate-auth-url.ts +33 -0
- package/src/user/generate-random-state.ts +16 -0
- package/src/user/index.ts +3 -0
- package/src/user/user.tsx +1161 -0
- package/src/whoami.tsx +61 -42
- package/src/worker-namespace.ts +190 -0
- package/src/worker.ts +110 -100
- package/src/zones.ts +39 -36
- package/templates/checked-fetch.js +17 -0
- package/templates/new-worker-scheduled.js +3 -3
- package/templates/new-worker-scheduled.ts +15 -15
- package/templates/new-worker.js +3 -3
- package/templates/new-worker.ts +15 -15
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-template-plugin.ts +155 -0
- package/templates/pages-template-worker.ts +161 -0
- package/templates/static-asset-facade.js +31 -31
- package/templates/tsconfig.json +95 -95
- package/wrangler-dist/cli.js +55383 -54138
- package/pages/functions/buildPlugin.ts +0 -105
- package/pages/functions/buildWorker.ts +0 -151
- package/pages/functions/filepath-routing.ts +0 -189
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -156
- package/pages/functions/template-plugin.ts +0 -147
- package/pages/functions/template-worker.ts +0 -143
- package/src/pages.tsx +0 -2093
- package/src/user.tsx +0 -1214
|
@@ -10,742 +10,803 @@ import { runWrangler } from "./helpers/run-wrangler";
|
|
|
10
10
|
import writeWranglerToml from "./helpers/write-wrangler-toml";
|
|
11
11
|
|
|
12
12
|
describe("wrangler dev", () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
13
|
+
runInTempDir();
|
|
14
|
+
const std = mockConsoleMethods();
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
(Dev as jest.Mock).mockClear();
|
|
17
|
+
patchConsole(() => {});
|
|
18
|
+
unsetAllMocks();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("compatibility-date", () => {
|
|
22
|
+
it("should not warn if there is no wrangler.toml and no compatibility-date specified", async () => {
|
|
23
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
24
|
+
await runWrangler("dev index.js");
|
|
25
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
26
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
27
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should warn if there is a wrangler.toml but no compatibility-date", async () => {
|
|
31
|
+
writeWranglerToml({
|
|
32
|
+
main: "index.js",
|
|
33
|
+
compatibility_date: undefined,
|
|
34
|
+
});
|
|
35
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
36
|
+
await runWrangler("dev");
|
|
37
|
+
const currentDate = new Date().toISOString().substring(0, 10);
|
|
38
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
39
|
+
expect(std.warn.replaceAll(currentDate, "<current-date>"))
|
|
40
|
+
.toMatchInlineSnapshot(`
|
|
41
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mNo compatibility_date was specified. Using today's date: <current-date>.[0m
|
|
42
|
+
|
|
43
|
+
Add one to your wrangler.toml file:
|
|
44
|
+
\`\`\`
|
|
45
|
+
compatibility_date = \\"<current-date>\\"
|
|
46
|
+
\`\`\`
|
|
47
|
+
or pass it in your terminal:
|
|
48
|
+
\`\`\`
|
|
49
|
+
--compatibility-date=<current-date>
|
|
50
|
+
\`\`\`
|
|
51
|
+
See [4mhttps://developers.cloudflare.com/workers/platform/compatibility-dates[0m for more information.
|
|
52
|
+
|
|
53
|
+
"
|
|
54
|
+
`);
|
|
55
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should not warn if there is a wrangler.toml but compatibility-date is specified at the command line", async () => {
|
|
59
|
+
writeWranglerToml({
|
|
60
|
+
main: "index.js",
|
|
61
|
+
compatibility_date: undefined,
|
|
62
|
+
});
|
|
63
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
64
|
+
await runWrangler("dev --compatibility-date=2020-01-01");
|
|
65
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
66
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
67
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe("entry-points", () => {
|
|
72
|
+
it("should error if there is no entry-point specified", async () => {
|
|
73
|
+
writeWranglerToml();
|
|
74
|
+
|
|
75
|
+
await expect(
|
|
76
|
+
runWrangler("dev")
|
|
77
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
78
|
+
`"Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler dev path/to/script\`) or the \`main\` config field."`
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
82
|
+
"
|
|
83
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
84
|
+
`);
|
|
85
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
86
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mMissing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler dev path/to/script\`) or the \`main\` config field.[0m
|
|
87
|
+
|
|
88
|
+
"
|
|
89
|
+
`);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should use `main` from the top-level environment", async () => {
|
|
93
|
+
writeWranglerToml({
|
|
94
|
+
main: "index.js",
|
|
95
|
+
});
|
|
96
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
97
|
+
await runWrangler("dev");
|
|
98
|
+
expect((Dev as jest.Mock).mock.calls[0][0].entry.file).toMatch(
|
|
99
|
+
/index\.js$/
|
|
100
|
+
);
|
|
101
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
102
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
103
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should use `main` from a named environment", async () => {
|
|
107
|
+
writeWranglerToml({
|
|
108
|
+
env: {
|
|
109
|
+
ENV1: {
|
|
110
|
+
main: "index.js",
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
115
|
+
await runWrangler("dev --env=ENV1");
|
|
116
|
+
expect((Dev as jest.Mock).mock.calls[0][0].entry.file).toMatch(
|
|
117
|
+
/index\.js$/
|
|
118
|
+
);
|
|
119
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
120
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
121
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should use `main` from a named environment, rather than the top-level", async () => {
|
|
125
|
+
writeWranglerToml({
|
|
126
|
+
main: "other.js",
|
|
127
|
+
env: {
|
|
128
|
+
ENV1: {
|
|
129
|
+
main: "index.js",
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
134
|
+
await runWrangler("dev --env=ENV1");
|
|
135
|
+
expect((Dev as jest.Mock).mock.calls[0][0].entry.file).toMatch(
|
|
136
|
+
/index\.js$/
|
|
137
|
+
);
|
|
138
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
139
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
140
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe("routes", () => {
|
|
145
|
+
it("should pass routes to <Dev/>", async () => {
|
|
146
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
147
|
+
|
|
148
|
+
// config.routes
|
|
149
|
+
mockGetZones("5.some-host.com", [{ id: "some-zone-id-5" }]);
|
|
150
|
+
writeWranglerToml({
|
|
151
|
+
main: "index.js",
|
|
152
|
+
routes: ["http://5.some-host.com/some/path/*"],
|
|
153
|
+
});
|
|
154
|
+
await runWrangler("dev");
|
|
155
|
+
expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
|
|
156
|
+
expect.objectContaining({
|
|
157
|
+
host: "5.some-host.com",
|
|
158
|
+
zone: "some-zone-id-5",
|
|
159
|
+
routes: ["http://5.some-host.com/some/path/*"],
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe("host", () => {
|
|
166
|
+
it("should resolve a host to its zone", async () => {
|
|
167
|
+
writeWranglerToml({
|
|
168
|
+
main: "index.js",
|
|
169
|
+
});
|
|
170
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
171
|
+
mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
|
|
172
|
+
await runWrangler("dev --host some-host.com");
|
|
173
|
+
expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
|
|
174
|
+
expect.objectContaining({
|
|
175
|
+
host: "some-host.com",
|
|
176
|
+
zone: "some-zone-id",
|
|
177
|
+
})
|
|
178
|
+
);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("should read wrangler.toml's dev.host", async () => {
|
|
182
|
+
writeWranglerToml({
|
|
183
|
+
main: "index.js",
|
|
184
|
+
dev: {
|
|
185
|
+
host: "some-host.com",
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
189
|
+
mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
|
|
190
|
+
await runWrangler("dev");
|
|
191
|
+
expect((Dev as jest.Mock).mock.calls[0][0].host).toEqual("some-host.com");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("should read --route", async () => {
|
|
195
|
+
writeWranglerToml({
|
|
196
|
+
main: "index.js",
|
|
197
|
+
});
|
|
198
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
199
|
+
mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
|
|
200
|
+
await runWrangler("dev --route http://some-host.com/some/path/*");
|
|
201
|
+
expect((Dev as jest.Mock).mock.calls[0][0].host).toEqual("some-host.com");
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("should read wrangler.toml's routes", async () => {
|
|
205
|
+
writeWranglerToml({
|
|
206
|
+
main: "index.js",
|
|
207
|
+
routes: [
|
|
208
|
+
"http://some-host.com/some/path/*",
|
|
209
|
+
"http://some-other-host.com/path/*",
|
|
210
|
+
],
|
|
211
|
+
});
|
|
212
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
213
|
+
mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
|
|
214
|
+
await runWrangler("dev");
|
|
215
|
+
expect((Dev as jest.Mock).mock.calls[0][0].host).toEqual("some-host.com");
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("should read wrangler.toml's environment specific routes", async () => {
|
|
219
|
+
writeWranglerToml({
|
|
220
|
+
main: "index.js",
|
|
221
|
+
routes: [
|
|
222
|
+
"http://a-host.com/some/path/*",
|
|
223
|
+
"http://another-host.com/path/*",
|
|
224
|
+
],
|
|
225
|
+
env: {
|
|
226
|
+
staging: {
|
|
227
|
+
routes: [
|
|
228
|
+
"http://some-host.com/some/path/*",
|
|
229
|
+
"http://some-other-host.com/path/*",
|
|
230
|
+
],
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
235
|
+
mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
|
|
236
|
+
await runWrangler("dev --env staging");
|
|
237
|
+
expect((Dev as jest.Mock).mock.calls[0][0].host).toEqual("some-host.com");
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("should strip leading `*` from given host when deducing a zone id", async () => {
|
|
241
|
+
writeWranglerToml({
|
|
242
|
+
main: "index.js",
|
|
243
|
+
route: "*some-host.com/some/path/*",
|
|
244
|
+
});
|
|
245
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
246
|
+
mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
|
|
247
|
+
await runWrangler("dev");
|
|
248
|
+
expect((Dev as jest.Mock).mock.calls[0][0].host).toEqual("some-host.com");
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it("should strip leading `*.` from given host when deducing a zone id", async () => {
|
|
252
|
+
writeWranglerToml({
|
|
253
|
+
main: "index.js",
|
|
254
|
+
route: "*.some-host.com/some/path/*",
|
|
255
|
+
});
|
|
256
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
257
|
+
mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
|
|
258
|
+
await runWrangler("dev");
|
|
259
|
+
expect((Dev as jest.Mock).mock.calls[0][0].host).toEqual("some-host.com");
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("should, when provided, use a configured zone_id", async () => {
|
|
263
|
+
writeWranglerToml({
|
|
264
|
+
main: "index.js",
|
|
265
|
+
routes: [
|
|
266
|
+
{ pattern: "https://some-domain.com/*", zone_id: "some-zone-id" },
|
|
267
|
+
],
|
|
268
|
+
});
|
|
269
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
270
|
+
await runWrangler("dev");
|
|
271
|
+
expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
|
|
272
|
+
expect.objectContaining({
|
|
273
|
+
host: "some-domain.com",
|
|
274
|
+
zone: "some-zone-id",
|
|
275
|
+
})
|
|
276
|
+
);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("should, when provided, use a zone_name to get a zone_id", async () => {
|
|
280
|
+
writeWranglerToml({
|
|
281
|
+
main: "index.js",
|
|
282
|
+
routes: [
|
|
283
|
+
{ pattern: "https://some-domain.com/*", zone_name: "some-zone.com" },
|
|
284
|
+
],
|
|
285
|
+
});
|
|
286
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
287
|
+
mockGetZones("some-zone.com", [{ id: "a-zone-id" }]);
|
|
288
|
+
await runWrangler("dev");
|
|
289
|
+
expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
|
|
290
|
+
expect.objectContaining({
|
|
291
|
+
// note that it uses the provided zone_name as a host too
|
|
292
|
+
host: "some-zone.com",
|
|
293
|
+
zone: "a-zone-id",
|
|
294
|
+
})
|
|
295
|
+
);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it("given a long host, it should use the longest subdomain that resolves to a zone", async () => {
|
|
299
|
+
writeWranglerToml({
|
|
300
|
+
main: "index.js",
|
|
301
|
+
});
|
|
302
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
303
|
+
mockGetZones("111.222.333.some-host.com", []);
|
|
304
|
+
mockGetZones("222.333.some-host.com", []);
|
|
305
|
+
mockGetZones("333.some-host.com", [{ id: "some-zone-id" }]);
|
|
306
|
+
await runWrangler("dev --host 111.222.333.some-host.com");
|
|
307
|
+
expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
|
|
308
|
+
expect.objectContaining({
|
|
309
|
+
host: "111.222.333.some-host.com",
|
|
310
|
+
zone: "some-zone-id",
|
|
311
|
+
})
|
|
312
|
+
);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("should, in order, use args.host/config.dev.host/args.routes/(config.route|config.routes)", async () => {
|
|
316
|
+
// This test might seem like it's testing implementation details, but let's be specific and consider it a spec
|
|
317
|
+
|
|
318
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
319
|
+
|
|
320
|
+
// config.routes
|
|
321
|
+
mockGetZones("5.some-host.com", [{ id: "some-zone-id-5" }]);
|
|
322
|
+
writeWranglerToml({
|
|
323
|
+
main: "index.js",
|
|
324
|
+
routes: ["http://5.some-host.com/some/path/*"],
|
|
325
|
+
});
|
|
326
|
+
await runWrangler("dev");
|
|
327
|
+
expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
|
|
328
|
+
expect.objectContaining({
|
|
329
|
+
host: "5.some-host.com",
|
|
330
|
+
zone: "some-zone-id-5",
|
|
331
|
+
})
|
|
332
|
+
);
|
|
333
|
+
(Dev as jest.Mock).mockClear();
|
|
334
|
+
|
|
335
|
+
// config.route
|
|
336
|
+
mockGetZones("4.some-host.com", [{ id: "some-zone-id-4" }]);
|
|
337
|
+
writeWranglerToml({
|
|
338
|
+
main: "index.js",
|
|
339
|
+
route: "https://4.some-host.com/some/path/*",
|
|
340
|
+
});
|
|
341
|
+
await runWrangler("dev");
|
|
342
|
+
expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
|
|
343
|
+
expect.objectContaining({
|
|
344
|
+
host: "4.some-host.com",
|
|
345
|
+
zone: "some-zone-id-4",
|
|
346
|
+
})
|
|
347
|
+
);
|
|
348
|
+
(Dev as jest.Mock).mockClear();
|
|
349
|
+
|
|
350
|
+
// --routes
|
|
351
|
+
mockGetZones("3.some-host.com", [{ id: "some-zone-id-3" }]);
|
|
352
|
+
writeWranglerToml({
|
|
353
|
+
main: "index.js",
|
|
354
|
+
route: "https://4.some-host.com/some/path/*",
|
|
355
|
+
});
|
|
356
|
+
await runWrangler("dev --routes http://3.some-host.com/some/path/*");
|
|
357
|
+
expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
|
|
358
|
+
expect.objectContaining({
|
|
359
|
+
host: "3.some-host.com",
|
|
360
|
+
zone: "some-zone-id-3",
|
|
361
|
+
})
|
|
362
|
+
);
|
|
363
|
+
(Dev as jest.Mock).mockClear();
|
|
364
|
+
|
|
365
|
+
// config.dev.host
|
|
366
|
+
mockGetZones("2.some-host.com", [{ id: "some-zone-id-2" }]);
|
|
367
|
+
writeWranglerToml({
|
|
368
|
+
main: "index.js",
|
|
369
|
+
dev: {
|
|
370
|
+
host: `2.some-host.com`,
|
|
371
|
+
},
|
|
372
|
+
route: "4.some-host.com/some/path/*",
|
|
373
|
+
});
|
|
374
|
+
await runWrangler("dev --routes http://3.some-host.com/some/path/*");
|
|
375
|
+
expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
|
|
376
|
+
expect.objectContaining({
|
|
377
|
+
host: "2.some-host.com",
|
|
378
|
+
zone: "some-zone-id-2",
|
|
379
|
+
})
|
|
380
|
+
);
|
|
381
|
+
(Dev as jest.Mock).mockClear();
|
|
382
|
+
|
|
383
|
+
// --host
|
|
384
|
+
mockGetZones("1.some-host.com", [{ id: "some-zone-id-1" }]);
|
|
385
|
+
writeWranglerToml({
|
|
386
|
+
main: "index.js",
|
|
387
|
+
dev: {
|
|
388
|
+
host: `2.some-host.com`,
|
|
389
|
+
},
|
|
390
|
+
route: "4.some-host.com/some/path/*",
|
|
391
|
+
});
|
|
392
|
+
await runWrangler(
|
|
393
|
+
"dev --routes http://3.some-host.com/some/path/* --host 1.some-host.com"
|
|
394
|
+
);
|
|
395
|
+
expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
|
|
396
|
+
expect.objectContaining({
|
|
397
|
+
host: "1.some-host.com",
|
|
398
|
+
zone: "some-zone-id-1",
|
|
399
|
+
})
|
|
400
|
+
);
|
|
401
|
+
(Dev as jest.Mock).mockClear();
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
it("should error if a host can't resolve to a zone", async () => {
|
|
405
|
+
writeWranglerToml({
|
|
406
|
+
main: "index.js",
|
|
407
|
+
});
|
|
408
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
409
|
+
mockGetZones("some-host.com", []);
|
|
410
|
+
await expect(
|
|
411
|
+
runWrangler("dev --host some-host.com")
|
|
412
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
413
|
+
`"Could not find zone for some-host.com"`
|
|
414
|
+
);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
it("should not try to resolve a zone when starting in local mode", async () => {
|
|
418
|
+
writeWranglerToml({
|
|
419
|
+
main: "index.js",
|
|
420
|
+
});
|
|
421
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
422
|
+
await runWrangler("dev --host some-host.com --local");
|
|
423
|
+
expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual(undefined);
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
describe("local upstream", () => {
|
|
428
|
+
it("should use dev.host from toml by default", async () => {
|
|
429
|
+
writeWranglerToml({
|
|
430
|
+
main: "index.js",
|
|
431
|
+
dev: {
|
|
432
|
+
host: `2.some-host.com`,
|
|
433
|
+
},
|
|
434
|
+
});
|
|
435
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
436
|
+
await runWrangler("dev --local");
|
|
437
|
+
expect((Dev as jest.Mock).mock.calls[0][0].localUpstream).toEqual(
|
|
438
|
+
"2.some-host.com"
|
|
439
|
+
);
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
it("should use route from toml by default", async () => {
|
|
443
|
+
writeWranglerToml({
|
|
444
|
+
main: "index.js",
|
|
445
|
+
route: "https://4.some-host.com/some/path/*",
|
|
446
|
+
});
|
|
447
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
448
|
+
await runWrangler("dev --local");
|
|
449
|
+
expect((Dev as jest.Mock).mock.calls[0][0].host).toEqual(
|
|
450
|
+
"4.some-host.com"
|
|
451
|
+
);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it("should respect the option when provided", async () => {
|
|
455
|
+
writeWranglerToml({
|
|
456
|
+
main: "index.js",
|
|
457
|
+
route: `2.some-host.com`,
|
|
458
|
+
});
|
|
459
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
460
|
+
await runWrangler("dev --local-upstream some-host.com --local");
|
|
461
|
+
expect((Dev as jest.Mock).mock.calls[0][0].localUpstream).toEqual(
|
|
462
|
+
"some-host.com"
|
|
463
|
+
);
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
describe("custom builds", () => {
|
|
468
|
+
it("should run a custom build before starting `dev`", async () => {
|
|
469
|
+
writeWranglerToml({
|
|
470
|
+
build: {
|
|
471
|
+
command: `node -e "console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')"`,
|
|
472
|
+
},
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
await runWrangler("dev index.js");
|
|
476
|
+
|
|
477
|
+
expect(fs.readFileSync("index.js", "utf-8")).toMatchInlineSnapshot(
|
|
478
|
+
`"export default { fetch(){ return new Response(123) } }"`
|
|
479
|
+
);
|
|
480
|
+
|
|
481
|
+
// and the command would pass through
|
|
482
|
+
expect((Dev as jest.Mock).mock.calls[0][0].build).toEqual({
|
|
483
|
+
command:
|
|
484
|
+
"node -e \"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\"",
|
|
485
|
+
cwd: undefined,
|
|
486
|
+
watch_dir: "src",
|
|
487
|
+
});
|
|
488
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
489
|
+
`"Running custom build: node -e \\"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\""`
|
|
490
|
+
);
|
|
491
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
492
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
if (process.platform !== "win32") {
|
|
496
|
+
it("should run a custom build of multiple steps combined by && before starting `dev`", async () => {
|
|
497
|
+
writeWranglerToml({
|
|
498
|
+
build: {
|
|
499
|
+
command: `echo "custom build" && echo "export default { fetch(){ return new Response(123) } }" > index.js`,
|
|
500
|
+
},
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
await runWrangler("dev index.js");
|
|
504
|
+
|
|
505
|
+
expect(fs.readFileSync("index.js", "utf-8")).toMatchInlineSnapshot(`
|
|
506
|
+
"export default { fetch(){ return new Response(123) } }
|
|
507
|
+
"
|
|
508
|
+
`);
|
|
509
|
+
|
|
510
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
511
|
+
`"Running custom build: echo \\"custom build\\" && echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js"`
|
|
512
|
+
);
|
|
513
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
514
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
it("should throw an error if the entry doesn't exist after the build finishes", async () => {
|
|
519
|
+
writeWranglerToml({
|
|
520
|
+
main: "index.js",
|
|
521
|
+
build: {
|
|
522
|
+
command: `node -e "console.log('custom build');"`,
|
|
523
|
+
},
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
await expect(runWrangler("dev")).rejects
|
|
527
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
467
528
|
"The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
|
|
468
529
|
The \`main\` property in wrangler.toml should point to the file generated by the custom build."
|
|
469
530
|
`);
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
531
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
532
|
+
"Running custom build: node -e \\"console.log('custom build');\\"
|
|
533
|
+
|
|
534
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
535
|
+
`);
|
|
536
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
537
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThe expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".[0m
|
|
538
|
+
|
|
539
|
+
The \`main\` property in wrangler.toml should point to the file generated by the custom build.
|
|
540
|
+
|
|
541
|
+
"
|
|
542
|
+
`);
|
|
543
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
describe("upstream-protocol", () => {
|
|
548
|
+
it("should default upstream-protocol to `https`", async () => {
|
|
549
|
+
writeWranglerToml({
|
|
550
|
+
main: "index.js",
|
|
551
|
+
});
|
|
552
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
553
|
+
await runWrangler("dev");
|
|
554
|
+
expect((Dev as jest.Mock).mock.calls[0][0].upstreamProtocol).toEqual(
|
|
555
|
+
"https"
|
|
556
|
+
);
|
|
557
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
558
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
559
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
it("should warn if `--upstream-protocol=http` is used", async () => {
|
|
563
|
+
writeWranglerToml({
|
|
564
|
+
main: "index.js",
|
|
565
|
+
});
|
|
566
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
567
|
+
await runWrangler("dev --upstream-protocol=http");
|
|
568
|
+
expect((Dev as jest.Mock).mock.calls[0][0].upstreamProtocol).toEqual(
|
|
569
|
+
"http"
|
|
570
|
+
);
|
|
571
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
572
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
573
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mSetting upstream-protocol to http is not currently implemented.[0m
|
|
574
|
+
|
|
575
|
+
If this is required in your project, please add your use case to the following issue:
|
|
576
|
+
[4mhttps://github.com/cloudflare/wrangler2/issues/583[0m.
|
|
577
|
+
|
|
578
|
+
"
|
|
579
|
+
`);
|
|
580
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
581
|
+
});
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
describe("local-protocol", () => {
|
|
585
|
+
it("should default local-protocol to `http`", async () => {
|
|
586
|
+
writeWranglerToml({
|
|
587
|
+
main: "index.js",
|
|
588
|
+
});
|
|
589
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
590
|
+
await runWrangler("dev");
|
|
591
|
+
expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual("http");
|
|
592
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
593
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
594
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
it("should use `local_protocol` from `wrangler.toml`, if available", async () => {
|
|
598
|
+
writeWranglerToml({
|
|
599
|
+
main: "index.js",
|
|
600
|
+
dev: {
|
|
601
|
+
local_protocol: "https",
|
|
602
|
+
},
|
|
603
|
+
});
|
|
604
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
605
|
+
await runWrangler("dev");
|
|
606
|
+
expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual(
|
|
607
|
+
"https"
|
|
608
|
+
);
|
|
609
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
610
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
611
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
it("should use --local-protocol command line arg, if provided", async () => {
|
|
615
|
+
// Here we show that the command line overrides the wrangler.toml by
|
|
616
|
+
// setting the config to https, and then setting it back to http on the command line.
|
|
617
|
+
writeWranglerToml({
|
|
618
|
+
main: "index.js",
|
|
619
|
+
dev: {
|
|
620
|
+
local_protocol: "https",
|
|
621
|
+
},
|
|
622
|
+
});
|
|
623
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
624
|
+
await runWrangler("dev --local-protocol=http");
|
|
625
|
+
expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual("http");
|
|
626
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
627
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
628
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
describe("ip", () => {
|
|
633
|
+
it("should default ip to localhost", async () => {
|
|
634
|
+
writeWranglerToml({
|
|
635
|
+
main: "index.js",
|
|
636
|
+
});
|
|
637
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
638
|
+
await runWrangler("dev");
|
|
639
|
+
expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("localhost");
|
|
640
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
641
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
642
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
it("should use to `ip` from `wrangler.toml`, if available", async () => {
|
|
646
|
+
writeWranglerToml({
|
|
647
|
+
main: "index.js",
|
|
648
|
+
dev: {
|
|
649
|
+
ip: "0.0.0.0",
|
|
650
|
+
},
|
|
651
|
+
});
|
|
652
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
653
|
+
await runWrangler("dev");
|
|
654
|
+
expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("0.0.0.0");
|
|
655
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
656
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
657
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
it("should use --ip command line arg, if provided", async () => {
|
|
661
|
+
writeWranglerToml({
|
|
662
|
+
main: "index.js",
|
|
663
|
+
dev: {
|
|
664
|
+
ip: "1.1.1.1",
|
|
665
|
+
},
|
|
666
|
+
});
|
|
667
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
668
|
+
await runWrangler("dev --ip=0.0.0.0");
|
|
669
|
+
expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("0.0.0.0");
|
|
670
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
671
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
672
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
673
|
+
});
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
describe("port", () => {
|
|
677
|
+
it("should default port to 8787 if it is not in use", async () => {
|
|
678
|
+
writeWranglerToml({
|
|
679
|
+
main: "index.js",
|
|
680
|
+
});
|
|
681
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
682
|
+
await runWrangler("dev");
|
|
683
|
+
expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(8787);
|
|
684
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
685
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
686
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
it("should use to `port` from `wrangler.toml`, if available", async () => {
|
|
690
|
+
writeWranglerToml({
|
|
691
|
+
main: "index.js",
|
|
692
|
+
dev: {
|
|
693
|
+
port: 8888,
|
|
694
|
+
},
|
|
695
|
+
});
|
|
696
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
697
|
+
// Mock `getPort()` to resolve to a completely different port.
|
|
698
|
+
(getPort as jest.Mock).mockResolvedValue(98765);
|
|
699
|
+
|
|
700
|
+
await runWrangler("dev");
|
|
701
|
+
expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(8888);
|
|
702
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
703
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
704
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
it("should use --port command line arg, if provided", async () => {
|
|
708
|
+
writeWranglerToml({
|
|
709
|
+
main: "index.js",
|
|
710
|
+
dev: {
|
|
711
|
+
port: 8888,
|
|
712
|
+
},
|
|
713
|
+
});
|
|
714
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
715
|
+
// Mock `getPort()` to resolve to a completely different port.
|
|
716
|
+
(getPort as jest.Mock).mockResolvedValue(98765);
|
|
717
|
+
|
|
718
|
+
await runWrangler("dev --port=9999");
|
|
719
|
+
expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(9999);
|
|
720
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
721
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
722
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
723
|
+
});
|
|
724
|
+
|
|
725
|
+
it("should use a different port to the default if it is in use", async () => {
|
|
726
|
+
writeWranglerToml({
|
|
727
|
+
main: "index.js",
|
|
728
|
+
});
|
|
729
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
730
|
+
// Mock `getPort()` to resolve to a completely different port.
|
|
731
|
+
(getPort as jest.Mock).mockResolvedValue(98765);
|
|
732
|
+
|
|
733
|
+
await runWrangler("dev");
|
|
734
|
+
expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(98765);
|
|
735
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
736
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
737
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
738
|
+
});
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
describe("durable_objects", () => {
|
|
742
|
+
it("should warn if there are remote Durable Objects, or missing migrations for local Durable Objects", async () => {
|
|
743
|
+
writeWranglerToml({
|
|
744
|
+
main: "index.js",
|
|
745
|
+
durable_objects: {
|
|
746
|
+
bindings: [
|
|
747
|
+
{ name: "NAME_1", class_name: "CLASS_1" },
|
|
748
|
+
{
|
|
749
|
+
name: "NAME_2",
|
|
750
|
+
class_name: "CLASS_2",
|
|
751
|
+
script_name: "SCRIPT_A",
|
|
752
|
+
},
|
|
753
|
+
{ name: "NAME_3", class_name: "CLASS_3" },
|
|
754
|
+
{
|
|
755
|
+
name: "NAME_4",
|
|
756
|
+
class_name: "CLASS_4",
|
|
757
|
+
script_name: "SCRIPT_B",
|
|
758
|
+
},
|
|
759
|
+
],
|
|
760
|
+
},
|
|
761
|
+
});
|
|
762
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
763
|
+
await runWrangler("dev");
|
|
764
|
+
expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("localhost");
|
|
765
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
766
|
+
"Your worker has access to the following bindings:
|
|
767
|
+
- Durable Objects:
|
|
768
|
+
- NAME_1: CLASS_1
|
|
769
|
+
- NAME_2: CLASS_2 (defined in SCRIPT_A)
|
|
770
|
+
- NAME_3: CLASS_3
|
|
771
|
+
- NAME_4: CLASS_4 (defined in SCRIPT_B)"
|
|
772
|
+
`);
|
|
773
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
774
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mProcessing wrangler.toml configuration:[0m
|
|
775
|
+
|
|
776
|
+
- In wrangler.toml, you have configured [durable_objects] exported by this Worker (CLASS_1,
|
|
777
|
+
CLASS_3), but no [migrations] for them. This may not work as expected until you add a [migrations]
|
|
778
|
+
section to your wrangler.toml. Add this configuration to your wrangler.toml:
|
|
779
|
+
|
|
780
|
+
\`\`\`
|
|
781
|
+
[[migrations]]
|
|
782
|
+
tag = \\"v1\\" # Should be unique for each entry
|
|
783
|
+
new_classes = [\\"CLASS_1\\", \\"CLASS_3\\"]
|
|
784
|
+
\`\`\`
|
|
785
|
+
|
|
786
|
+
Refer to
|
|
787
|
+
[4mhttps://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml[0m
|
|
788
|
+
for more details.
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mWARNING: You have Durable Object bindings that are not defined locally in the worker being developed.[0m
|
|
792
|
+
|
|
793
|
+
Be aware that changes to the data stored in these Durable Objects will be permanent and affect the
|
|
794
|
+
live instances.
|
|
795
|
+
Remote Durable Objects that are affected:
|
|
796
|
+
- {\\"name\\":\\"NAME_2\\",\\"class_name\\":\\"CLASS_2\\",\\"script_name\\":\\"SCRIPT_A\\"}
|
|
797
|
+
- {\\"name\\":\\"NAME_4\\",\\"class_name\\":\\"CLASS_4\\",\\"script_name\\":\\"SCRIPT_B\\"}
|
|
798
|
+
|
|
799
|
+
"
|
|
800
|
+
`);
|
|
801
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
802
|
+
});
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
describe(".dev.vars", () => {
|
|
806
|
+
it("should override `vars` bindings from `wrangler.toml` with values in `.dev.vars`", async () => {
|
|
807
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
808
|
+
|
|
809
|
+
const localVarsEnvContent = dedent`
|
|
749
810
|
# Preceding comment
|
|
750
811
|
VAR_1="var #1 value" # End of line comment
|
|
751
812
|
VAR_3="var #3 value"
|
|
@@ -755,256 +816,344 @@ describe("wrangler dev", () => {
|
|
|
755
816
|
EMPTY=
|
|
756
817
|
UNQUOTED= unquoted value
|
|
757
818
|
`;
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
819
|
+
fs.writeFileSync(".dev.vars", localVarsEnvContent, "utf8");
|
|
820
|
+
|
|
821
|
+
writeWranglerToml({
|
|
822
|
+
main: "index.js",
|
|
823
|
+
vars: {
|
|
824
|
+
VAR_1: "original value 1",
|
|
825
|
+
VAR_2: "original value 2", // should not get overridden
|
|
826
|
+
VAR_3: "original value 3",
|
|
827
|
+
VAR_MULTI_LINE_1: "original multi-line 1",
|
|
828
|
+
VAR_MULTI_LINE_2: "original multi-line 2",
|
|
829
|
+
EMPTY: "original empty",
|
|
830
|
+
UNQUOTED: "original unquoted",
|
|
831
|
+
},
|
|
832
|
+
});
|
|
833
|
+
await runWrangler("dev");
|
|
834
|
+
const varBindings: Record<string, unknown> = (Dev as jest.Mock).mock
|
|
835
|
+
.calls[0][0].bindings.vars;
|
|
836
|
+
|
|
837
|
+
expect(varBindings).toEqual({
|
|
838
|
+
VAR_1: "var #1 value",
|
|
839
|
+
VAR_2: "original value 2",
|
|
840
|
+
VAR_3: "var #3 value",
|
|
841
|
+
VAR_MULTI_LINE_1: "A: line 1\nline 2",
|
|
842
|
+
VAR_MULTI_LINE_2: "B: line 1\nline 2",
|
|
843
|
+
EMPTY: "",
|
|
844
|
+
UNQUOTED: "unquoted value", // Note that whitespace is trimmed
|
|
845
|
+
});
|
|
846
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
847
|
+
"Using vars defined in .dev.vars
|
|
848
|
+
Your worker has access to the following bindings:
|
|
849
|
+
- Vars:
|
|
850
|
+
- VAR_1: \\"(hidden)\\"
|
|
851
|
+
- VAR_2: \\"original value 2\\"
|
|
852
|
+
- VAR_3: \\"(hidden)\\"
|
|
853
|
+
- VAR_MULTI_LINE_1: \\"(hidden)\\"
|
|
854
|
+
- VAR_MULTI_LINE_2: \\"(hidden)\\"
|
|
855
|
+
- EMPTY: \\"(hidden)\\"
|
|
856
|
+
- UNQUOTED: \\"(hidden)\\""
|
|
857
|
+
`);
|
|
858
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
859
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
860
|
+
});
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
describe("serve static assets", () => {
|
|
864
|
+
it("should error if --site is used with no value", async () => {
|
|
865
|
+
await expect(
|
|
866
|
+
runWrangler("dev --site")
|
|
867
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
868
|
+
`"Not enough arguments following: site"`
|
|
869
|
+
);
|
|
870
|
+
|
|
871
|
+
expect(std).toMatchInlineSnapshot(`
|
|
872
|
+
Object {
|
|
873
|
+
"debug": "",
|
|
874
|
+
"err": "[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough arguments following: site[0m
|
|
875
|
+
|
|
876
|
+
",
|
|
877
|
+
"out": "
|
|
878
|
+
wrangler dev [script]
|
|
879
|
+
|
|
880
|
+
👂 Start a local server for developing your worker
|
|
881
|
+
|
|
882
|
+
Positionals:
|
|
883
|
+
script The path to an entry point for your worker [string]
|
|
884
|
+
|
|
885
|
+
Flags:
|
|
886
|
+
-c, --config Path to .toml configuration file [string]
|
|
887
|
+
-h, --help Show help [boolean]
|
|
888
|
+
-v, --version Show version number [boolean]
|
|
889
|
+
|
|
890
|
+
Options:
|
|
891
|
+
--name Name of the worker [string]
|
|
892
|
+
--no-bundle Skip internal build steps and directly publish script [boolean] [default: false]
|
|
893
|
+
--format Choose an entry type [deprecated] [choices: \\"modules\\", \\"service-worker\\"]
|
|
894
|
+
-e, --env Perform on a specific environment [string]
|
|
895
|
+
--compatibility-date Date to use for compatibility checks [string]
|
|
896
|
+
--compatibility-flags, --compatibility-flag Flags to use for compatibility checks [array]
|
|
897
|
+
--latest Use the latest version of the worker runtime [boolean] [default: true]
|
|
898
|
+
--ip IP address to listen on, defaults to \`localhost\` [string]
|
|
899
|
+
--port Port to listen on [number]
|
|
900
|
+
--inspector-port Port for devtools to connect to [number]
|
|
901
|
+
--routes, --route Routes to upload [array]
|
|
902
|
+
--host Host to forward requests to, defaults to the zone of project [string]
|
|
903
|
+
--local-protocol Protocol to listen to requests on, defaults to http. [choices: \\"http\\", \\"https\\"]
|
|
904
|
+
--local-upstream Host to act as origin in local mode, defaults to dev.host or route [string]
|
|
905
|
+
--assets Static assets to be served [string]
|
|
906
|
+
--site Root folder of static assets for Workers Sites [string]
|
|
907
|
+
--site-include Array of .gitignore-style patterns that match file or directory names from the sites directory. Only matched items will be uploaded. [array]
|
|
908
|
+
--site-exclude Array of .gitignore-style patterns that match file or directory names from the sites directory. Matched items will not be uploaded. [array]
|
|
909
|
+
--upstream-protocol Protocol to forward requests to host on, defaults to https. [choices: \\"http\\", \\"https\\"]
|
|
910
|
+
--jsx-factory The function that is called for each JSX element [string]
|
|
911
|
+
--jsx-fragment The function that is called for each JSX fragment [string]
|
|
912
|
+
--tsconfig Path to a custom tsconfig.json file [string]
|
|
913
|
+
-l, --local Run on my machine [boolean] [default: false]
|
|
914
|
+
--minify Minify the script [boolean]
|
|
915
|
+
--node-compat Enable node.js compatibility [boolean]
|
|
916
|
+
--experimental-enable-local-persistence Enable persistence for this session (only for local mode) [boolean]
|
|
917
|
+
--inspect Enable dev tools [deprecated] [boolean]",
|
|
918
|
+
"warn": "",
|
|
919
|
+
}
|
|
920
|
+
`);
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
it("should error if --assets and --site are used together", async () => {
|
|
924
|
+
writeWranglerToml({
|
|
925
|
+
main: "./index.js",
|
|
926
|
+
});
|
|
927
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
928
|
+
await expect(
|
|
929
|
+
runWrangler("dev --assets abc --site xyz")
|
|
930
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
931
|
+
`"Cannot use Assets and Workers Sites in the same Worker."`
|
|
932
|
+
);
|
|
933
|
+
});
|
|
934
|
+
|
|
935
|
+
it("should error if --assets and config.site are used together", async () => {
|
|
936
|
+
writeWranglerToml({
|
|
937
|
+
main: "./index.js",
|
|
938
|
+
site: {
|
|
939
|
+
bucket: "xyz",
|
|
940
|
+
},
|
|
941
|
+
});
|
|
942
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
943
|
+
await expect(
|
|
944
|
+
runWrangler("dev --assets abc")
|
|
945
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
946
|
+
`"Cannot use Assets and Workers Sites in the same Worker."`
|
|
947
|
+
);
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
it("should error if config.assets and --site are used together", async () => {
|
|
951
|
+
writeWranglerToml({
|
|
952
|
+
main: "./index.js",
|
|
953
|
+
assets: "abc",
|
|
954
|
+
});
|
|
955
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
956
|
+
await expect(
|
|
957
|
+
runWrangler("dev --site xyz")
|
|
958
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
959
|
+
`"Cannot use Assets and Workers Sites in the same Worker."`
|
|
960
|
+
);
|
|
961
|
+
});
|
|
962
|
+
|
|
963
|
+
it("should error if config.assets and config.site are used together", async () => {
|
|
964
|
+
writeWranglerToml({
|
|
965
|
+
main: "./index.js",
|
|
966
|
+
assets: "abc",
|
|
967
|
+
site: {
|
|
968
|
+
bucket: "xyz",
|
|
969
|
+
},
|
|
970
|
+
});
|
|
971
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
972
|
+
await expect(
|
|
973
|
+
runWrangler("dev --assets abc")
|
|
974
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
975
|
+
`"Cannot use Assets and Workers Sites in the same Worker."`
|
|
976
|
+
);
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
it("should indicate whether Sites is being used", async () => {
|
|
980
|
+
writeWranglerToml({
|
|
981
|
+
main: "index.js",
|
|
982
|
+
});
|
|
983
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
984
|
+
|
|
985
|
+
await runWrangler("dev");
|
|
986
|
+
expect((Dev as jest.Mock).mock.calls[0][0].isWorkersSite).toEqual(false);
|
|
987
|
+
|
|
988
|
+
await runWrangler("dev --site abc");
|
|
989
|
+
expect((Dev as jest.Mock).mock.calls[1][0].isWorkersSite).toEqual(true);
|
|
990
|
+
|
|
991
|
+
await runWrangler("dev --assets abc");
|
|
992
|
+
expect((Dev as jest.Mock).mock.calls[2][0].isWorkersSite).toEqual(false);
|
|
993
|
+
});
|
|
994
|
+
|
|
995
|
+
it("should warn if --assets is used", async () => {
|
|
996
|
+
writeWranglerToml({
|
|
997
|
+
main: "./index.js",
|
|
998
|
+
});
|
|
999
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
1000
|
+
|
|
1001
|
+
await runWrangler('dev --assets "./assets"');
|
|
1002
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1003
|
+
Object {
|
|
1004
|
+
"debug": "",
|
|
1005
|
+
"err": "",
|
|
1006
|
+
"out": "",
|
|
1007
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe --assets argument is experimental and may change or break at any time[0m
|
|
1008
|
+
|
|
1009
|
+
",
|
|
1010
|
+
}
|
|
1011
|
+
`);
|
|
1012
|
+
});
|
|
1013
|
+
|
|
1014
|
+
it("should warn if config.assets is used", async () => {
|
|
1015
|
+
writeWranglerToml({
|
|
1016
|
+
main: "./index.js",
|
|
1017
|
+
assets: "./assets",
|
|
1018
|
+
});
|
|
1019
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
1020
|
+
|
|
1021
|
+
await runWrangler("dev");
|
|
1022
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1023
|
+
Object {
|
|
1024
|
+
"debug": "",
|
|
1025
|
+
"err": "",
|
|
1026
|
+
"out": "",
|
|
1027
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mProcessing wrangler.toml configuration:[0m
|
|
1028
|
+
|
|
1029
|
+
- \\"assets\\" fields are experimental and may change or break at any time.
|
|
1030
|
+
|
|
1031
|
+
",
|
|
1032
|
+
}
|
|
1033
|
+
`);
|
|
1034
|
+
});
|
|
1035
|
+
});
|
|
1036
|
+
|
|
1037
|
+
describe("--inspect", () => {
|
|
1038
|
+
it("should warn if --inspect is used", async () => {
|
|
1039
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
1040
|
+
await runWrangler("dev index.js --inspect");
|
|
1041
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1042
|
+
Object {
|
|
1043
|
+
"debug": "",
|
|
1044
|
+
"err": "",
|
|
1045
|
+
"out": "",
|
|
1046
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mPassing --inspect is unnecessary, now you can always connect to devtools.[0m
|
|
1047
|
+
|
|
1048
|
+
",
|
|
1049
|
+
}
|
|
1050
|
+
`);
|
|
1051
|
+
});
|
|
1052
|
+
});
|
|
1053
|
+
|
|
1054
|
+
describe("service bindings", () => {
|
|
1055
|
+
it("should warn when using service bindings", async () => {
|
|
1056
|
+
writeWranglerToml({
|
|
1057
|
+
services: [
|
|
1058
|
+
{ binding: "WorkerA", service: "A" },
|
|
1059
|
+
{ binding: "WorkerB", service: "B", environment: "staging" },
|
|
1060
|
+
],
|
|
1061
|
+
});
|
|
1062
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
1063
|
+
await runWrangler("dev index.js");
|
|
1064
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1065
|
+
Object {
|
|
1066
|
+
"debug": "",
|
|
1067
|
+
"err": "",
|
|
1068
|
+
"out": "Your worker has access to the following bindings:
|
|
1069
|
+
- Services:
|
|
1070
|
+
- WorkerA: A
|
|
1071
|
+
- WorkerB: B - staging",
|
|
1072
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mProcessing wrangler.toml configuration:[0m
|
|
1073
|
+
|
|
1074
|
+
- \\"services\\" fields are experimental and may change or break at any time.
|
|
1075
|
+
|
|
1076
|
+
|
|
1077
|
+
[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThis worker is bound to live services: WorkerA (A), WorkerB (B@staging)[0m
|
|
1078
|
+
|
|
1079
|
+
",
|
|
1080
|
+
}
|
|
1081
|
+
`);
|
|
1082
|
+
});
|
|
1083
|
+
});
|
|
1084
|
+
|
|
1085
|
+
describe("print bindings", () => {
|
|
1086
|
+
it("should print bindings", async () => {
|
|
1087
|
+
writeWranglerToml({
|
|
1088
|
+
services: [
|
|
1089
|
+
{ binding: "WorkerA", service: "A" },
|
|
1090
|
+
{ binding: "WorkerB", service: "B", environment: "staging" },
|
|
1091
|
+
],
|
|
1092
|
+
});
|
|
1093
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
1094
|
+
await runWrangler("dev index.js");
|
|
1095
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1096
|
+
Object {
|
|
1097
|
+
"debug": "",
|
|
1098
|
+
"err": "",
|
|
1099
|
+
"out": "Your worker has access to the following bindings:
|
|
1100
|
+
- Services:
|
|
1101
|
+
- WorkerA: A
|
|
1102
|
+
- WorkerB: B - staging",
|
|
1103
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mProcessing wrangler.toml configuration:[0m
|
|
1104
|
+
|
|
1105
|
+
- \\"services\\" fields are experimental and may change or break at any time.
|
|
1106
|
+
|
|
1107
|
+
|
|
1108
|
+
[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThis worker is bound to live services: WorkerA (A), WorkerB (B@staging)[0m
|
|
1109
|
+
|
|
1110
|
+
",
|
|
1111
|
+
}
|
|
1112
|
+
`);
|
|
1113
|
+
});
|
|
1114
|
+
|
|
1115
|
+
it("should mask vars that were overriden in .dev.vars", async () => {
|
|
1116
|
+
writeWranglerToml({
|
|
1117
|
+
vars: {
|
|
1118
|
+
variable: 123,
|
|
1119
|
+
overriden: "original values",
|
|
1120
|
+
},
|
|
1121
|
+
});
|
|
1122
|
+
fs.writeFileSync(
|
|
1123
|
+
".dev.vars",
|
|
1124
|
+
`
|
|
976
1125
|
SECRET = "A secret"
|
|
977
1126
|
overriden = "overriden value"
|
|
978
1127
|
`
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1128
|
+
);
|
|
1129
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
1130
|
+
await runWrangler("dev index.js");
|
|
1131
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1132
|
+
Object {
|
|
1133
|
+
"debug": "",
|
|
1134
|
+
"err": "",
|
|
1135
|
+
"out": "Using vars defined in .dev.vars
|
|
1136
|
+
Your worker has access to the following bindings:
|
|
1137
|
+
- Vars:
|
|
1138
|
+
- variable: \\"123\\"
|
|
1139
|
+
- overriden: \\"(hidden)\\"
|
|
1140
|
+
- SECRET: \\"(hidden)\\"",
|
|
1141
|
+
"warn": "",
|
|
1142
|
+
}
|
|
1143
|
+
`);
|
|
1144
|
+
});
|
|
1145
|
+
});
|
|
997
1146
|
});
|
|
998
1147
|
|
|
999
1148
|
function mockGetZones(domain: string, zones: { id: string }[] = []) {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1149
|
+
const removeMock = setMockResponse(
|
|
1150
|
+
"/zones",
|
|
1151
|
+
"GET",
|
|
1152
|
+
(_urlPieces, _init, queryParams) => {
|
|
1153
|
+
expect([...queryParams.entries()]).toEqual([["name", domain]]);
|
|
1154
|
+
// Because the API URL `/zones` is the same for each request, we can get into a situation where earlier mocks get triggered for later requests. So, we simply clear the mock on every trigger.
|
|
1155
|
+
removeMock();
|
|
1156
|
+
return zones;
|
|
1157
|
+
}
|
|
1158
|
+
);
|
|
1010
1159
|
}
|