wrangler 0.0.0-e1c615f → 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.
Files changed (85) hide show
  1. package/bin/wrangler.js +2 -2
  2. package/package.json +28 -13
  3. package/pages/functions/buildWorker.ts +6 -1
  4. package/pages/functions/filepath-routing.test.ts +112 -28
  5. package/pages/functions/filepath-routing.ts +88 -131
  6. package/pages/functions/routes.ts +11 -18
  7. package/pages/functions/template-worker.ts +21 -28
  8. package/src/__tests__/configuration.test.ts +2185 -0
  9. package/src/__tests__/dev.test.tsx +56 -9
  10. package/src/__tests__/guess-worker-format.test.ts +66 -0
  11. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  12. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  13. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  14. package/src/__tests__/helpers/mock-account-id.ts +30 -0
  15. package/src/__tests__/helpers/mock-bin.ts +36 -0
  16. package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +53 -17
  17. package/src/__tests__/helpers/mock-console.ts +62 -0
  18. package/src/__tests__/{mock-dialogs.ts → helpers/mock-dialogs.ts} +1 -1
  19. package/src/__tests__/helpers/mock-kv.ts +40 -0
  20. package/src/__tests__/helpers/mock-user.ts +27 -0
  21. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  22. package/src/__tests__/helpers/run-in-tmp.ts +29 -0
  23. package/src/__tests__/helpers/run-wrangler.ts +16 -0
  24. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  25. package/src/__tests__/index.test.ts +655 -76
  26. package/src/__tests__/jest.setup.ts +37 -2
  27. package/src/__tests__/kv.test.ts +441 -398
  28. package/src/__tests__/logout.test.ts +50 -0
  29. package/src/__tests__/package-manager.test.ts +206 -0
  30. package/src/__tests__/parse.test.ts +322 -0
  31. package/src/__tests__/publish.test.ts +2406 -0
  32. package/src/__tests__/r2.test.ts +198 -0
  33. package/src/__tests__/secret.test.ts +326 -0
  34. package/src/__tests__/sentry.test.ts +146 -0
  35. package/src/__tests__/tail.test.ts +564 -0
  36. package/src/__tests__/whoami.test.tsx +86 -0
  37. package/src/api/form_data.ts +112 -26
  38. package/src/api/preview.ts +34 -15
  39. package/src/api/worker.ts +58 -27
  40. package/src/bundle.ts +133 -0
  41. package/src/cfetch/index.ts +21 -19
  42. package/src/cfetch/internal.ts +85 -21
  43. package/src/cli.ts +10 -0
  44. package/src/config/README.md +107 -0
  45. package/src/config/config.ts +265 -0
  46. package/src/config/diagnostics.ts +80 -0
  47. package/src/config/environment.ts +305 -0
  48. package/src/config/index.ts +52 -0
  49. package/src/config/validation-helpers.ts +370 -0
  50. package/src/config/validation.ts +1017 -0
  51. package/src/dev.tsx +455 -368
  52. package/src/dialogs.tsx +2 -2
  53. package/src/entry.ts +57 -0
  54. package/src/environment-variables.ts +33 -0
  55. package/src/guess-worker-format.ts +68 -0
  56. package/src/index.tsx +1044 -646
  57. package/src/inspect.ts +609 -0
  58. package/src/kv.tsx +47 -39
  59. package/src/module-collection.ts +142 -36
  60. package/src/open-in-browser.ts +13 -0
  61. package/src/package-manager.ts +126 -0
  62. package/src/pages.tsx +139 -62
  63. package/src/parse.ts +183 -0
  64. package/src/paths.ts +26 -0
  65. package/src/proxy.ts +350 -77
  66. package/src/publish.ts +307 -289
  67. package/src/r2.ts +50 -0
  68. package/src/reporting.ts +115 -0
  69. package/src/sites.tsx +183 -56
  70. package/src/tail/filters.ts +279 -0
  71. package/src/tail/index.ts +299 -0
  72. package/src/tail/printing.ts +62 -0
  73. package/src/user.tsx +137 -110
  74. package/src/whoami.tsx +69 -0
  75. package/templates/new-worker.js +15 -0
  76. package/templates/new-worker.ts +15 -0
  77. package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
  78. package/templates/tsconfig.json +105 -0
  79. package/wrangler-dist/cli.js +127861 -111486
  80. package/wrangler-dist/cli.js.map +3 -3
  81. package/src/__tests__/run-in-tmp.ts +0 -19
  82. package/src/__tests__/run-wrangler.ts +0 -32
  83. package/src/api/inspect.ts +0 -430
  84. package/src/config.ts +0 -131
  85. package/src/tail.tsx +0 -73
