wrangler 0.0.0-fe5dcfd → 0.0.0-ff53f4e

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