@@ -0,0 +1,2185 @@
1
+ import path from "node:path";
2
+ import { normalizeAndValidateConfig } from "../config/validation";
3
+ import type { RawConfig, RawEnvironment } from "../config";
4
+
5
+ describe("normalizeAndValidateConfig()", () => {
6
+ it("should use defaults for empty configuration", () => {
7
+ const { config, diagnostics } = normalizeAndValidateConfig({}, undefined);
8
+
9
+ expect(config).toEqual({
10
+ account_id: undefined,
11
+ build: {
12
+ command: undefined,
13
+ cwd: undefined,
14
+ watch_dir: undefined,
15
+ },
16
+ compatibility_date: undefined,
17
+ compatibility_flags: [],
18
+ configPath: undefined,
19
+ dev: {
20
+ ip: "127.0.0.1",
21
+ local_protocol: "http",
22
+ port: 8787,
23
+ upstream_protocol: "https",
24
+ },
25
+ durable_objects: {
26
+ bindings: [],
27
+ },
28
+ env: {},
29
+ jsx_factory: "React.createElement",
30
+ jsx_fragment: "React.Fragment",
31
+ kv_namespaces: [],
32
+ legacy_env: true,
33
+ main: undefined,
34
+ migrations: [],
35
+ name: undefined,
36
+ r2_buckets: [],
37
+ route: undefined,
38
+ routes: undefined,
39
+ rules: [],
40
+ site: undefined,
41
+ text_blobs: undefined,
42
+ triggers: {
43
+ crons: [],
44
+ },
45
+ unsafe: {
46
+ bindings: [],
47
+ },
48
+ usage_model: undefined,
49
+ vars: {},
50
+ wasm_modules: undefined,
51
+ workers_dev: true,
52
+ zone_id: undefined,
53
+ });
54
+ expect(diagnostics.hasErrors()).toBe(false);
55
+ expect(diagnostics.hasWarnings()).toBe(false);
56
+ });
57
+
58
+ describe("top-level non-environment configuration", () => {
59
+ it("should override config defaults with provided values", () => {
60
+ const main = "src/index.ts";
61
+ const expectedConfig: RawConfig = {
62
+ main,
63
+ legacy_env: true,
64
+ dev: {
65
+ ip: "255.255.255.255",
66
+ port: 9999,
67
+ local_protocol: "HTTPS",
68
+ upstream_protocol: "HTTP",
69
+ },
70
+ build: {
71
+ command: "COMMAND",
72
+ cwd: "CWD",
73
+ watch_dir: "WATCH_DIR",
74
+ },
75
+ };
76
+
77
+ const { config, diagnostics } = normalizeAndValidateConfig(
78
+ expectedConfig,
79
+ undefined
80
+ );
81
+
82
+ const resolvedMain = path.resolve(process.cwd(), main);
83
+ expect(config).toEqual(
84
+ expect.objectContaining({ ...expectedConfig, main: resolvedMain })
85
+ );
86
+ expect(diagnostics.hasErrors()).toBe(false);
87
+ expect(diagnostics.hasWarnings()).toBe(false);
88
+ });
89
+
90
+ it("should error on invalid top level fields", () => {
91
+ const expectedConfig = {
92
+ main: 111,
93
+ legacy_env: "FOO",
94
+ dev: {
95
+ ip: 222,
96
+ port: "FOO",
97
+ local_protocol: 333,
98
+ upstream_protocol: 444,
99
+ },
100
+ build: {
101
+ command: 555,
102
+ cwd: 666,
103
+ watch_dir: 777,
104
+ },
105
+ };
106
+
107
+ const { config, diagnostics } = normalizeAndValidateConfig(
108
+ expectedConfig as unknown as RawConfig,
109
+ undefined
110
+ );
111
+
112
+ expect(config).toEqual(
113
+ expect.objectContaining({ ...expectedConfig, main: undefined })
114
+ );
115
+ expect(diagnostics.hasWarnings()).toBe(false);
116
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
117
+ "Processing wrangler configuration:
118
+ - ERROR: \\"build.command\\" should be of type string but got 555.
119
+ - ERROR: \\"build.cwd\\" should be of type string but got 666.
120
+ - ERROR: \\"build.watch_dir\\" should be of type string but got 777.
121
+ - ERROR: \\"legacy_env\\" should be of type boolean but got \\"FOO\\".
122
+ - ERROR: \\"main\\" should be a string but got 111
123
+ - ERROR: \\"dev.ip\\" should be of type string but got 222.
124
+ - ERROR: \\"dev.port\\" should be of type number but got \\"FOO\\".
125
+ - ERROR: \\"dev.local_protocol\\" should be of type string but got 333.
126
+ - ERROR: \\"dev.upstream_protocol\\" should be of type string but got 444."
127
+ `);
128
+ });
129
+
130
+ it("should warn on and remove unexpected top level fields", () => {
131
+ const expectedConfig = {
132
+ miniflare: {
133
+ host: "127.0.0.1",
134
+ },
135
+ };
136
+
137
+ const { config, diagnostics } = normalizeAndValidateConfig(
138
+ expectedConfig as unknown as RawConfig,
139
+ undefined
140
+ );
141
+
142
+ expect("miniflare" in config).toBe(false);
143
+ expect(diagnostics.hasErrors()).toBe(false);
144
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
145
+ "Processing wrangler configuration:
146
+ - Unexpected fields found in top-level field: \\"miniflare\\""
147
+ `);
148
+ });
149
+
150
+ it("should override build.upload config defaults with provided values and warn about deprecations", () => {
151
+ const expectedConfig: RawConfig = {
152
+ build: {
153
+ upload: {
154
+ dir: "src",
155
+ format: "modules",
156
+ main: "index.ts",
157
+ rules: [{ type: "Text", globs: ["GLOB"], fallthrough: true }],
158
+ },
159
+ },
160
+ };
161
+
162
+ const { config, diagnostics } = normalizeAndValidateConfig(
163
+ expectedConfig,
164
+ path.resolve("project/wrangler.toml")
165
+ );
166
+
167
+ expect(config.main).toEqual(path.resolve("project/src/index.ts"));
168
+ expect(config.build.upload).toBeUndefined();
169
+ expect(diagnostics.hasErrors()).toBe(false);
170
+ expect(diagnostics.hasWarnings()).toBe(true);
171
+ expect(normalizePath(diagnostics.renderWarnings()))
172
+ .toMatchInlineSnapshot(`
173
+ "Processing project/wrangler.toml configuration:
174
+ - DEPRECATION: \\"build.upload.format\\":
175
+ The format is inferred automatically from the code.
176
+ - DEPRECATION: \\"build.upload.main\\":
177
+ Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
178
+ Then add the top level \`main\` field to your configuration file:
179
+ \`\`\`
180
+ main = \\"src/index.ts\\"
181
+ \`\`\`
182
+ - DEPRECATION: \\"build.upload.dir\\":
183
+ Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the Worker.
184
+ - DEPRECATION: The \`build.upload.rules\` config field is no longer used, the rules should be specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration file, and add this:
185
+ \`\`\`
186
+ [[rules]]
187
+ type = \\"Text\\"
188
+ globs = [ \\"GLOB\\" ]
189
+ fallthrough = true
190
+ \`\`\`"
191
+ `);
192
+ });
193
+
194
+ it("should override `migrations` config defaults with provided values", () => {
195
+ const expectedConfig: RawConfig = {
196
+ migrations: [
197
+ {
198
+ tag: "TAG",
199
+ new_classes: ["CLASS_1", "CLASS_2"],
200
+ renamed_classes: [
201
+ {
202
+ from: "FROM_CLASS",
203
+ to: "TO_CLASS",
204
+ },
205
+ ],
206
+ deleted_classes: ["CLASS_3", "CLASS_4"],
207
+ },
208
+ ],
209
+ };
210
+
211
+ const { config, diagnostics } = normalizeAndValidateConfig(
212
+ expectedConfig,
213
+ undefined
214
+ );
215
+
216
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
217
+ expect(diagnostics.hasErrors()).toBe(false);
218
+ expect(diagnostics.hasWarnings()).toBe(false);
219
+ });
220
+
221
+ it("should error on invalid `migrations` values", () => {
222
+ const expectedConfig = {
223
+ migrations: [
224
+ {
225
+ tag: 111,
226
+ new_classes: [222, 333],
227
+ renamed_classes: [
228
+ {
229
+ from: 444,
230
+ to: 555,
231
+ },
232
+ ],
233
+ deleted_classes: [666, 777],
234
+ },
235
+ ],
236
+ };
237
+
238
+ const { config, diagnostics } = normalizeAndValidateConfig(
239
+ expectedConfig as unknown as RawConfig,
240
+ undefined
241
+ );
242
+
243
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
244
+ expect(diagnostics.hasWarnings()).toBe(false);
245
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
246
+ "Processing wrangler configuration:
247
+ - ERROR: \\"migrations[0].tag\\" should be of type string but got 111.
248
+ - ERROR: \\"migrations[0].new_classes.[0]\\" should be of type string but got 222.
249
+ - ERROR: \\"migrations[0].new_classes.[1]\\" should be of type string but got 333.
250
+ - \\"migrations[0].renamed_classes\\" should be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
251
+ - ERROR: \\"migrations[0].deleted_classes.[0]\\" should be of type string but got 666.
252
+ - ERROR: \\"migrations[0].deleted_classes.[1]\\" should be of type string but got 777."
253
+ `);
254
+ });
255
+
256
+ it("should override `site` config defaults with provided values", () => {
257
+ const expectedConfig: RawConfig = {
258
+ site: {
259
+ bucket: "BUCKET",
260
+ "entry-point": "ENTRY_POINT",
261
+ include: ["INCLUDE_1", "INCLUDE_2"],
262
+ exclude: ["EXCLUDE_1", "EXCLUDE_2"],
263
+ },
264
+ };
265
+
266
+ const { config, diagnostics } = normalizeAndValidateConfig(
267
+ expectedConfig,
268
+ undefined
269
+ );
270
+
271
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
272
+ expect(diagnostics.hasErrors()).toBe(false);
273
+ expect(diagnostics.hasWarnings()).toBe(false);
274
+ });
275
+
276
+ it("should error if `site` config is missing `bucket`", () => {
277
+ const expectedConfig: RawConfig = {
278
+ site: {
279
+ "entry-point": "ENTRY_POINT",
280
+ include: ["INCLUDE_1", "INCLUDE_2"],
281
+ exclude: ["EXCLUDE_1", "EXCLUDE_2"],
282
+ },
283
+ } as RawConfig;
284
+
285
+ const { config, diagnostics } = normalizeAndValidateConfig(
286
+ expectedConfig,
287
+ undefined
288
+ );
289
+
290
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
291
+ expect(diagnostics.hasErrors()).toBe(true);
292
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
293
+ "Processing wrangler configuration:
294
+ - ERROR: \\"site.bucket\\" is a required field."
295
+ `);
296
+ expect(diagnostics.hasWarnings()).toBe(false);
297
+ });
298
+
299
+ it("should error on invalid `site` values", () => {
300
+ const expectedConfig = {
301
+ site: {
302
+ bucket: "BUCKET",
303
+ "entry-point": 111,
304
+ include: [222, 333],
305
+ exclude: [444, 555],
306
+ },
307
+ };
308
+
309
+ const { config, diagnostics } = normalizeAndValidateConfig(
310
+ expectedConfig as unknown as RawConfig,
311
+ undefined
312
+ );
313
+
314
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
315
+ expect(diagnostics.hasWarnings()).toBe(false);
316
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
317
+ "Processing wrangler configuration:
318
+ - ERROR: \\"site.entry_point\\" should be of type string but got 111.
319
+ - ERROR: \\"sites.include.[0]\\" should be of type string but got 222.
320
+ - ERROR: \\"sites.include.[1]\\" should be of type string but got 333.
321
+ - ERROR: \\"sites.exclude.[0]\\" should be of type string but got 444.
322
+ - ERROR: \\"sites.exclude.[1]\\" should be of type string but got 555."
323
+ `);
324
+ });
325
+
326
+ it("should map `wasm_module` paths from relative to the config path to relative to the cwd", () => {
327
+ const expectedConfig: RawConfig = {
328
+ wasm_modules: {
329
+ MODULE_1: "path/to/module_1.mjs",
330
+ MODULE_2: "module_2.mjs",
331
+ },
332
+ };
333
+
334
+ const { config, diagnostics } = normalizeAndValidateConfig(
335
+ expectedConfig,
336
+ "project/wrangler.toml"
337
+ );
338
+
339
+ expect(config).toEqual(
340
+ expect.objectContaining({
341
+ wasm_modules: {
342
+ MODULE_1: path.normalize("project/path/to/module_1.mjs"),
343
+ MODULE_2: path.normalize("project/module_2.mjs"),
344
+ },
345
+ })
346
+ );
347
+ expect(diagnostics.hasErrors()).toBe(false);
348
+ expect(diagnostics.hasWarnings()).toBe(false);
349
+ });
350
+
351
+ it("should error on invalid `wasm_module` paths", () => {
352
+ const expectedConfig = {
353
+ wasm_modules: {
354
+ MODULE_1: 111,
355
+ MODULE_2: 222,
356
+ },
357
+ };
358
+
359
+ const { config, diagnostics } = normalizeAndValidateConfig(
360
+ expectedConfig as unknown as RawConfig,
361
+ "project/wrangler.toml"
362
+ );
363
+
364
+ expect(config).toEqual(
365
+ expect.objectContaining({
366
+ wasm_modules: {},
367
+ })
368
+ );
369
+ expect(diagnostics.hasWarnings()).toBe(false);
370
+ expect(normalizePath(diagnostics.renderErrors())).toMatchInlineSnapshot(`
371
+ "Processing project/wrangler.toml configuration:
372
+ - Expected \\"wasm_modules['MODULE_1']\\" field to be a string but got 111.
373
+ - Expected \\"wasm_modules['MODULE_2']\\" field to be a string but got 222."
374
+ `);
375
+ });
376
+
377
+ it("should map `text_blobs` paths from relative to the config path to relative to the cwd", () => {
378
+ const expectedConfig: RawConfig = {
379
+ text_blobs: {
380
+ BLOB_1: "path/to/text1.txt",
381
+ BLOB_2: "text2.md",
382
+ },
383
+ };
384
+
385
+ const { config, diagnostics } = normalizeAndValidateConfig(
386
+ expectedConfig,
387
+ "project/wrangler.toml"
388
+ );
389
+
390
+ expect(config).toEqual(
391
+ expect.objectContaining({
392
+ text_blobs: {
393
+ BLOB_1: path.normalize("project/path/to/text1.txt"),
394
+ BLOB_2: path.normalize("project/text2.md"),
395
+ },
396
+ })
397
+ );
398
+ expect(diagnostics.hasErrors()).toBe(false);
399
+ expect(diagnostics.hasWarnings()).toBe(false);
400
+ });
401
+
402
+ it("should error on invalid `text_blob` paths", () => {
403
+ const expectedConfig = {
404
+ text_blobs: {
405
+ MODULE_1: 111,
406
+ MODULE_2: 222,
407
+ },
408
+ };
409
+
410
+ const { config, diagnostics } = normalizeAndValidateConfig(
411
+ expectedConfig as unknown as RawConfig,
412
+ "project/wrangler.toml"
413
+ );
414
+
415
+ expect(config).toEqual(
416
+ expect.objectContaining({
417
+ text_blobs: {},
418
+ })
419
+ );
420
+ expect(diagnostics.hasWarnings()).toBe(false);
421
+ expect(normalizePath(diagnostics.renderErrors())).toMatchInlineSnapshot(`
422
+ "Processing project/wrangler.toml configuration:
423
+ - Expected \\"text_blobs['MODULE_1']\\" field to be a string but got 111.
424
+ - Expected \\"text_blobs['MODULE_2']\\" field to be a string but got 222."
425
+ `);
426
+ });
427
+
428
+ describe("(deprecated)", () => {
429
+ it("should remove and warn about deprecated properties", () => {
430
+ const rawConfig: RawConfig = {
431
+ type: "webpack",
432
+ webpack_config: "CONFIG",
433
+ };
434
+
435
+ const { config, diagnostics } = normalizeAndValidateConfig(
436
+ rawConfig,
437
+ undefined
438
+ );
439
+
440
+ // Note the `.not.` here...
441
+ expect(config).toEqual(
442
+ expect.not.objectContaining({
443
+ type: expect.anything(),
444
+ webpack_config: expect.anything(),
445
+ })
446
+ );
447
+ expect(diagnostics.hasErrors()).toBe(false);
448
+ expect(diagnostics.hasWarnings()).toBe(true);
449
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
450
+ "Processing wrangler configuration:
451
+ - DEPRECATION: \\"type\\":
452
+ DO NOT USE THIS. Most common features now work out of the box with wrangler, including modules, jsx, typescript, etc. If you need anything more, use a custom build.
453
+ - DEPRECATION: \\"webpack_config\\":
454
+ DO NOT USE THIS. Most common features now work out of the box with wrangler, including modules, jsx, typescript, etc. If you need anything more, use a custom build."
455
+ `);
456
+ });
457
+ });
458
+ });
459
+
460
+ describe("top-level environment configuration", () => {
461
+ it("should override config defaults with provided values", () => {
462
+ const expectedConfig: RawConfig = {
463
+ name: "NAME",
464
+ account_id: "ACCOUNT_ID",
465
+ compatibility_date: "2022-01-01",
466
+ compatibility_flags: ["FLAG1", "FLAG2"],
467
+ workers_dev: false,
468
+ routes: ["ROUTE_1", "ROUTE_2"],
469
+ route: "ROUTE_3",
470
+ jsx_factory: "JSX_FACTORY",
471
+ jsx_fragment: "JSX_FRAGMENT",
472
+ triggers: { crons: ["CRON_1", "CRON_2"] },
473
+ usage_model: "bundled",
474
+ vars: {
475
+ VAR1: "VALUE_1",
476
+ VAR2: "VALUE_2",
477
+ },
478
+ durable_objects: {
479
+ bindings: [
480
+ { name: "DO_BINDING_1", class_name: "CLASS1" },
481
+ {
482
+ name: "DO_BINDING_2",
483
+ class_name: "CLASS2",
484
+ script_name: "SCRIPT2",
485
+ },
486
+ ],
487
+ },
488
+ kv_namespaces: [
489
+ { binding: "KV_BINDING_1", id: "KV_ID_1" },
490
+ {
491
+ binding: "KV_BINDING_2",
492
+ id: "KV_ID_2",
493
+ preview_id: "KV_PREVIEW_1",
494
+ },
495
+ ],
496
+ r2_buckets: [
497
+ { binding: "R2_BINDING_1", bucket_name: "R2_BUCKET_1" },
498
+ {
499
+ binding: "R2_BINDING_2",
500
+ bucket_name: "R2_BUCKET_2",
501
+ preview_bucket_name: "R2_PREVIEW_2",
502
+ },
503
+ ],
504
+ unsafe: {
505
+ bindings: [
506
+ { name: "UNSAFE_BINDING_1", type: "UNSAFE_TYPE_1" },
507
+ {
508
+ name: "UNSAFE_BINDING_2",
509
+ type: "UNSAFE_TYPE_2",
510
+ extra: "UNSAFE_EXTRA_1",
511
+ },
512
+ ],
513
+ },
514
+ };
515
+
516
+ const { config, diagnostics } = normalizeAndValidateConfig(
517
+ expectedConfig,
518
+ undefined
519
+ );
520
+
521
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
522
+ expect(diagnostics.hasErrors()).toBe(false);
523
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
524
+ "Processing wrangler configuration:
525
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
526
+ `);
527
+ });
528
+
529
+ it("should error on invalid environment values", () => {
530
+ const expectedConfig: RawConfig = {
531
+ name: 111,
532
+ account_id: 222,
533
+ compatibility_date: 333,
534
+ compatibility_flags: [444, 555],
535
+ workers_dev: "BAD",
536
+ routes: [666, 777],
537
+ route: 888,
538
+ jsx_factory: 999,
539
+ jsx_fragment: 1000,
540
+ triggers: { crons: [1111, 1222] },
541
+ usage_model: "INVALID",
542
+ } as unknown as RawConfig;
543
+
544
+ const { config, diagnostics } = normalizeAndValidateConfig(
545
+ expectedConfig,
546
+ undefined
547
+ );
548
+
549
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
550
+ expect(diagnostics.hasWarnings()).toBe(false);
551
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
552
+ "Processing wrangler configuration:
553
+ - Expected \\"route\\" field to be a string but got 888.
554
+ - Expected \\"routes\\" field to be an array of strings but got [666,777].
555
+ - Expected \\"workers_dev\\" field to be a boolean but got \\"BAD\\".
556
+ - Expected \\"account_id\\" field to be a string but got 222.
557
+ - Expected \\"compatibility_date\\" field to be a string but got 333.
558
+ - Expected \\"compatibility_flags\\" field to be an array of strings but got [444,555].
559
+ - Expected \\"jsx_factory\\" field to be a string but got 999.
560
+ - Expected \\"jsx_fragment\\" field to be a string but got 1000.
561
+ - Expected \\"name\\" field to be a string but got 111.
562
+ - Expected \\"usage_model\\" field to be on of bundled,unbound but got \\"INVALID\\"."
563
+ `);
564
+ });
565
+
566
+ describe("durable_objects field", () => {
567
+ it("should error if durable_objects is an array", () => {
568
+ const { config, diagnostics } = normalizeAndValidateConfig(
569
+ { durable_objects: [] } as unknown as RawConfig,
570
+ undefined
571
+ );
572
+
573
+ expect(config).toEqual(
574
+ expect.not.objectContaining({ durable_objects: expect.anything })
575
+ );
576
+ expect(diagnostics.hasWarnings()).toBe(false);
577
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
578
+ "Processing wrangler configuration:
579
+ - The field \\"durable_objects\\" should be an object but got []."
580
+ `);
581
+ });
582
+
583
+ it("should error if durable_objects is a string", () => {
584
+ const { config, diagnostics } = normalizeAndValidateConfig(
585
+ { durable_objects: "BAD" } as unknown as RawConfig,
586
+ undefined
587
+ );
588
+
589
+ expect(config).toEqual(
590
+ expect.not.objectContaining({ durable_objects: expect.anything })
591
+ );
592
+ expect(diagnostics.hasWarnings()).toBe(false);
593
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
594
+ "Processing wrangler configuration:
595
+ - The field \\"durable_objects\\" should be an object but got \\"BAD\\"."
596
+ `);
597
+ });
598
+
599
+ it("should error if durable_objects is a number", () => {
600
+ const { config, diagnostics } = normalizeAndValidateConfig(
601
+ { durable_objects: 999 } as unknown as RawConfig,
602
+ undefined
603
+ );
604
+
605
+ expect(config).toEqual(
606
+ expect.not.objectContaining({ durable_objects: expect.anything })
607
+ );
608
+ expect(diagnostics.hasWarnings()).toBe(false);
609
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
610
+ "Processing wrangler configuration:
611
+ - The field \\"durable_objects\\" should be an object but got 999."
612
+ `);
613
+ });
614
+
615
+ it("should error if durable_objects is null", () => {
616
+ const { config, diagnostics } = normalizeAndValidateConfig(
617
+ { durable_objects: null } as unknown as RawConfig,
618
+ undefined
619
+ );
620
+
621
+ expect(config).toEqual(
622
+ expect.not.objectContaining({ durable_objects: expect.anything })
623
+ );
624
+ expect(diagnostics.hasWarnings()).toBe(false);
625
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
626
+ "Processing wrangler configuration:
627
+ - The field \\"durable_objects\\" should be an object but got null."
628
+ `);
629
+ });
630
+
631
+ it("should error if durable_objects.bindings is not defined", () => {
632
+ const { config, diagnostics } = normalizeAndValidateConfig(
633
+ { durable_objects: {} } as unknown as RawConfig,
634
+ undefined
635
+ );
636
+
637
+ expect(config).toEqual(
638
+ expect.not.objectContaining({ durable_objects: expect.anything })
639
+ );
640
+ expect(diagnostics.hasWarnings()).toBe(false);
641
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
642
+ "Processing wrangler configuration:
643
+ - The field \\"durable_objects\\" is missing the required \\"bindings\\" property."
644
+ `);
645
+ });
646
+
647
+ it("should error if durable_objects.bindings is an object", () => {
648
+ const { config, diagnostics } = normalizeAndValidateConfig(
649
+ { durable_objects: { bindings: {} } } as unknown as RawConfig,
650
+ undefined
651
+ );
652
+
653
+ expect(config).toEqual(
654
+ expect.not.objectContaining({
655
+ durable_objects: { bindings: expect.anything },
656
+ })
657
+ );
658
+ expect(diagnostics.hasWarnings()).toBe(false);
659
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
660
+ "Processing wrangler configuration:
661
+ - The field \\"durable_objects.bindings\\" should be an array but got {}."
662
+ `);
663
+ });
664
+
665
+ it("should error if durable_objects.bindings is a string", () => {
666
+ const { config, diagnostics } = normalizeAndValidateConfig(
667
+ { durable_objects: { bindings: "BAD" } } as unknown as RawConfig,
668
+ undefined
669
+ );
670
+
671
+ expect(config).toEqual(
672
+ expect.not.objectContaining({
673
+ durable_objects: { bindings: expect.anything },
674
+ })
675
+ );
676
+ expect(diagnostics.hasWarnings()).toBe(false);
677
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
678
+ "Processing wrangler configuration:
679
+ - The field \\"durable_objects.bindings\\" should be an array but got \\"BAD\\"."
680
+ `);
681
+ });
682
+
683
+ it("should error if durable_objects.bindings is a number", () => {
684
+ const { config, diagnostics } = normalizeAndValidateConfig(
685
+ { durable_objects: { bindings: 999 } } as unknown as RawConfig,
686
+ undefined
687
+ );
688
+
689
+ expect(config).toEqual(
690
+ expect.not.objectContaining({
691
+ durable_objects: { bindings: expect.anything },
692
+ })
693
+ );
694
+ expect(diagnostics.hasWarnings()).toBe(false);
695
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
696
+ "Processing wrangler configuration:
697
+ - The field \\"durable_objects.bindings\\" should be an array but got 999."
698
+ `);
699
+ });
700
+
701
+ it("should error if durable_objects.bindings is null", () => {
702
+ const { config, diagnostics } = normalizeAndValidateConfig(
703
+ { durable_objects: { bindings: null } } as unknown as RawConfig,
704
+ undefined
705
+ );
706
+
707
+ expect(config).toEqual(
708
+ expect.not.objectContaining({
709
+ durable_objects: { bindings: expect.anything },
710
+ })
711
+ );
712
+ expect(diagnostics.hasWarnings()).toBe(false);
713
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
714
+ "Processing wrangler configuration:
715
+ - The field \\"durable_objects.bindings\\" should be an array but got null."
716
+ `);
717
+ });
718
+
719
+ it("should error if durable_objects.bindings are not valid", () => {
720
+ const { config, diagnostics } = normalizeAndValidateConfig(
721
+ {
722
+ durable_objects: {
723
+ bindings: [
724
+ {},
725
+ { name: "VALID" },
726
+ { name: 1555, class_name: 1666 },
727
+ {
728
+ name: 1777,
729
+ class_name: 1888,
730
+ script_name: 1999,
731
+ },
732
+ ],
733
+ },
734
+ } as unknown as RawConfig,
735
+ undefined
736
+ );
737
+
738
+ expect(config).toEqual(
739
+ expect.not.objectContaining({
740
+ durable_objects: { bindings: expect.anything },
741
+ })
742
+ );
743
+ expect(diagnostics.hasWarnings()).toBe(false);
744
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
745
+ "Processing wrangler configuration:
746
+
747
+ - \\"durable_objects.bindings[0]\\": {}
748
+ - ERROR: bindings should have a string \\"name\\" field.
749
+ - ERROR: should have a string \\"class_name\\" field.
750
+
751
+ - \\"durable_objects.bindings[1]\\": {\\"name\\":\\"VALID\\"}
752
+ - ERROR: should have a string \\"class_name\\" field.
753
+
754
+ - \\"durable_objects.bindings[2]\\": {\\"name\\":1555,\\"class_name\\":1666}
755
+ - ERROR: bindings should have a string \\"name\\" field.
756
+ - ERROR: should have a string \\"class_name\\" field.
757
+
758
+ - \\"durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
759
+ - ERROR: bindings should have a string \\"name\\" field.
760
+ - ERROR: should have a string \\"class_name\\" field.
761
+ - ERROR: should, optionally, have a string \\"script_name\\" field."
762
+ `);
763
+ });
764
+ });
765
+
766
+ describe("kv_namespaces field", () => {
767
+ it("should error if kv_namespaces is an object", () => {
768
+ const { config, diagnostics } = normalizeAndValidateConfig(
769
+ { kv_namespaces: {} } as unknown as RawConfig,
770
+ undefined
771
+ );
772
+
773
+ expect(config).toEqual(
774
+ expect.not.objectContaining({ kv_namespaces: expect.anything })
775
+ );
776
+ expect(diagnostics.hasWarnings()).toBe(false);
777
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
778
+ "Processing wrangler configuration:
779
+ - The field \\"kv_namespaces\\" should be an array but got {}."
780
+ `);
781
+ });
782
+
783
+ it("should error if kv_namespaces is a string", () => {
784
+ const { config, diagnostics } = normalizeAndValidateConfig(
785
+ { kv_namespaces: "BAD" } as unknown as RawConfig,
786
+ undefined
787
+ );
788
+
789
+ expect(config).toEqual(
790
+ expect.not.objectContaining({ kv_namespaces: expect.anything })
791
+ );
792
+ expect(diagnostics.hasWarnings()).toBe(false);
793
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
794
+ "Processing wrangler configuration:
795
+ - The field \\"kv_namespaces\\" should be an array but got \\"BAD\\"."
796
+ `);
797
+ });
798
+
799
+ it("should error if kv_namespaces is a number", () => {
800
+ const { config, diagnostics } = normalizeAndValidateConfig(
801
+ { kv_namespaces: 999 } as unknown as RawConfig,
802
+ undefined
803
+ );
804
+
805
+ expect(config).toEqual(
806
+ expect.not.objectContaining({ kv_namespaces: expect.anything })
807
+ );
808
+ expect(diagnostics.hasWarnings()).toBe(false);
809
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
810
+ "Processing wrangler configuration:
811
+ - The field \\"kv_namespaces\\" should be an array but got 999."
812
+ `);
813
+ });
814
+
815
+ it("should error if kv_namespaces is null", () => {
816
+ const { config, diagnostics } = normalizeAndValidateConfig(
817
+ { kv_namespaces: null } as unknown as RawConfig,
818
+ undefined
819
+ );
820
+
821
+ expect(config).toEqual(
822
+ expect.not.objectContaining({ kv_namespaces: expect.anything })
823
+ );
824
+ expect(diagnostics.hasWarnings()).toBe(false);
825
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
826
+ "Processing wrangler configuration:
827
+ - The field \\"kv_namespaces\\" should be an array but got null."
828
+ `);
829
+ });
830
+
831
+ it("should error if kv_namespaces.bindings are not valid", () => {
832
+ const { config, diagnostics } = normalizeAndValidateConfig(
833
+ {
834
+ kv_namespaces: [
835
+ {},
836
+ { binding: "VALID" },
837
+ { binding: 2000, id: 2111 },
838
+ {
839
+ binding: "KV_BINDING_2",
840
+ id: "KV_ID_2",
841
+ preview_id: 2222,
842
+ },
843
+ ],
844
+ } as unknown as RawConfig,
845
+ undefined
846
+ );
847
+
848
+ expect(config).toEqual(
849
+ expect.not.objectContaining({
850
+ kv_namespaces: { bindings: expect.anything },
851
+ })
852
+ );
853
+ expect(diagnostics.hasWarnings()).toBe(false);
854
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
855
+ "Processing wrangler configuration:
856
+ - \\"kv_namespaces[0]\\" bindings should have a string \\"binding\\" field but got {}.
857
+ - \\"kv_namespaces[0]\\" bindings should have a string \\"id\\" field but got {}.
858
+ - \\"kv_namespaces[1]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":\\"VALID\\"}.
859
+ - \\"kv_namespaces[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
860
+ - \\"kv_namespaces[2]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
861
+ - \\"kv_namespaces[3]\\" bindings should, optionally, have a string \\"preview_id\\" field but got {\\"binding\\":\\"KV_BINDING_2\\",\\"id\\":\\"KV_ID_2\\",\\"preview_id\\":2222}."
862
+ `);
863
+ });
864
+ });
865
+
866
+ describe("r2_buckets field", () => {
867
+ it("should error if r2_buckets is an object", () => {
868
+ const { config, diagnostics } = normalizeAndValidateConfig(
869
+ { r2_buckets: {} } as unknown as RawConfig,
870
+ undefined
871
+ );
872
+
873
+ expect(config).toEqual(
874
+ expect.not.objectContaining({ r2_buckets: expect.anything })
875
+ );
876
+ expect(diagnostics.hasWarnings()).toBe(false);
877
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
878
+ "Processing wrangler configuration:
879
+ - The field \\"r2_buckets\\" should be an array but got {}."
880
+ `);
881
+ });
882
+
883
+ it("should error if r2_buckets is a string", () => {
884
+ const { config, diagnostics } = normalizeAndValidateConfig(
885
+ { r2_buckets: "BAD" } as unknown as RawConfig,
886
+ undefined
887
+ );
888
+
889
+ expect(config).toEqual(
890
+ expect.not.objectContaining({ r2_buckets: expect.anything })
891
+ );
892
+ expect(diagnostics.hasWarnings()).toBe(false);
893
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
894
+ "Processing wrangler configuration:
895
+ - The field \\"r2_buckets\\" should be an array but got \\"BAD\\"."
896
+ `);
897
+ });
898
+
899
+ it("should error if r2_buckets is a number", () => {
900
+ const { config, diagnostics } = normalizeAndValidateConfig(
901
+ { r2_buckets: 999 } as unknown as RawConfig,
902
+ undefined
903
+ );
904
+
905
+ expect(config).toEqual(
906
+ expect.not.objectContaining({ r2_buckets: expect.anything })
907
+ );
908
+ expect(diagnostics.hasWarnings()).toBe(false);
909
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
910
+ "Processing wrangler configuration:
911
+ - The field \\"r2_buckets\\" should be an array but got 999."
912
+ `);
913
+ });
914
+
915
+ it("should error if r2_buckets is null", () => {
916
+ const { config, diagnostics } = normalizeAndValidateConfig(
917
+ { r2_buckets: null } as unknown as RawConfig,
918
+ undefined
919
+ );
920
+
921
+ expect(config).toEqual(
922
+ expect.not.objectContaining({ r2_buckets: expect.anything })
923
+ );
924
+ expect(diagnostics.hasWarnings()).toBe(false);
925
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
926
+ "Processing wrangler configuration:
927
+ - The field \\"r2_buckets\\" should be an array but got null."
928
+ `);
929
+ });
930
+
931
+ it("should error if r2_buckets.bindings are not valid", () => {
932
+ const { config, diagnostics } = normalizeAndValidateConfig(
933
+ {
934
+ r2_buckets: [
935
+ {},
936
+ { binding: "R2_BINDING_1" },
937
+ { binding: 2333, bucket_name: 2444 },
938
+ {
939
+ binding: "R2_BINDING_2",
940
+ bucket_name: "R2_BUCKET_2",
941
+ preview_bucket_name: 2555,
942
+ },
943
+ ],
944
+ } as unknown as RawConfig,
945
+ undefined
946
+ );
947
+
948
+ expect(config).toEqual(
949
+ expect.not.objectContaining({
950
+ r2_buckets: { bindings: expect.anything },
951
+ })
952
+ );
953
+ expect(diagnostics.hasWarnings()).toBe(false);
954
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
955
+ "Processing wrangler configuration:
956
+ - \\"r2_buckets[0]\\" bindings should have a string \\"binding\\" field but got {}.
957
+ - \\"r2_buckets[0]\\" bindings should have a string \\"bucket_name\\" field but got {}.
958
+ - \\"r2_buckets[1]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_1\\"}.
959
+ - \\"r2_buckets[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
960
+ - \\"r2_buckets[2]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
961
+ - \\"r2_buckets[3]\\" bindings should, optionally, have a string \\"preview_bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_2\\",\\"bucket_name\\":\\"R2_BUCKET_2\\",\\"preview_bucket_name\\":2555}."
962
+ `);
963
+ });
964
+ });
965
+
966
+ describe("unsafe field", () => {
967
+ it("should error if unsafe is an array", () => {
968
+ const { config, diagnostics } = normalizeAndValidateConfig(
969
+ { unsafe: [] } as unknown as RawConfig,
970
+ undefined
971
+ );
972
+
973
+ expect(config).toEqual(
974
+ expect.not.objectContaining({ unsafe: expect.anything })
975
+ );
976
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
977
+ "Processing wrangler configuration:
978
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
979
+ `);
980
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
981
+ "Processing wrangler configuration:
982
+ - The field \\"unsafe\\" should be an object but got []."
983
+ `);
984
+ });
985
+
986
+ it("should error if unsafe is a string", () => {
987
+ const { config, diagnostics } = normalizeAndValidateConfig(
988
+ { unsafe: "BAD" } as unknown as RawConfig,
989
+ undefined
990
+ );
991
+
992
+ expect(config).toEqual(
993
+ expect.not.objectContaining({ unsafe: expect.anything })
994
+ );
995
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
996
+ "Processing wrangler configuration:
997
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
998
+ `);
999
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1000
+ "Processing wrangler configuration:
1001
+ - The field \\"unsafe\\" should be an object but got \\"BAD\\"."
1002
+ `);
1003
+ });
1004
+
1005
+ it("should error if unsafe is a number", () => {
1006
+ const { config, diagnostics } = normalizeAndValidateConfig(
1007
+ { unsafe: 999 } as unknown as RawConfig,
1008
+ undefined
1009
+ );
1010
+
1011
+ expect(config).toEqual(
1012
+ expect.not.objectContaining({ unsafe: expect.anything })
1013
+ );
1014
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1015
+ "Processing wrangler configuration:
1016
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
1017
+ `);
1018
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1019
+ "Processing wrangler configuration:
1020
+ - The field \\"unsafe\\" should be an object but got 999."
1021
+ `);
1022
+ });
1023
+
1024
+ it("should error if unsafe is null", () => {
1025
+ const { config, diagnostics } = normalizeAndValidateConfig(
1026
+ { unsafe: null } as unknown as RawConfig,
1027
+ undefined
1028
+ );
1029
+
1030
+ expect(config).toEqual(
1031
+ expect.not.objectContaining({ unsafe: expect.anything })
1032
+ );
1033
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1034
+ "Processing wrangler configuration:
1035
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
1036
+ `);
1037
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1038
+ "Processing wrangler configuration:
1039
+ - The field \\"unsafe\\" should be an object but got null."
1040
+ `);
1041
+ });
1042
+
1043
+ it("should error if unsafe.bindings is not defined", () => {
1044
+ const { config, diagnostics } = normalizeAndValidateConfig(
1045
+ { unsafe: {} } as unknown as RawConfig,
1046
+ undefined
1047
+ );
1048
+
1049
+ expect(config).toEqual(
1050
+ expect.not.objectContaining({ unsafe: expect.anything })
1051
+ );
1052
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1053
+ "Processing wrangler configuration:
1054
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
1055
+ `);
1056
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1057
+ "Processing wrangler configuration:
1058
+ - The field \\"unsafe\\" is missing the required \\"bindings\\" property."
1059
+ `);
1060
+ });
1061
+
1062
+ it("should error if unsafe.bindings is an object", () => {
1063
+ const { config, diagnostics } = normalizeAndValidateConfig(
1064
+ { unsafe: { bindings: {} } } as unknown as RawConfig,
1065
+ undefined
1066
+ );
1067
+
1068
+ expect(config).toEqual(
1069
+ expect.not.objectContaining({
1070
+ unsafe: { bindings: expect.anything },
1071
+ })
1072
+ );
1073
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1074
+ "Processing wrangler configuration:
1075
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
1076
+ `);
1077
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1078
+ "Processing wrangler configuration:
1079
+ - The field \\"unsafe.bindings\\" should be an array but got {}."
1080
+ `);
1081
+ });
1082
+
1083
+ it("should error if unsafe.bindings is a string", () => {
1084
+ const { config, diagnostics } = normalizeAndValidateConfig(
1085
+ { unsafe: { bindings: "BAD" } } as unknown as RawConfig,
1086
+ undefined
1087
+ );
1088
+
1089
+ expect(config).toEqual(
1090
+ expect.not.objectContaining({
1091
+ unsafe: { bindings: expect.anything },
1092
+ })
1093
+ );
1094
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1095
+ "Processing wrangler configuration:
1096
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
1097
+ `);
1098
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1099
+ "Processing wrangler configuration:
1100
+ - The field \\"unsafe.bindings\\" should be an array but got \\"BAD\\"."
1101
+ `);
1102
+ });
1103
+
1104
+ it("should error if unsafe.bindings is a number", () => {
1105
+ const { config, diagnostics } = normalizeAndValidateConfig(
1106
+ { unsafe: { bindings: 999 } } as unknown as RawConfig,
1107
+ undefined
1108
+ );
1109
+
1110
+ expect(config).toEqual(
1111
+ expect.not.objectContaining({
1112
+ unsafe: { bindings: expect.anything },
1113
+ })
1114
+ );
1115
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1116
+ "Processing wrangler configuration:
1117
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
1118
+ `);
1119
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1120
+ "Processing wrangler configuration:
1121
+ - The field \\"unsafe.bindings\\" should be an array but got 999."
1122
+ `);
1123
+ });
1124
+
1125
+ it("should error if unsafe.bindings is null", () => {
1126
+ const { config, diagnostics } = normalizeAndValidateConfig(
1127
+ { unsafe: { bindings: null } } as unknown as RawConfig,
1128
+ undefined
1129
+ );
1130
+
1131
+ expect(config).toEqual(
1132
+ expect.not.objectContaining({
1133
+ unsafe: { bindings: expect.anything },
1134
+ })
1135
+ );
1136
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1137
+ "Processing wrangler configuration:
1138
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
1139
+ `);
1140
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1141
+ "Processing wrangler configuration:
1142
+ - The field \\"unsafe.bindings\\" should be an array but got null."
1143
+ `);
1144
+ });
1145
+
1146
+ it("should error if durable_objects.bindings are not valid", () => {
1147
+ const { config, diagnostics } = normalizeAndValidateConfig(
1148
+ {
1149
+ unsafe: {
1150
+ bindings: [
1151
+ {},
1152
+ { name: "UNSAFE_BINDING_1" },
1153
+ { name: 2666, type: 2777 },
1154
+ {
1155
+ name: "UNSAFE_BINDING_2",
1156
+ type: "UNSAFE_TYPE_2",
1157
+ extra: 2888,
1158
+ },
1159
+ ],
1160
+ },
1161
+ } as unknown as RawConfig,
1162
+ undefined
1163
+ );
1164
+
1165
+ expect(config).toEqual(
1166
+ expect.not.objectContaining({
1167
+ durable_objects: { bindings: expect.anything },
1168
+ })
1169
+ );
1170
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1171
+ "Processing wrangler configuration:
1172
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
1173
+ `);
1174
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1175
+ "Processing wrangler configuration:
1176
+
1177
+ - \\"unsafe.bindings[0]\\": {}
1178
+ - ERROR: should have a string \\"name\\" field.
1179
+ - ERROR: should have a string \\"type\\" field.
1180
+
1181
+ - \\"unsafe.bindings[1]\\": {\\"name\\":\\"UNSAFE_BINDING_1\\"}
1182
+ - ERROR: should have a string \\"type\\" field.
1183
+
1184
+ - \\"unsafe.bindings[2]\\": {\\"name\\":2666,\\"type\\":2777}
1185
+ - ERROR: should have a string \\"name\\" field.
1186
+ - ERROR: should have a string \\"type\\" field."
1187
+ `);
1188
+ });
1189
+ });
1190
+
1191
+ describe("(deprecated)", () => {
1192
+ it("should remove and warn about deprecated properties", () => {
1193
+ const rawConfig: RawConfig = {
1194
+ zone_id: "ZONE_ID",
1195
+ experimental_services: [
1196
+ {
1197
+ name: "NAME",
1198
+ service: "SERVICE",
1199
+ environment: "ENV",
1200
+ },
1201
+ ],
1202
+ };
1203
+
1204
+ const { config, diagnostics } = normalizeAndValidateConfig(
1205
+ rawConfig,
1206
+ undefined
1207
+ );
1208
+
1209
+ expect("experimental_services" in config).toBe(false);
1210
+ // Zone is not removed yet, since `route` commands might use it
1211
+ expect(config.zone_id).toEqual("ZONE_ID");
1212
+ expect(diagnostics.hasErrors()).toBe(false);
1213
+ expect(diagnostics.hasWarnings()).toBe(true);
1214
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1215
+ "Processing wrangler configuration:
1216
+ - DEPRECATION: \\"zone_id\\":
1217
+ This is unnecessary since we can deduce this from routes directly.
1218
+ - DEPRECATION: \\"experimental_services\\":
1219
+ The \\"experimental_services\\" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
1220
+ \`\`\`
1221
+ [[unsafe.bindings]]
1222
+ name = \\"NAME\\"
1223
+ type = \\"service\\"
1224
+ service = \\"SERVICE\\"
1225
+ environment = \\"ENV\\"
1226
+ \`\`\`"
1227
+ `);
1228
+ });
1229
+ });
1230
+ });
1231
+
1232
+ describe("named environments", () => {
1233
+ it("should use top-level values for inheritable config fields", () => {
1234
+ const expectedConfig: RawConfig = {
1235
+ name: "NAME",
1236
+ account_id: "ACCOUNT_ID",
1237
+ compatibility_date: "2022-01-01",
1238
+ compatibility_flags: ["FLAG1", "FLAG2"],
1239
+ workers_dev: false,
1240
+ routes: ["ROUTE_1", "ROUTE_2"],
1241
+ route: "ROUTE_3",
1242
+ jsx_factory: "JSX_FACTORY",
1243
+ jsx_fragment: "JSX_FRAGMENT",
1244
+ triggers: { crons: ["CRON_1", "CRON_2"] },
1245
+ usage_model: "bundled",
1246
+ };
1247
+
1248
+ const { config, diagnostics } = normalizeAndValidateConfig(
1249
+ { ...expectedConfig, env: { DEV: {} } },
1250
+ undefined
1251
+ );
1252
+
1253
+ expect(config.env.DEV).toEqual(expect.objectContaining(expectedConfig));
1254
+ expect(diagnostics.hasErrors()).toBe(false);
1255
+ expect(diagnostics.hasWarnings()).toBe(false);
1256
+ });
1257
+
1258
+ it("should override top-level values for inheritable config fields", () => {
1259
+ const environment: RawEnvironment = {
1260
+ name: "ENV_NAME",
1261
+ account_id: "ENV_ACCOUNT_ID",
1262
+ compatibility_date: "2022-02-02",
1263
+ compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
1264
+ workers_dev: true,
1265
+ routes: ["ENV_ROUTE_1", "ENV_ROUTE_2"],
1266
+ route: "ENV_ROUTE_3",
1267
+ jsx_factory: "ENV_JSX_FACTORY",
1268
+ jsx_fragment: "ENV_JSX_FRAGMENT",
1269
+ triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
1270
+ usage_model: "unbound",
1271
+ };
1272
+ const expectedConfig: RawConfig = {
1273
+ name: "NAME",
1274
+ account_id: "ACCOUNT_ID",
1275
+ compatibility_date: "2022-01-01",
1276
+ compatibility_flags: ["FLAG1", "FLAG2"],
1277
+ workers_dev: false,
1278
+ routes: ["ROUTE_1", "ROUTE_2"],
1279
+ route: "ROUTE_3",
1280
+ jsx_factory: "JSX_FACTORY",
1281
+ jsx_fragment: "JSX_FRAGMENT",
1282
+ triggers: { crons: ["CRON_1", "CRON_2"] },
1283
+ usage_model: "bundled",
1284
+ env: {
1285
+ ENV1: environment,
1286
+ },
1287
+ };
1288
+
1289
+ const { config, diagnostics } = normalizeAndValidateConfig(
1290
+ expectedConfig,
1291
+ undefined
1292
+ );
1293
+
1294
+ expect(config.env.ENV1).toEqual(expect.objectContaining(environment));
1295
+ expect(diagnostics.hasErrors()).toBe(false);
1296
+ expect(diagnostics.hasWarnings()).toBe(false);
1297
+ });
1298
+
1299
+ it("should warn for non-inherited fields that are missing in environments", () => {
1300
+ const vars: RawConfig["vars"] = {
1301
+ FOO: "foo",
1302
+ };
1303
+ const durable_objects: RawConfig["durable_objects"] = {
1304
+ bindings: [],
1305
+ };
1306
+ const kv_namespaces: RawConfig["kv_namespaces"] = [];
1307
+ const r2_buckets: RawConfig["r2_buckets"] = [];
1308
+ const unsafe: RawConfig["unsafe"] = { bindings: [] };
1309
+ const rawConfig: RawConfig = {
1310
+ vars,
1311
+ durable_objects,
1312
+ kv_namespaces,
1313
+ r2_buckets,
1314
+ unsafe,
1315
+ env: {
1316
+ ENV1: {},
1317
+ },
1318
+ };
1319
+
1320
+ const { config, diagnostics } = normalizeAndValidateConfig(
1321
+ rawConfig,
1322
+ undefined
1323
+ );
1324
+
1325
+ expect(config.env.ENV1).toEqual(
1326
+ expect.not.objectContaining({
1327
+ vars,
1328
+ durable_objects,
1329
+ kv_namespaces,
1330
+ r2_buckets,
1331
+ unsafe,
1332
+ })
1333
+ );
1334
+ expect(diagnostics.hasErrors()).toBe(false);
1335
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1336
+ "Processing wrangler configuration:
1337
+ - \\"unsafe\\" fields are experimental and may change or break at any time.
1338
+ - \\"env.ENV1\\" environment configuration
1339
+ - \\"vars\\" exists at the top level, but not on \\"env.ENV1\\".
1340
+ This is not what you probably want, since \\"vars\\" is not inherited by environments.
1341
+ Please add \\"vars\\" to \\"env.ENV1\\".
1342
+ - \\"durable_objects\\" exists at the top level, but not on \\"env.ENV1\\".
1343
+ This is not what you probably want, since \\"durable_objects\\" is not inherited by environments.
1344
+ Please add \\"durable_objects\\" to \\"env.ENV1\\".
1345
+ - \\"kv_namespaces\\" exists at the top level, but not on \\"env.ENV1\\".
1346
+ This is not what you probably want, since \\"kv_namespaces\\" is not inherited by environments.
1347
+ Please add \\"kv_namespaces\\" to \\"env.ENV1\\".
1348
+ - \\"r2_buckets\\" exists at the top level, but not on \\"env.ENV1\\".
1349
+ This is not what you probably want, since \\"r2_buckets\\" is not inherited by environments.
1350
+ Please add \\"r2_buckets\\" to \\"env.ENV1\\".
1351
+ - \\"unsafe\\" exists at the top level, but not on \\"env.ENV1\\".
1352
+ This is not what you probably want, since \\"unsafe\\" is not inherited by environments.
1353
+ Please add \\"unsafe\\" to \\"env.ENV1\\"."
1354
+ `);
1355
+ });
1356
+
1357
+ it("should error on invalid environment values", () => {
1358
+ const expectedConfig: RawEnvironment = {
1359
+ name: 111,
1360
+ account_id: 222,
1361
+ compatibility_date: 333,
1362
+ compatibility_flags: [444, 555],
1363
+ workers_dev: "BAD",
1364
+ routes: [666, 777],
1365
+ route: 888,
1366
+ jsx_factory: 999,
1367
+ jsx_fragment: 1000,
1368
+ triggers: { crons: [1111, 1222] },
1369
+ usage_model: "INVALID",
1370
+ } as unknown as RawEnvironment;
1371
+
1372
+ const { config, diagnostics } = normalizeAndValidateConfig(
1373
+ { env: { ENV1: expectedConfig } },
1374
+ undefined
1375
+ );
1376
+
1377
+ expect(config.env.ENV1).toEqual(expect.objectContaining(expectedConfig));
1378
+ expect(diagnostics.hasWarnings()).toBe(false);
1379
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1380
+ "Processing wrangler configuration:
1381
+
1382
+ - \\"env.ENV1\\" environment configuration
1383
+ - Expected \\"route\\" field to be a string but got 888.
1384
+ - Expected \\"routes\\" field to be an array of strings but got [666,777].
1385
+ - Expected \\"workers_dev\\" field to be a boolean but got \\"BAD\\".
1386
+ - Expected \\"account_id\\" field to be a string but got 222.
1387
+ - Expected \\"compatibility_date\\" field to be a string but got 333.
1388
+ - Expected \\"compatibility_flags\\" field to be an array of strings but got [444,555].
1389
+ - Expected \\"jsx_factory\\" field to be a string but got 999.
1390
+ - Expected \\"jsx_fragment\\" field to be a string but got 1000.
1391
+ - Expected \\"name\\" field to be a string but got 111.
1392
+ - Expected \\"usage_model\\" field to be on of bundled,unbound but got \\"INVALID\\"."
1393
+ `);
1394
+ });
1395
+
1396
+ describe("durable_objects field", () => {
1397
+ it("should error if durable_objects is an array", () => {
1398
+ const { config, diagnostics } = normalizeAndValidateConfig(
1399
+ { env: { ENV1: { durable_objects: [] } } } as unknown as RawConfig,
1400
+ undefined
1401
+ );
1402
+
1403
+ expect(config.env.ENV1).toEqual(
1404
+ expect.not.objectContaining({ durable_objects: expect.anything })
1405
+ );
1406
+ expect(diagnostics.hasWarnings()).toBe(false);
1407
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1408
+ "Processing wrangler configuration:
1409
+
1410
+ - \\"env.ENV1\\" environment configuration
1411
+ - The field \\"env.ENV1.durable_objects\\" should be an object but got []."
1412
+ `);
1413
+ });
1414
+
1415
+ it("should error if durable_objects is a string", () => {
1416
+ const { config, diagnostics } = normalizeAndValidateConfig(
1417
+ { env: { ENV1: { durable_objects: "BAD" } } } as unknown as RawConfig,
1418
+ undefined
1419
+ );
1420
+
1421
+ expect(config.env.ENV1).toEqual(
1422
+ expect.not.objectContaining({ durable_objects: expect.anything })
1423
+ );
1424
+ expect(diagnostics.hasWarnings()).toBe(false);
1425
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1426
+ "Processing wrangler configuration:
1427
+
1428
+ - \\"env.ENV1\\" environment configuration
1429
+ - The field \\"env.ENV1.durable_objects\\" should be an object but got \\"BAD\\"."
1430
+ `);
1431
+ });
1432
+
1433
+ it("should error if durable_objects is a number", () => {
1434
+ const { config, diagnostics } = normalizeAndValidateConfig(
1435
+ { env: { ENV1: { durable_objects: 999 } } } as unknown as RawConfig,
1436
+ undefined
1437
+ );
1438
+
1439
+ expect(config.env.ENV1).toEqual(
1440
+ expect.not.objectContaining({ durable_objects: expect.anything })
1441
+ );
1442
+ expect(diagnostics.hasWarnings()).toBe(false);
1443
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1444
+ "Processing wrangler configuration:
1445
+
1446
+ - \\"env.ENV1\\" environment configuration
1447
+ - The field \\"env.ENV1.durable_objects\\" should be an object but got 999."
1448
+ `);
1449
+ });
1450
+
1451
+ it("should error if durable_objects is null", () => {
1452
+ const { config, diagnostics } = normalizeAndValidateConfig(
1453
+ { env: { ENV1: { durable_objects: null } } } as unknown as RawConfig,
1454
+ undefined
1455
+ );
1456
+
1457
+ expect(config.env.ENV1).toEqual(
1458
+ expect.not.objectContaining({ durable_objects: expect.anything })
1459
+ );
1460
+ expect(diagnostics.hasWarnings()).toBe(false);
1461
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1462
+ "Processing wrangler configuration:
1463
+
1464
+ - \\"env.ENV1\\" environment configuration
1465
+ - The field \\"env.ENV1.durable_objects\\" should be an object but got null."
1466
+ `);
1467
+ });
1468
+
1469
+ it("should error if durable_objects.bindings is not defined", () => {
1470
+ const { config, diagnostics } = normalizeAndValidateConfig(
1471
+ { env: { ENV1: { durable_objects: {} } } } as unknown as RawConfig,
1472
+ undefined
1473
+ );
1474
+
1475
+ expect(config.env.ENV1).toEqual(
1476
+ expect.not.objectContaining({ durable_objects: expect.anything })
1477
+ );
1478
+ expect(diagnostics.hasWarnings()).toBe(false);
1479
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1480
+ "Processing wrangler configuration:
1481
+
1482
+ - \\"env.ENV1\\" environment configuration
1483
+ - The field \\"env.ENV1.durable_objects\\" is missing the required \\"bindings\\" property."
1484
+ `);
1485
+ });
1486
+
1487
+ it("should error if durable_objects.bindings is an object", () => {
1488
+ const { config, diagnostics } = normalizeAndValidateConfig(
1489
+ {
1490
+ env: { ENV1: { durable_objects: { bindings: {} } } },
1491
+ } as unknown as RawConfig,
1492
+ undefined
1493
+ );
1494
+
1495
+ expect(config.env.ENV1).toEqual(
1496
+ expect.not.objectContaining({
1497
+ durable_objects: { bindings: expect.anything },
1498
+ })
1499
+ );
1500
+ expect(diagnostics.hasWarnings()).toBe(false);
1501
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1502
+ "Processing wrangler configuration:
1503
+
1504
+ - \\"env.ENV1\\" environment configuration
1505
+ - The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got {}."
1506
+ `);
1507
+ });
1508
+
1509
+ it("should error if durable_objects.bindings is a string", () => {
1510
+ const { config, diagnostics } = normalizeAndValidateConfig(
1511
+ {
1512
+ env: { ENV1: { durable_objects: { bindings: "BAD" } } },
1513
+ } as unknown as RawConfig,
1514
+ undefined
1515
+ );
1516
+
1517
+ expect(config.env.ENV1).toEqual(
1518
+ expect.not.objectContaining({
1519
+ durable_objects: { bindings: expect.anything },
1520
+ })
1521
+ );
1522
+ expect(diagnostics.hasWarnings()).toBe(false);
1523
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1524
+ "Processing wrangler configuration:
1525
+
1526
+ - \\"env.ENV1\\" environment configuration
1527
+ - The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got \\"BAD\\"."
1528
+ `);
1529
+ });
1530
+
1531
+ it("should error if durable_objects.bindings is a number", () => {
1532
+ const { config, diagnostics } = normalizeAndValidateConfig(
1533
+ {
1534
+ env: { ENV1: { durable_objects: { bindings: 999 } } },
1535
+ } as unknown as RawConfig,
1536
+ undefined
1537
+ );
1538
+
1539
+ expect(config.env.ENV1).toEqual(
1540
+ expect.not.objectContaining({
1541
+ durable_objects: { bindings: expect.anything },
1542
+ })
1543
+ );
1544
+ expect(diagnostics.hasWarnings()).toBe(false);
1545
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1546
+ "Processing wrangler configuration:
1547
+
1548
+ - \\"env.ENV1\\" environment configuration
1549
+ - The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got 999."
1550
+ `);
1551
+ });
1552
+
1553
+ it("should error if durable_objects.bindings is null", () => {
1554
+ const { config, diagnostics } = normalizeAndValidateConfig(
1555
+ {
1556
+ env: { ENV1: { durable_objects: { bindings: null } } },
1557
+ } as unknown as RawConfig,
1558
+ undefined
1559
+ );
1560
+
1561
+ expect(config.env.ENV1).toEqual(
1562
+ expect.not.objectContaining({
1563
+ durable_objects: { bindings: expect.anything },
1564
+ })
1565
+ );
1566
+ expect(diagnostics.hasWarnings()).toBe(false);
1567
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1568
+ "Processing wrangler configuration:
1569
+
1570
+ - \\"env.ENV1\\" environment configuration
1571
+ - The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got null."
1572
+ `);
1573
+ });
1574
+
1575
+ it("should error if durable_objects.bindings are not valid", () => {
1576
+ const { config, diagnostics } = normalizeAndValidateConfig(
1577
+ {
1578
+ env: {
1579
+ ENV1: {
1580
+ durable_objects: {
1581
+ bindings: [
1582
+ {},
1583
+ { name: "VALID" },
1584
+ { name: 1555, class_name: 1666 },
1585
+ {
1586
+ name: 1777,
1587
+ class_name: 1888,
1588
+ script_name: 1999,
1589
+ },
1590
+ ],
1591
+ },
1592
+ },
1593
+ },
1594
+ } as unknown as RawConfig,
1595
+ undefined
1596
+ );
1597
+
1598
+ expect(config.env.ENV1).toEqual(
1599
+ expect.not.objectContaining({
1600
+ durable_objects: { bindings: expect.anything },
1601
+ })
1602
+ );
1603
+ expect(diagnostics.hasWarnings()).toBe(false);
1604
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1605
+ "Processing wrangler configuration:
1606
+
1607
+ - \\"env.ENV1\\" environment configuration
1608
+
1609
+ - \\"env.ENV1.durable_objects.bindings[0]\\": {}
1610
+ - ERROR: bindings should have a string \\"name\\" field.
1611
+ - ERROR: should have a string \\"class_name\\" field.
1612
+
1613
+ - \\"env.ENV1.durable_objects.bindings[1]\\": {\\"name\\":\\"VALID\\"}
1614
+ - ERROR: should have a string \\"class_name\\" field.
1615
+
1616
+ - \\"env.ENV1.durable_objects.bindings[2]\\": {\\"name\\":1555,\\"class_name\\":1666}
1617
+ - ERROR: bindings should have a string \\"name\\" field.
1618
+ - ERROR: should have a string \\"class_name\\" field.
1619
+
1620
+ - \\"env.ENV1.durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
1621
+ - ERROR: bindings should have a string \\"name\\" field.
1622
+ - ERROR: should have a string \\"class_name\\" field.
1623
+ - ERROR: should, optionally, have a string \\"script_name\\" field."
1624
+ `);
1625
+ });
1626
+ });
1627
+
1628
+ describe("kv_namespaces field", () => {
1629
+ it("should error if kv_namespaces is an object", () => {
1630
+ const { config, diagnostics } = normalizeAndValidateConfig(
1631
+ { env: { ENV1: { kv_namespaces: {} } } } as unknown as RawConfig,
1632
+ undefined
1633
+ );
1634
+
1635
+ expect(config.env.ENV1).toEqual(
1636
+ expect.not.objectContaining({ kv_namespaces: expect.anything })
1637
+ );
1638
+ expect(diagnostics.hasWarnings()).toBe(false);
1639
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1640
+ "Processing wrangler configuration:
1641
+
1642
+ - \\"env.ENV1\\" environment configuration
1643
+ - The field \\"env.ENV1.kv_namespaces\\" should be an array but got {}."
1644
+ `);
1645
+ });
1646
+
1647
+ it("should error if kv_namespaces is a string", () => {
1648
+ const { config, diagnostics } = normalizeAndValidateConfig(
1649
+ { env: { ENV1: { kv_namespaces: "BAD" } } } as unknown as RawConfig,
1650
+ undefined
1651
+ );
1652
+
1653
+ expect(config.env.ENV1).toEqual(
1654
+ expect.not.objectContaining({ kv_namespaces: expect.anything })
1655
+ );
1656
+ expect(diagnostics.hasWarnings()).toBe(false);
1657
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1658
+ "Processing wrangler configuration:
1659
+
1660
+ - \\"env.ENV1\\" environment configuration
1661
+ - The field \\"env.ENV1.kv_namespaces\\" should be an array but got \\"BAD\\"."
1662
+ `);
1663
+ });
1664
+
1665
+ it("should error if kv_namespaces is a number", () => {
1666
+ const { config, diagnostics } = normalizeAndValidateConfig(
1667
+ { env: { ENV1: { kv_namespaces: 999 } } } as unknown as RawConfig,
1668
+ undefined
1669
+ );
1670
+
1671
+ expect(config.env.ENV1).toEqual(
1672
+ expect.not.objectContaining({ kv_namespaces: expect.anything })
1673
+ );
1674
+ expect(diagnostics.hasWarnings()).toBe(false);
1675
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1676
+ "Processing wrangler configuration:
1677
+
1678
+ - \\"env.ENV1\\" environment configuration
1679
+ - The field \\"env.ENV1.kv_namespaces\\" should be an array but got 999."
1680
+ `);
1681
+ });
1682
+
1683
+ it("should error if kv_namespaces is null", () => {
1684
+ const { config, diagnostics } = normalizeAndValidateConfig(
1685
+ { env: { ENV1: { kv_namespaces: null } } } as unknown as RawConfig,
1686
+ undefined
1687
+ );
1688
+
1689
+ expect(config.env.ENV1).toEqual(
1690
+ expect.not.objectContaining({ kv_namespaces: expect.anything })
1691
+ );
1692
+ expect(diagnostics.hasWarnings()).toBe(false);
1693
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1694
+ "Processing wrangler configuration:
1695
+
1696
+ - \\"env.ENV1\\" environment configuration
1697
+ - The field \\"env.ENV1.kv_namespaces\\" should be an array but got null."
1698
+ `);
1699
+ });
1700
+
1701
+ it("should error if kv_namespaces.bindings are not valid", () => {
1702
+ const { config, diagnostics } = normalizeAndValidateConfig(
1703
+ {
1704
+ env: {
1705
+ ENV1: {
1706
+ kv_namespaces: [
1707
+ {},
1708
+ { binding: "VALID" },
1709
+ { binding: 2000, id: 2111 },
1710
+ {
1711
+ binding: "KV_BINDING_2",
1712
+ id: "KV_ID_2",
1713
+ preview_id: 2222,
1714
+ },
1715
+ ],
1716
+ },
1717
+ },
1718
+ } as unknown as RawConfig,
1719
+ undefined
1720
+ );
1721
+
1722
+ expect(config.env.ENV1).toEqual(
1723
+ expect.not.objectContaining({
1724
+ kv_namespaces: { bindings: expect.anything },
1725
+ })
1726
+ );
1727
+ expect(diagnostics.hasWarnings()).toBe(false);
1728
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1729
+ "Processing wrangler configuration:
1730
+
1731
+ - \\"env.ENV1\\" environment configuration
1732
+ - \\"env.ENV1.kv_namespaces[0]\\" bindings should have a string \\"binding\\" field but got {}.
1733
+ - \\"env.ENV1.kv_namespaces[0]\\" bindings should have a string \\"id\\" field but got {}.
1734
+ - \\"env.ENV1.kv_namespaces[1]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":\\"VALID\\"}.
1735
+ - \\"env.ENV1.kv_namespaces[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
1736
+ - \\"env.ENV1.kv_namespaces[2]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
1737
+ - \\"env.ENV1.kv_namespaces[3]\\" bindings should, optionally, have a string \\"preview_id\\" field but got {\\"binding\\":\\"KV_BINDING_2\\",\\"id\\":\\"KV_ID_2\\",\\"preview_id\\":2222}."
1738
+ `);
1739
+ });
1740
+ });
1741
+
1742
+ describe("r2_buckets field", () => {
1743
+ it("should error if r2_buckets is an object", () => {
1744
+ const { config, diagnostics } = normalizeAndValidateConfig(
1745
+ { env: { ENV1: { r2_buckets: {} } } } as unknown as RawConfig,
1746
+ undefined
1747
+ );
1748
+
1749
+ expect(config.env.ENV1).toEqual(
1750
+ expect.not.objectContaining({ r2_buckets: expect.anything })
1751
+ );
1752
+ expect(diagnostics.hasWarnings()).toBe(false);
1753
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1754
+ "Processing wrangler configuration:
1755
+
1756
+ - \\"env.ENV1\\" environment configuration
1757
+ - The field \\"env.ENV1.r2_buckets\\" should be an array but got {}."
1758
+ `);
1759
+ });
1760
+
1761
+ it("should error if r2_buckets is a string", () => {
1762
+ const { config, diagnostics } = normalizeAndValidateConfig(
1763
+ { env: { ENV1: { r2_buckets: "BAD" } } } as unknown as RawConfig,
1764
+ undefined
1765
+ );
1766
+
1767
+ expect(config.env.ENV1).toEqual(
1768
+ expect.not.objectContaining({ r2_buckets: expect.anything })
1769
+ );
1770
+ expect(diagnostics.hasWarnings()).toBe(false);
1771
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1772
+ "Processing wrangler configuration:
1773
+
1774
+ - \\"env.ENV1\\" environment configuration
1775
+ - The field \\"env.ENV1.r2_buckets\\" should be an array but got \\"BAD\\"."
1776
+ `);
1777
+ });
1778
+
1779
+ it("should error if r2_buckets is a number", () => {
1780
+ const { config, diagnostics } = normalizeAndValidateConfig(
1781
+ { env: { ENV1: { r2_buckets: 999 } } } as unknown as RawConfig,
1782
+ undefined
1783
+ );
1784
+
1785
+ expect(config.env.ENV1).toEqual(
1786
+ expect.not.objectContaining({ r2_buckets: expect.anything })
1787
+ );
1788
+ expect(diagnostics.hasWarnings()).toBe(false);
1789
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1790
+ "Processing wrangler configuration:
1791
+
1792
+ - \\"env.ENV1\\" environment configuration
1793
+ - The field \\"env.ENV1.r2_buckets\\" should be an array but got 999."
1794
+ `);
1795
+ });
1796
+
1797
+ it("should error if r2_buckets is null", () => {
1798
+ const { config, diagnostics } = normalizeAndValidateConfig(
1799
+ { env: { ENV1: { r2_buckets: null } } } as unknown as RawConfig,
1800
+ undefined
1801
+ );
1802
+
1803
+ expect(config.env.ENV1).toEqual(
1804
+ expect.not.objectContaining({ r2_buckets: expect.anything })
1805
+ );
1806
+ expect(diagnostics.hasWarnings()).toBe(false);
1807
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1808
+ "Processing wrangler configuration:
1809
+
1810
+ - \\"env.ENV1\\" environment configuration
1811
+ - The field \\"env.ENV1.r2_buckets\\" should be an array but got null."
1812
+ `);
1813
+ });
1814
+
1815
+ it("should error if r2_buckets.bindings are not valid", () => {
1816
+ const { config, diagnostics } = normalizeAndValidateConfig(
1817
+ {
1818
+ env: {
1819
+ ENV1: {
1820
+ r2_buckets: [
1821
+ {},
1822
+ { binding: "R2_BINDING_1" },
1823
+ { binding: 2333, bucket_name: 2444 },
1824
+ {
1825
+ binding: "R2_BINDING_2",
1826
+ bucket_name: "R2_BUCKET_2",
1827
+ preview_bucket_name: 2555,
1828
+ },
1829
+ ],
1830
+ },
1831
+ },
1832
+ } as unknown as RawConfig,
1833
+ undefined
1834
+ );
1835
+
1836
+ expect(config.env.ENV1).toEqual(
1837
+ expect.not.objectContaining({
1838
+ r2_buckets: { bindings: expect.anything },
1839
+ })
1840
+ );
1841
+ expect(diagnostics.hasWarnings()).toBe(false);
1842
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1843
+ "Processing wrangler configuration:
1844
+
1845
+ - \\"env.ENV1\\" environment configuration
1846
+ - \\"env.ENV1.r2_buckets[0]\\" bindings should have a string \\"binding\\" field but got {}.
1847
+ - \\"env.ENV1.r2_buckets[0]\\" bindings should have a string \\"bucket_name\\" field but got {}.
1848
+ - \\"env.ENV1.r2_buckets[1]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_1\\"}.
1849
+ - \\"env.ENV1.r2_buckets[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
1850
+ - \\"env.ENV1.r2_buckets[2]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
1851
+ - \\"env.ENV1.r2_buckets[3]\\" bindings should, optionally, have a string \\"preview_bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_2\\",\\"bucket_name\\":\\"R2_BUCKET_2\\",\\"preview_bucket_name\\":2555}."
1852
+ `);
1853
+ });
1854
+ });
1855
+
1856
+ describe("unsafe field", () => {
1857
+ it("should error if unsafe is an array", () => {
1858
+ const { config, diagnostics } = normalizeAndValidateConfig(
1859
+ { env: { ENV1: { unsafe: [] } } } as unknown as RawConfig,
1860
+ undefined
1861
+ );
1862
+
1863
+ expect(config.env.ENV1).toEqual(
1864
+ expect.not.objectContaining({ unsafe: expect.anything })
1865
+ );
1866
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1867
+ "Processing wrangler configuration:
1868
+
1869
+ - \\"env.ENV1\\" environment configuration
1870
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
1871
+ `);
1872
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1873
+ "Processing wrangler configuration:
1874
+
1875
+ - \\"env.ENV1\\" environment configuration
1876
+ - The field \\"env.ENV1.unsafe\\" should be an object but got []."
1877
+ `);
1878
+ });
1879
+
1880
+ it("should error if unsafe is a string", () => {
1881
+ const { config, diagnostics } = normalizeAndValidateConfig(
1882
+ { env: { ENV1: { unsafe: "BAD" } } } as unknown as RawConfig,
1883
+ undefined
1884
+ );
1885
+
1886
+ expect(config.env.ENV1).toEqual(
1887
+ expect.not.objectContaining({ unsafe: expect.anything })
1888
+ );
1889
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1890
+ "Processing wrangler configuration:
1891
+
1892
+ - \\"env.ENV1\\" environment configuration
1893
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
1894
+ `);
1895
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1896
+ "Processing wrangler configuration:
1897
+
1898
+ - \\"env.ENV1\\" environment configuration
1899
+ - The field \\"env.ENV1.unsafe\\" should be an object but got \\"BAD\\"."
1900
+ `);
1901
+ });
1902
+
1903
+ it("should error if unsafe is a number", () => {
1904
+ const { config, diagnostics } = normalizeAndValidateConfig(
1905
+ { env: { ENV1: { unsafe: 999 } } } as unknown as RawConfig,
1906
+ undefined
1907
+ );
1908
+
1909
+ expect(config.env.ENV1).toEqual(
1910
+ expect.not.objectContaining({ unsafe: expect.anything })
1911
+ );
1912
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1913
+ "Processing wrangler configuration:
1914
+
1915
+ - \\"env.ENV1\\" environment configuration
1916
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
1917
+ `);
1918
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1919
+ "Processing wrangler configuration:
1920
+
1921
+ - \\"env.ENV1\\" environment configuration
1922
+ - The field \\"env.ENV1.unsafe\\" should be an object but got 999."
1923
+ `);
1924
+ });
1925
+
1926
+ it("should error if unsafe is null", () => {
1927
+ const { config, diagnostics } = normalizeAndValidateConfig(
1928
+ { env: { ENV1: { unsafe: null } } } as unknown as RawConfig,
1929
+ undefined
1930
+ );
1931
+
1932
+ expect(config.env.ENV1).toEqual(
1933
+ expect.not.objectContaining({ unsafe: expect.anything })
1934
+ );
1935
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1936
+ "Processing wrangler configuration:
1937
+
1938
+ - \\"env.ENV1\\" environment configuration
1939
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
1940
+ `);
1941
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1942
+ "Processing wrangler configuration:
1943
+
1944
+ - \\"env.ENV1\\" environment configuration
1945
+ - The field \\"env.ENV1.unsafe\\" should be an object but got null."
1946
+ `);
1947
+ });
1948
+
1949
+ it("should error if unsafe.bindings is not defined", () => {
1950
+ const { config, diagnostics } = normalizeAndValidateConfig(
1951
+ { env: { ENV1: { unsafe: {} } } } as unknown as RawConfig,
1952
+ undefined
1953
+ );
1954
+
1955
+ expect(config.env.ENV1).toEqual(
1956
+ expect.not.objectContaining({ unsafe: expect.anything })
1957
+ );
1958
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1959
+ "Processing wrangler configuration:
1960
+
1961
+ - \\"env.ENV1\\" environment configuration
1962
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
1963
+ `);
1964
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1965
+ "Processing wrangler configuration:
1966
+
1967
+ - \\"env.ENV1\\" environment configuration
1968
+ - The field \\"env.ENV1.unsafe\\" is missing the required \\"bindings\\" property."
1969
+ `);
1970
+ });
1971
+
1972
+ it("should error if unsafe.bindings is an object", () => {
1973
+ const { config, diagnostics } = normalizeAndValidateConfig(
1974
+ {
1975
+ env: { ENV1: { unsafe: { bindings: {} } } },
1976
+ } as unknown as RawConfig,
1977
+ undefined
1978
+ );
1979
+
1980
+ expect(config.env.ENV1).toEqual(
1981
+ expect.not.objectContaining({
1982
+ unsafe: { bindings: expect.anything },
1983
+ })
1984
+ );
1985
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1986
+ "Processing wrangler configuration:
1987
+
1988
+ - \\"env.ENV1\\" environment configuration
1989
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
1990
+ `);
1991
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1992
+ "Processing wrangler configuration:
1993
+
1994
+ - \\"env.ENV1\\" environment configuration
1995
+ - The field \\"env.ENV1.unsafe.bindings\\" should be an array but got {}."
1996
+ `);
1997
+ });
1998
+
1999
+ it("should error if unsafe.bindings is a string", () => {
2000
+ const { config, diagnostics } = normalizeAndValidateConfig(
2001
+ {
2002
+ env: { ENV1: { unsafe: { bindings: "BAD" } } },
2003
+ } as unknown as RawConfig,
2004
+ undefined
2005
+ );
2006
+
2007
+ expect(config.env.ENV1).toEqual(
2008
+ expect.not.objectContaining({
2009
+ unsafe: { bindings: expect.anything },
2010
+ })
2011
+ );
2012
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2013
+ "Processing wrangler configuration:
2014
+
2015
+ - \\"env.ENV1\\" environment configuration
2016
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
2017
+ `);
2018
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2019
+ "Processing wrangler configuration:
2020
+
2021
+ - \\"env.ENV1\\" environment configuration
2022
+ - The field \\"env.ENV1.unsafe.bindings\\" should be an array but got \\"BAD\\"."
2023
+ `);
2024
+ });
2025
+
2026
+ it("should error if unsafe.bindings is a number", () => {
2027
+ const { config, diagnostics } = normalizeAndValidateConfig(
2028
+ {
2029
+ env: { ENV1: { unsafe: { bindings: 999 } } },
2030
+ } as unknown as RawConfig,
2031
+ undefined
2032
+ );
2033
+
2034
+ expect(config.env.ENV1).toEqual(
2035
+ expect.not.objectContaining({
2036
+ unsafe: { bindings: expect.anything },
2037
+ })
2038
+ );
2039
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2040
+ "Processing wrangler configuration:
2041
+
2042
+ - \\"env.ENV1\\" environment configuration
2043
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
2044
+ `);
2045
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2046
+ "Processing wrangler configuration:
2047
+
2048
+ - \\"env.ENV1\\" environment configuration
2049
+ - The field \\"env.ENV1.unsafe.bindings\\" should be an array but got 999."
2050
+ `);
2051
+ });
2052
+
2053
+ it("should error if unsafe.bindings is null", () => {
2054
+ const { config, diagnostics } = normalizeAndValidateConfig(
2055
+ {
2056
+ env: { ENV1: { unsafe: { bindings: null } } },
2057
+ } as unknown as RawConfig,
2058
+ undefined
2059
+ );
2060
+
2061
+ expect(config.env.ENV1).toEqual(
2062
+ expect.not.objectContaining({
2063
+ unsafe: { bindings: expect.anything },
2064
+ })
2065
+ );
2066
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2067
+ "Processing wrangler configuration:
2068
+
2069
+ - \\"env.ENV1\\" environment configuration
2070
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
2071
+ `);
2072
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2073
+ "Processing wrangler configuration:
2074
+
2075
+ - \\"env.ENV1\\" environment configuration
2076
+ - The field \\"env.ENV1.unsafe.bindings\\" should be an array but got null."
2077
+ `);
2078
+ });
2079
+
2080
+ it("should error if unsafe.bindings are not valid", () => {
2081
+ const { config, diagnostics } = normalizeAndValidateConfig(
2082
+ {
2083
+ env: {
2084
+ ENV1: {
2085
+ unsafe: {
2086
+ bindings: [
2087
+ {},
2088
+ { name: "UNSAFE_BINDING_1" },
2089
+ { name: 2666, type: 2777 },
2090
+ {
2091
+ name: "UNSAFE_BINDING_2",
2092
+ type: "UNSAFE_TYPE_2",
2093
+ extra: 2888,
2094
+ },
2095
+ ],
2096
+ },
2097
+ },
2098
+ },
2099
+ } as unknown as RawConfig,
2100
+ undefined
2101
+ );
2102
+
2103
+ expect(config.env.ENV1).toEqual(
2104
+ expect.not.objectContaining({
2105
+ durable_objects: { bindings: expect.anything },
2106
+ })
2107
+ );
2108
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2109
+ "Processing wrangler configuration:
2110
+
2111
+ - \\"env.ENV1\\" environment configuration
2112
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
2113
+ `);
2114
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2115
+ "Processing wrangler configuration:
2116
+
2117
+ - \\"env.ENV1\\" environment configuration
2118
+
2119
+ - \\"env.ENV1.unsafe.bindings[0]\\": {}
2120
+ - ERROR: should have a string \\"name\\" field.
2121
+ - ERROR: should have a string \\"type\\" field.
2122
+
2123
+ - \\"env.ENV1.unsafe.bindings[1]\\": {\\"name\\":\\"UNSAFE_BINDING_1\\"}
2124
+ - ERROR: should have a string \\"type\\" field.
2125
+
2126
+ - \\"env.ENV1.unsafe.bindings[2]\\": {\\"name\\":2666,\\"type\\":2777}
2127
+ - ERROR: should have a string \\"name\\" field.
2128
+ - ERROR: should have a string \\"type\\" field."
2129
+ `);
2130
+ });
2131
+ });
2132
+
2133
+ describe("(deprecated)", () => {
2134
+ it("should remove and warn about deprecated properties", () => {
2135
+ const environment: RawEnvironment = {
2136
+ zone_id: "ZONE_ID",
2137
+ experimental_services: [
2138
+ {
2139
+ name: "NAME",
2140
+ service: "SERVICE",
2141
+ environment: "ENV",
2142
+ },
2143
+ ],
2144
+ };
2145
+
2146
+ const { config, diagnostics } = normalizeAndValidateConfig(
2147
+ {
2148
+ env: {
2149
+ ENV1: environment,
2150
+ },
2151
+ },
2152
+ undefined
2153
+ );
2154
+
2155
+ expect("experimental_services" in config.env.ENV1).toBe(false);
2156
+ // Zone is not removed yet, since `route` commands might use it
2157
+ expect(config.env.ENV1.zone_id).toEqual("ZONE_ID");
2158
+ expect(diagnostics.hasErrors()).toBe(false);
2159
+ expect(diagnostics.hasWarnings()).toBe(true);
2160
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2161
+ "Processing wrangler configuration:
2162
+
2163
+ - \\"env.ENV1\\" environment configuration
2164
+ - DEPRECATION: \\"zone_id\\":
2165
+ This is unnecessary since we can deduce this from routes directly.
2166
+ - DEPRECATION: \\"experimental_services\\":
2167
+ The \\"experimental_services\\" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
2168
+ \`\`\`
2169
+ [[unsafe.bindings]]
2170
+ name = \\"NAME\\"
2171
+ type = \\"service\\"
2172
+ service = \\"SERVICE\\"
2173
+ environment = \\"ENV\\"
2174
+ \`\`\`"
2175
+ `);
2176
+ });
2177
+ });
2178
+ });
2179
+ });
2180
+
2181
+ function normalizePath(text: string): string {
2182
+ return text
2183
+ .replace("project\\wrangler.toml", "project/wrangler.toml")
2184
+ .replace("src\\index.ts", "src/index.ts");
2185
+ }