wrangler 0.0.0-e2f9bb2 → 0.0.0-e322475

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 (103) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +3 -1
  3. package/bin/wrangler.js +36 -4
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +15 -7
  6. package/pages/functions/buildPlugin.ts +13 -0
  7. package/pages/functions/buildWorker.ts +14 -1
  8. package/pages/functions/template-plugin.ts +3 -2
  9. package/src/__tests__/configuration.test.ts +652 -229
  10. package/src/__tests__/dev.test.tsx +372 -79
  11. package/src/__tests__/helpers/mock-cfetch.ts +2 -2
  12. package/src/__tests__/helpers/mock-console.ts +11 -1
  13. package/src/__tests__/helpers/mock-dialogs.ts +75 -11
  14. package/src/__tests__/helpers/mock-process.ts +24 -0
  15. package/src/__tests__/index.test.ts +81 -72
  16. package/src/__tests__/init.test.ts +1360 -410
  17. package/src/__tests__/jest.setup.ts +38 -0
  18. package/src/__tests__/kv.test.ts +218 -152
  19. package/src/__tests__/logger.test.ts +26 -0
  20. package/src/__tests__/package-manager.test.ts +154 -7
  21. package/src/__tests__/pages.test.ts +478 -53
  22. package/src/__tests__/parse.test.ts +8 -0
  23. package/src/__tests__/publish.test.ts +1614 -333
  24. package/src/__tests__/r2.test.ts +55 -36
  25. package/src/__tests__/secret.test.ts +39 -4
  26. package/src/__tests__/user.test.ts +1 -0
  27. package/src/__tests__/whoami.test.tsx +34 -0
  28. package/src/abort.d.ts +3 -0
  29. package/src/bundle-reporter.tsx +29 -0
  30. package/src/bundle.ts +42 -7
  31. package/src/cfetch/index.ts +21 -4
  32. package/src/cfetch/internal.ts +25 -20
  33. package/src/config/config.ts +11 -2
  34. package/src/config/environment.ts +41 -15
  35. package/src/config/index.ts +162 -0
  36. package/src/config/validation-helpers.ts +10 -1
  37. package/src/config/validation.ts +234 -78
  38. package/src/create-worker-preview.ts +32 -22
  39. package/src/create-worker-upload-form.ts +22 -8
  40. package/src/dev/dev.tsx +48 -67
  41. package/src/dev/local.tsx +16 -7
  42. package/src/dev/remote.tsx +57 -21
  43. package/src/dev/use-esbuild.ts +1 -7
  44. package/src/dialogs.tsx +48 -0
  45. package/src/durable.ts +102 -0
  46. package/src/entry.ts +71 -10
  47. package/src/generate-auth-url.ts +33 -0
  48. package/src/generate-random-state.ts +16 -0
  49. package/src/git-client.ts +42 -0
  50. package/src/index.tsx +619 -338
  51. package/src/inspect.ts +39 -0
  52. package/src/kv.ts +116 -27
  53. package/src/logger.ts +8 -1
  54. package/src/open-in-browser.ts +3 -12
  55. package/src/package-manager.ts +50 -3
  56. package/src/pages.tsx +434 -207
  57. package/src/parse.ts +44 -5
  58. package/src/proxy.ts +66 -44
  59. package/src/publish.ts +407 -137
  60. package/src/sites.tsx +103 -28
  61. package/src/user.tsx +35 -26
  62. package/src/whoami.tsx +3 -2
  63. package/src/worker.ts +10 -1
  64. package/src/zones.ts +73 -0
  65. package/templates/new-worker-scheduled.js +17 -0
  66. package/templates/new-worker-scheduled.ts +32 -0
  67. package/templates/new-worker.ts +16 -1
  68. package/templates/no-op-worker.js +10 -0
  69. package/templates/static-asset-facade.js +2 -6
  70. package/wrangler-dist/cli.js +46122 -32396
  71. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  72. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  73. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  74. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  75. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  76. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  77. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  78. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  79. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  80. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  81. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  82. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  83. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  84. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  85. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  86. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  87. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  88. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  89. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  90. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  91. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  92. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  93. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  94. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  95. package/vendor/wrangler-mime/LICENSE +0 -21
  96. package/vendor/wrangler-mime/Mime.js +0 -97
  97. package/vendor/wrangler-mime/README.md +0 -187
  98. package/vendor/wrangler-mime/cli.js +0 -46
  99. package/vendor/wrangler-mime/index.js +0 -4
  100. package/vendor/wrangler-mime/lite.js +0 -4
  101. package/vendor/wrangler-mime/package.json +0 -52
  102. package/vendor/wrangler-mime/types/other.js +0 -1
  103. package/vendor/wrangler-mime/types/standard.js +0 -1
@@ -19,7 +19,7 @@ describe("normalizeAndValidateConfig()", () => {
19
19
  build: {
20
20
  command: undefined,
21
21
  cwd: undefined,
22
- watch_dir: undefined,
22
+ watch_dir: "./src",
23
23
  },
24
24
  compatibility_date: undefined,
25
25
  compatibility_flags: [],
@@ -27,7 +27,7 @@ describe("normalizeAndValidateConfig()", () => {
27
27
  dev: {
28
28
  ip: "localhost",
29
29
  local_protocol: "http",
30
- port: 8787,
30
+ port: undefined, // the default of 8787 is set at runtime
31
31
  upstream_protocol: "https",
32
32
  host: undefined,
33
33
  },
@@ -43,6 +43,7 @@ describe("normalizeAndValidateConfig()", () => {
43
43
  migrations: [],
44
44
  name: undefined,
45
45
  r2_buckets: [],
46
+ services: [],
46
47
  route: undefined,
47
48
  routes: undefined,
48
49
  rules: [],
@@ -60,6 +61,8 @@ describe("normalizeAndValidateConfig()", () => {
60
61
  data_blobs: undefined,
61
62
  workers_dev: undefined,
62
63
  zone_id: undefined,
64
+ minify: undefined,
65
+ node_compat: undefined,
63
66
  });
64
67
  expect(diagnostics.hasErrors()).toBe(false);
65
68
  expect(diagnostics.hasWarnings()).toBe(false);
@@ -162,68 +165,110 @@ describe("normalizeAndValidateConfig()", () => {
162
165
  `);
163
166
  });
164
167
 
165
- it("should override `migrations` config defaults with provided values", () => {
166
- const expectedConfig: RawConfig = {
167
- migrations: [
168
- {
169
- tag: "TAG",
170
- new_classes: ["CLASS_1", "CLASS_2"],
171
- renamed_classes: [
172
- {
173
- from: "FROM_CLASS",
174
- to: "TO_CLASS",
175
- },
176
- ],
177
- deleted_classes: ["CLASS_3", "CLASS_4"],
178
- },
179
- ],
180
- };
168
+ describe("migrations", () => {
169
+ it("should override `migrations` config defaults with provided values", () => {
170
+ const expectedConfig: RawConfig = {
171
+ migrations: [
172
+ {
173
+ tag: "TAG",
174
+ new_classes: ["CLASS_1", "CLASS_2"],
175
+ renamed_classes: [
176
+ {
177
+ from: "FROM_CLASS",
178
+ to: "TO_CLASS",
179
+ },
180
+ ],
181
+ deleted_classes: ["CLASS_3", "CLASS_4"],
182
+ },
183
+ ],
184
+ };
181
185
 
182
- const { config, diagnostics } = normalizeAndValidateConfig(
183
- expectedConfig,
184
- undefined,
185
- { env: undefined }
186
- );
186
+ const { config, diagnostics } = normalizeAndValidateConfig(
187
+ expectedConfig,
188
+ undefined,
189
+ { env: undefined }
190
+ );
187
191
 
188
- expect(config).toEqual(expect.objectContaining(expectedConfig));
189
- expect(diagnostics.hasErrors()).toBe(false);
190
- expect(diagnostics.hasWarnings()).toBe(false);
191
- });
192
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
193
+ expect(diagnostics.hasErrors()).toBe(false);
194
+ expect(diagnostics.hasWarnings()).toBe(false);
195
+ });
192
196
 
193
- it("should error on invalid `migrations` values", () => {
194
- const expectedConfig = {
195
- migrations: [
196
- {
197
- tag: 111,
198
- new_classes: [222, 333],
199
- renamed_classes: [
200
- {
201
- from: 444,
202
- to: 555,
203
- },
204
- ],
205
- deleted_classes: [666, 777],
206
- },
207
- ],
208
- };
197
+ it("should error on invalid `migrations` values", () => {
198
+ const expectedConfig = {
199
+ migrations: [
200
+ {
201
+ tag: 111,
202
+ new_classes: [222, 333],
203
+ renamed_classes: [
204
+ {
205
+ from: 444,
206
+ to: 555,
207
+ },
208
+ ],
209
+ deleted_classes: [666, 777],
210
+ },
211
+ ],
212
+ };
209
213
 
210
- const { config, diagnostics } = normalizeAndValidateConfig(
211
- expectedConfig as unknown as RawConfig,
212
- undefined,
213
- { env: undefined }
214
- );
214
+ const { config, diagnostics } = normalizeAndValidateConfig(
215
+ expectedConfig as unknown as RawConfig,
216
+ undefined,
217
+ { env: undefined }
218
+ );
215
219
 
216
- expect(config).toEqual(expect.objectContaining(expectedConfig));
217
- expect(diagnostics.hasWarnings()).toBe(false);
218
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
219
- "Processing wrangler configuration:
220
- - Expected \\"migrations[0].tag\\" to be of type string but got 111.
221
- - Expected \\"migrations[0].new_classes.[0]\\" to be of type string but got 222.
222
- - Expected \\"migrations[0].new_classes.[1]\\" to be of type string but got 333.
223
- - Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
224
- - Expected \\"migrations[0].deleted_classes.[0]\\" to be of type string but got 666.
225
- - Expected \\"migrations[0].deleted_classes.[1]\\" to be of type string but got 777."
226
- `);
220
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
221
+ expect(diagnostics.hasWarnings()).toBe(false);
222
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
223
+ "Processing wrangler configuration:
224
+ - Expected \\"migrations[0].tag\\" to be of type string but got 111.
225
+ - Expected \\"migrations[0].new_classes.[0]\\" to be of type string but got 222.
226
+ - Expected \\"migrations[0].new_classes.[1]\\" to be of type string but got 333.
227
+ - Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
228
+ - Expected \\"migrations[0].deleted_classes.[0]\\" to be of type string but got 666.
229
+ - Expected \\"migrations[0].deleted_classes.[1]\\" to be of type string but got 777."
230
+ `);
231
+ });
232
+
233
+ it("should warn/error on unexpected fields on `migrations`", async () => {
234
+ const expectedConfig = {
235
+ migrations: [
236
+ {
237
+ tag: "TAG",
238
+ new_classes: ["CLASS_1", "CLASS_2"],
239
+ renamed_classes: [
240
+ {
241
+ from: "FROM_CLASS",
242
+ to: "TO_CLASS",
243
+ },
244
+ {
245
+ a: "something",
246
+ b: "someone",
247
+ },
248
+ ],
249
+ deleted_classes: ["CLASS_3", "CLASS_4"],
250
+ unrecognized_field: "FOO",
251
+ },
252
+ ],
253
+ };
254
+
255
+ const { config, diagnostics } = normalizeAndValidateConfig(
256
+ expectedConfig as unknown as RawConfig,
257
+ undefined,
258
+ { env: undefined }
259
+ );
260
+
261
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
262
+ expect(diagnostics.hasErrors()).toBe(true);
263
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
264
+ "Processing wrangler configuration:
265
+ - Unexpected fields found in migrations field: \\"unrecognized_field\\""
266
+ `);
267
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
268
+ "Processing wrangler configuration:
269
+ - Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":\\"FROM_CLASS\\",\\"to\\":\\"TO_CLASS\\"},{\\"a\\":\\"something\\",\\"b\\":\\"someone\\"}]."
270
+ `);
271
+ });
227
272
  });
228
273
 
229
274
  describe("site", () => {
@@ -367,6 +412,67 @@ describe("normalizeAndValidateConfig()", () => {
367
412
  });
368
413
  });
369
414
 
415
+ describe("assets", () => {
416
+ it("should error if `assets` config is missing `bucket`", () => {
417
+ const expectedConfig: RawConfig = {
418
+ // @ts-expect-error we're intentionally passing an invalid configuration here
419
+ assets: {
420
+ include: ["INCLUDE_1", "INCLUDE_2"],
421
+ exclude: ["EXCLUDE_1", "EXCLUDE_2"],
422
+ },
423
+ };
424
+
425
+ const { config, diagnostics } = normalizeAndValidateConfig(
426
+ expectedConfig,
427
+ undefined,
428
+ { env: undefined }
429
+ );
430
+
431
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
432
+ expect(diagnostics.hasWarnings()).toBe(true);
433
+ expect(diagnostics.hasErrors()).toBe(true);
434
+
435
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
436
+ "Processing wrangler configuration:
437
+ - \\"assets\\" fields are experimental and may change or break at any time."
438
+ `);
439
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
440
+ "Processing wrangler configuration:
441
+ - \\"assets.bucket\\" is a required field."
442
+ `);
443
+ });
444
+
445
+ it("should error on invalid `assets` values", () => {
446
+ const expectedConfig = {
447
+ assets: {
448
+ bucket: "BUCKET",
449
+ include: [222, 333],
450
+ exclude: [444, 555],
451
+ },
452
+ };
453
+
454
+ const { config, diagnostics } = normalizeAndValidateConfig(
455
+ expectedConfig as unknown as RawConfig,
456
+ undefined,
457
+ { env: undefined }
458
+ );
459
+
460
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
461
+ expect(diagnostics.hasWarnings()).toBe(true);
462
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
463
+ "Processing wrangler configuration:
464
+ - \\"assets\\" fields are experimental and may change or break at any time."
465
+ `);
466
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
467
+ "Processing wrangler configuration:
468
+ - Expected \\"assets.include.[0]\\" to be of type string but got 222.
469
+ - Expected \\"assets.include.[1]\\" to be of type string but got 333.
470
+ - Expected \\"assets.exclude.[0]\\" to be of type string but got 444.
471
+ - Expected \\"assets.exclude.[1]\\" to be of type string but got 555."
472
+ `);
473
+ });
474
+ });
475
+
370
476
  it("should map `wasm_module` paths from relative to the config path to relative to the cwd", () => {
371
477
  const expectedConfig: RawConfig = {
372
478
  wasm_modules: {
@@ -393,6 +499,40 @@ describe("normalizeAndValidateConfig()", () => {
393
499
  expect(diagnostics.hasWarnings()).toBe(false);
394
500
  });
395
501
 
502
+ it("should warn on unexpected fields on `triggers`", async () => {
503
+ const expectedConfig: RawConfig = {
504
+ triggers: {
505
+ crons: ["1 * * * *"],
506
+ // @ts-expect-error we're purposely adding a field
507
+ // that doesn't belong here
508
+ someOtherfield: 123,
509
+ },
510
+ };
511
+
512
+ const { config, diagnostics } = normalizeAndValidateConfig(
513
+ expectedConfig,
514
+ "project/wrangler.toml",
515
+ { env: undefined }
516
+ );
517
+
518
+ expect(config).toEqual(
519
+ expect.objectContaining({
520
+ triggers: {
521
+ crons: ["1 * * * *"],
522
+ someOtherfield: 123,
523
+ },
524
+ })
525
+ );
526
+ expect(diagnostics.hasErrors()).toBe(false);
527
+ expect(diagnostics.hasWarnings()).toBe(true);
528
+
529
+ expect(normalizePath(diagnostics.renderWarnings()))
530
+ .toMatchInlineSnapshot(`
531
+ "Processing project/wrangler.toml configuration:
532
+ - Unexpected fields found in triggers field: \\"someOtherfield\\""
533
+ `);
534
+ });
535
+
396
536
  it("should error on invalid `wasm_modules` paths", () => {
397
537
  const expectedConfig = {
398
538
  wasm_modules: {
@@ -620,6 +760,12 @@ describe("normalizeAndValidateConfig()", () => {
620
760
  class_name: "CLASS2",
621
761
  script_name: "SCRIPT2",
622
762
  },
763
+ {
764
+ name: "DO_BINDING_3",
765
+ class_name: "CLASS3",
766
+ script_name: "SCRIPT3",
767
+ environment: "ENV3",
768
+ },
623
769
  ],
624
770
  },
625
771
  kv_namespaces: [
@@ -638,6 +784,13 @@ describe("normalizeAndValidateConfig()", () => {
638
784
  preview_bucket_name: "R2_PREVIEW_2",
639
785
  },
640
786
  ],
787
+ services: [
788
+ {
789
+ binding: "SERVICE_BINDING_1",
790
+ service: "SERVICE_TYPE_1",
791
+ environment: "SERVICE_BINDING_ENVIRONMENT_1",
792
+ },
793
+ ],
641
794
  unsafe: {
642
795
  bindings: [
643
796
  { name: "UNSAFE_BINDING_1", type: "UNSAFE_TYPE_1" },
@@ -648,6 +801,8 @@ describe("normalizeAndValidateConfig()", () => {
648
801
  },
649
802
  ],
650
803
  },
804
+ minify: true,
805
+ node_compat: true,
651
806
  };
652
807
 
653
808
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -661,9 +816,19 @@ describe("normalizeAndValidateConfig()", () => {
661
816
  );
662
817
  expect(diagnostics.hasErrors()).toBe(false);
663
818
  expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
664
- "Processing wrangler configuration:
665
- - \\"unsafe\\" fields are experimental and may change or break at any time."
666
- `);
819
+ "Processing wrangler configuration:
820
+ - \\"unsafe\\" fields are experimental and may change or break at any time.
821
+ - \\"services\\" fields are experimental and may change or break at any time.
822
+ - In wrangler.toml, you have configured [durable_objects] exported by this Worker (CLASS1), but no [migrations] for them. This may not work as expected until you add a [migrations] section to your wrangler.toml. Add this configuration to your wrangler.toml:
823
+
824
+ \`\`\`
825
+ [[migrations]]
826
+ tag = \\"v1\\" # Should be unique for each entry
827
+ new_classes = [\\"CLASS1\\"]
828
+ \`\`\`
829
+
830
+ Refer to https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml for more details."
831
+ `);
667
832
  });
668
833
 
669
834
  it("should error on invalid environment values", () => {
@@ -705,6 +870,8 @@ describe("normalizeAndValidateConfig()", () => {
705
870
  cwd: 1555,
706
871
  watch_dir: 1666,
707
872
  },
873
+ minify: "INVALID",
874
+ node_compat: "INVALID",
708
875
  } as unknown as RawEnvironment;
709
876
 
710
877
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -717,8 +884,8 @@ describe("normalizeAndValidateConfig()", () => {
717
884
  expect(diagnostics.hasWarnings()).toBe(false);
718
885
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
719
886
  "Processing wrangler configuration:
720
- - Expected \\"route\\" to be either a string, or an object with shape { pattern, zone_id | zone_name }, but got 888.
721
- - Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, zone_id | zone_name }, but these weren't valid: [
887
+ - Expected \\"route\\" to be either a string, or an object with shape { pattern, custom_domain, zone_id | zone_name }, but got 888.
888
+ - Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, custom_domain, zone_id | zone_name }, but these weren't valid: [
722
889
  666,
723
890
  777,
724
891
  {
@@ -767,175 +934,256 @@ describe("normalizeAndValidateConfig()", () => {
767
934
  - Expected \\"tsconfig\\" to be of type string but got true.
768
935
  - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got 111.
769
936
  - Expected \\"main\\" to be of type string but got 1333.
770
- - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\"."
937
+ - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\".
938
+ - Expected \\"minify\\" to be of type boolean but got \\"INVALID\\".
939
+ - Expected \\"node_compat\\" to be of type boolean but got \\"INVALID\\"."
771
940
  `);
772
941
  });
773
942
 
774
- it("should error on invalid `name` value with spaces", () => {
775
- const expectedConfig: RawEnvironment = {
776
- name: "NCC 1701 D",
777
- } as unknown as RawEnvironment;
943
+ describe("name", () => {
944
+ it("should error on invalid `name` value with spaces", () => {
945
+ const expectedConfig: RawEnvironment = {
946
+ name: "NCC 1701 D",
947
+ } as unknown as RawEnvironment;
778
948
 
779
- const { config, diagnostics } = normalizeAndValidateConfig(
780
- expectedConfig,
781
- undefined,
782
- { env: undefined }
783
- );
949
+ const { config, diagnostics } = normalizeAndValidateConfig(
950
+ expectedConfig,
951
+ undefined,
952
+ { env: undefined }
953
+ );
784
954
 
785
- expect(config).toEqual(expect.objectContaining(expectedConfig));
786
- expect(diagnostics.hasWarnings()).toBe(false);
787
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
788
- "Processing wrangler configuration:
789
- - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"NCC 1701 D\\"."
790
- `);
791
- });
955
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
956
+ expect(diagnostics.hasWarnings()).toBe(false);
957
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
958
+ "Processing wrangler configuration:
959
+ - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"NCC 1701 D\\"."
960
+ `);
961
+ });
792
962
 
793
- it("should be valid `name` with underscores", () => {
794
- const expectedConfig: RawEnvironment = {
795
- name: "enterprise_nx_01",
796
- } as unknown as RawEnvironment;
963
+ it("should be valid `name` with underscores", () => {
964
+ const expectedConfig: RawEnvironment = {
965
+ name: "enterprise_nx_01",
966
+ } as unknown as RawEnvironment;
797
967
 
798
- const { config, diagnostics } = normalizeAndValidateConfig(
799
- expectedConfig,
800
- undefined,
801
- { env: undefined }
802
- );
968
+ const { config, diagnostics } = normalizeAndValidateConfig(
969
+ expectedConfig,
970
+ undefined,
971
+ { env: undefined }
972
+ );
803
973
 
804
- expect(config).toEqual(expect.objectContaining(expectedConfig));
805
- expect(diagnostics.hasWarnings()).toBe(false);
806
- expect(diagnostics.hasErrors()).toBe(false);
807
- });
974
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
975
+ expect(diagnostics.hasWarnings()).toBe(false);
976
+ expect(diagnostics.hasErrors()).toBe(false);
977
+ });
808
978
 
809
- it("should error on invalid `name` value with special characters", () => {
810
- const expectedConfig: RawEnvironment = {
811
- name: "Thy'lek-Shran",
812
- } as unknown as RawEnvironment;
979
+ it("should error on invalid `name` value with special characters", () => {
980
+ const expectedConfig: RawEnvironment = {
981
+ name: "Thy'lek-Shran",
982
+ } as unknown as RawEnvironment;
813
983
 
814
- const { config, diagnostics } = normalizeAndValidateConfig(
815
- expectedConfig,
816
- undefined,
817
- { env: undefined }
818
- );
984
+ const { config, diagnostics } = normalizeAndValidateConfig(
985
+ expectedConfig,
986
+ undefined,
987
+ { env: undefined }
988
+ );
819
989
 
820
- expect(config).toEqual(expect.objectContaining(expectedConfig));
821
- expect(diagnostics.hasWarnings()).toBe(false);
822
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
823
- "Processing wrangler configuration:
824
- - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"Thy'lek-Shran\\"."
825
- `);
826
- });
990
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
991
+ expect(diagnostics.hasWarnings()).toBe(false);
992
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
993
+ "Processing wrangler configuration:
994
+ - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"Thy'lek-Shran\\"."
995
+ `);
996
+ });
827
997
 
828
- it("should error on invalid `name` value with only special characters", () => {
829
- const expectedConfig: RawEnvironment = {
830
- name: "!@#$%^&*(()",
831
- } as unknown as RawEnvironment;
998
+ it("should error on invalid `name` value with only special characters", () => {
999
+ const expectedConfig: RawEnvironment = {
1000
+ name: "!@#$%^&*(()",
1001
+ } as unknown as RawEnvironment;
832
1002
 
833
- const { config, diagnostics } = normalizeAndValidateConfig(
834
- expectedConfig,
835
- undefined,
836
- { env: undefined }
837
- );
1003
+ const { config, diagnostics } = normalizeAndValidateConfig(
1004
+ expectedConfig,
1005
+ undefined,
1006
+ { env: undefined }
1007
+ );
838
1008
 
839
- expect(config).toEqual(expect.objectContaining(expectedConfig));
840
- expect(diagnostics.hasWarnings()).toBe(false);
841
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
842
- "Processing wrangler configuration:
843
- - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"!@#$%^&*(()\\"."
844
- `);
1009
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
1010
+ expect(diagnostics.hasWarnings()).toBe(false);
1011
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1012
+ "Processing wrangler configuration:
1013
+ - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"!@#$%^&*(()\\"."
1014
+ `);
1015
+ });
845
1016
  });
846
1017
 
847
- it("should override build.upload config defaults with provided values and warn about deprecations", () => {
848
- const expectedConfig: RawEnvironment = {
849
- build: {
850
- upload: {
851
- dir: "src",
852
- format: "modules",
853
- main: "index.ts",
854
- rules: [{ type: "Text", globs: ["GLOB"], fallthrough: true }],
1018
+ describe("build", () => {
1019
+ it("should override build.upload config defaults with provided values and warn about deprecations", () => {
1020
+ const expectedConfig: RawEnvironment = {
1021
+ build: {
1022
+ upload: {
1023
+ dir: "src",
1024
+ format: "modules",
1025
+ main: "index.ts",
1026
+ rules: [{ type: "Text", globs: ["GLOB"], fallthrough: true }],
1027
+ },
855
1028
  },
856
- },
857
- };
1029
+ };
858
1030
 
859
- const { config, diagnostics } = normalizeAndValidateConfig(
860
- expectedConfig,
861
- path.resolve("project/wrangler.toml"),
862
- { env: undefined }
863
- );
1031
+ const { config, diagnostics } = normalizeAndValidateConfig(
1032
+ expectedConfig,
1033
+ path.resolve("project/wrangler.toml"),
1034
+ { env: undefined }
1035
+ );
864
1036
 
865
- expect(config.main).toEqual(path.resolve("project/src/index.ts"));
866
- expect(config.build.upload).toBeUndefined();
867
- expect(diagnostics.hasErrors()).toBe(false);
868
- expect(diagnostics.hasWarnings()).toBe(true);
869
- expect(normalizePath(diagnostics.renderWarnings()))
870
- .toMatchInlineSnapshot(`
871
- "Processing project/wrangler.toml configuration:
872
- - Deprecation: \\"build.upload.format\\":
873
- The format is inferred automatically from the code.
874
- - Deprecation: \\"build.upload.main\\":
875
- Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
876
- Then add the top level \`main\` field to your configuration file:
877
- \`\`\`
878
- main = \\"src/index.ts\\"
879
- \`\`\`
880
- - Deprecation: \\"build.upload.dir\\":
881
- Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the Worker.
882
- - 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:
883
- \`\`\`
884
- [[rules]]
885
- type = \\"Text\\"
886
- globs = [ \\"GLOB\\" ]
887
- fallthrough = true
888
- \`\`\`"
889
- `);
890
- });
1037
+ expect(config.main).toEqual(path.resolve("project/src/index.ts"));
1038
+ expect(config.build.upload).toBeUndefined();
1039
+ expect(diagnostics.hasErrors()).toBe(false);
1040
+ expect(diagnostics.hasWarnings()).toBe(true);
1041
+ expect(normalizePath(diagnostics.renderWarnings()))
1042
+ .toMatchInlineSnapshot(`
1043
+ "Processing project/wrangler.toml configuration:
1044
+ - Deprecation: \\"build.upload.format\\":
1045
+ The format is inferred automatically from the code.
1046
+ - Deprecation: \\"build.upload.main\\":
1047
+ Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
1048
+ Then add the top level \`main\` field to your configuration file:
1049
+ \`\`\`
1050
+ main = \\"src/index.ts\\"
1051
+ \`\`\`
1052
+ - Deprecation: \\"build.upload.dir\\":
1053
+ Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the Worker.
1054
+ - 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:
1055
+ \`\`\`
1056
+ [[rules]]
1057
+ type = \\"Text\\"
1058
+ globs = [ \\"GLOB\\" ]
1059
+ fallthrough = true
1060
+ \`\`\`"
1061
+ `);
1062
+ });
891
1063
 
892
- it("should default custom build watch directories to src", () => {
893
- const expectedConfig: RawEnvironment = {
894
- build: {
895
- command: "execute some --build",
896
- },
897
- };
1064
+ it("should default custom build watch directories to src", () => {
1065
+ const expectedConfig: RawEnvironment = {
1066
+ build: {
1067
+ command: "execute some --build",
1068
+ },
1069
+ };
898
1070
 
899
- const { config, diagnostics } = normalizeAndValidateConfig(
900
- expectedConfig,
901
- undefined,
902
- { env: undefined }
903
- );
1071
+ const { config, diagnostics } = normalizeAndValidateConfig(
1072
+ expectedConfig,
1073
+ undefined,
1074
+ { env: undefined }
1075
+ );
904
1076
 
905
- expect(config.build).toEqual(
906
- expect.objectContaining({
907
- command: "execute some --build",
908
- watch_dir: "./src",
909
- })
910
- );
1077
+ expect(config.build).toEqual(
1078
+ expect.objectContaining({
1079
+ command: "execute some --build",
1080
+ watch_dir: "./src",
1081
+ })
1082
+ );
911
1083
 
912
- expect(diagnostics.hasErrors()).toBe(false);
913
- expect(diagnostics.hasWarnings()).toBe(false);
914
- });
1084
+ expect(diagnostics.hasErrors()).toBe(false);
1085
+ expect(diagnostics.hasWarnings()).toBe(false);
1086
+ });
915
1087
 
916
- it("should resolve custom build watch directories relative to wrangler.toml", async () => {
917
- const expectedConfig: RawEnvironment = {
918
- build: {
919
- command: "execute some --build",
920
- watch_dir: "some/path",
921
- },
922
- };
1088
+ it("should resolve custom build watch directories relative to wrangler.toml", async () => {
1089
+ const expectedConfig: RawEnvironment = {
1090
+ build: {
1091
+ command: "execute some --build",
1092
+ watch_dir: "some/path",
1093
+ },
1094
+ };
923
1095
 
924
- const { config, diagnostics } = normalizeAndValidateConfig(
925
- expectedConfig,
926
- "project/wrangler.toml",
927
- { env: undefined }
928
- );
1096
+ const { config, diagnostics } = normalizeAndValidateConfig(
1097
+ expectedConfig,
1098
+ "project/wrangler.toml",
1099
+ { env: undefined }
1100
+ );
929
1101
 
930
- expect(config.build).toEqual(
931
- expect.objectContaining({
932
- command: "execute some --build",
933
- watch_dir: path.normalize("project/some/path"),
934
- })
935
- );
1102
+ expect(config.build).toEqual(
1103
+ expect.objectContaining({
1104
+ command: "execute some --build",
1105
+ watch_dir: path.normalize("project/some/path"),
1106
+ })
1107
+ );
936
1108
 
937
- expect(diagnostics.hasErrors()).toBe(false);
938
- expect(diagnostics.hasWarnings()).toBe(false);
1109
+ expect(diagnostics.hasErrors()).toBe(false);
1110
+ expect(diagnostics.hasWarnings()).toBe(false);
1111
+ });
1112
+
1113
+ it("should allow watch_dir to be an array of paths", () => {
1114
+ const expectedConfig: RawEnvironment = {
1115
+ build: {
1116
+ command: "execute some --build",
1117
+ watch_dir: ["some/path/a", "some/path/b", "some/path/c"],
1118
+ },
1119
+ };
1120
+
1121
+ const { config, diagnostics } = normalizeAndValidateConfig(
1122
+ expectedConfig,
1123
+ "project/wrangler.toml",
1124
+ { env: undefined }
1125
+ );
1126
+
1127
+ expect(config.build).toEqual(
1128
+ expect.objectContaining({
1129
+ command: "execute some --build",
1130
+ watch_dir: [
1131
+ path.normalize("project/some/path/a"),
1132
+ path.normalize("project/some/path/b"),
1133
+ path.normalize("project/some/path/c"),
1134
+ ],
1135
+ })
1136
+ );
1137
+
1138
+ expect(diagnostics.hasErrors()).toBe(false);
1139
+ expect(diagnostics.hasWarnings()).toBe(false);
1140
+ });
1141
+
1142
+ it("should error when the watch_dir array isn't an array of strings", () => {
1143
+ const expectedConfig: RawEnvironment = {
1144
+ build: {
1145
+ command: "execute some --build",
1146
+ watch_dir: [
1147
+ "some/path/a",
1148
+ "some/path/b",
1149
+ // @ts-expect-error intentionally bad "paths"
1150
+ 123,
1151
+ "some/path/c",
1152
+ // @ts-expect-error intentionally bad "paths"
1153
+ false,
1154
+ ],
1155
+ },
1156
+ };
1157
+
1158
+ const { config, diagnostics } = normalizeAndValidateConfig(
1159
+ expectedConfig,
1160
+ "project/wrangler.toml",
1161
+ { env: undefined }
1162
+ );
1163
+
1164
+ expect(config.build).toEqual(
1165
+ expect.objectContaining({
1166
+ command: "execute some --build",
1167
+ watch_dir: [
1168
+ path.normalize("project/some/path/a"),
1169
+ path.normalize("project/some/path/b"),
1170
+ path.normalize("project/123"),
1171
+ path.normalize("project/some/path/c"),
1172
+ path.normalize("project/false"),
1173
+ ],
1174
+ })
1175
+ );
1176
+
1177
+ expect(diagnostics.hasWarnings()).toBe(false);
1178
+ expect(diagnostics.hasErrors()).toBe(true);
1179
+
1180
+ expect(normalizePath(diagnostics.renderErrors()))
1181
+ .toMatchInlineSnapshot(`
1182
+ "Processing project/wrangler.toml configuration:
1183
+ - Expected \\"build.watch_dir.[2]\\" to be of type string but got 123.
1184
+ - Expected \\"build.watch_dir.[4]\\" to be of type string but got false."
1185
+ `);
1186
+ });
939
1187
  });
940
1188
 
941
1189
  describe("durable_objects field", () => {
@@ -1106,13 +1354,29 @@ describe("normalizeAndValidateConfig()", () => {
1106
1354
  durable_objects: {
1107
1355
  bindings: [
1108
1356
  {},
1109
- { name: "VALID" },
1357
+ { name: "MISSING_CLASS" },
1110
1358
  { name: 1555, class_name: 1666 },
1111
1359
  {
1112
1360
  name: 1777,
1113
1361
  class_name: 1888,
1114
1362
  script_name: 1999,
1115
1363
  },
1364
+ {
1365
+ name: "SOMENAME",
1366
+ class_name: "SomeClass",
1367
+ environment: "staging",
1368
+ },
1369
+ {
1370
+ name: 1778,
1371
+ class_name: 1889,
1372
+ script_name: 1992,
1373
+ environment: 2111,
1374
+ },
1375
+ {
1376
+ name: 1772,
1377
+ class_name: 1883,
1378
+ environment: 2112,
1379
+ },
1116
1380
  ],
1117
1381
  },
1118
1382
  } as unknown as RawConfig,
@@ -1126,6 +1390,8 @@ describe("normalizeAndValidateConfig()", () => {
1126
1390
  })
1127
1391
  );
1128
1392
  expect(diagnostics.hasWarnings()).toBe(false);
1393
+
1394
+ expect(diagnostics.hasErrors()).toBe(true);
1129
1395
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1130
1396
  "Processing wrangler configuration:
1131
1397
 
@@ -1133,7 +1399,7 @@ describe("normalizeAndValidateConfig()", () => {
1133
1399
  - binding should have a string \\"name\\" field.
1134
1400
  - binding should have a string \\"class_name\\" field.
1135
1401
 
1136
- - \\"durable_objects.bindings[1]\\": {\\"name\\":\\"VALID\\"}
1402
+ - \\"durable_objects.bindings[1]\\": {\\"name\\":\\"MISSING_CLASS\\"}
1137
1403
  - binding should have a string \\"class_name\\" field.
1138
1404
 
1139
1405
  - \\"durable_objects.bindings[2]\\": {\\"name\\":1555,\\"class_name\\":1666}
@@ -1143,7 +1409,22 @@ describe("normalizeAndValidateConfig()", () => {
1143
1409
  - \\"durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
1144
1410
  - binding should have a string \\"name\\" field.
1145
1411
  - binding should have a string \\"class_name\\" field.
1146
- - binding should, optionally, have a string \\"script_name\\" field."
1412
+ - the field \\"script_name\\", when present, should be a string.
1413
+
1414
+ - \\"durable_objects.bindings[4]\\": {\\"name\\":\\"SOMENAME\\",\\"class_name\\":\\"SomeClass\\",\\"environment\\":\\"staging\\"}
1415
+ - binding should have a \\"script_name\\" field if \\"environment\\" is present.
1416
+
1417
+ - \\"durable_objects.bindings[5]\\": {\\"name\\":1778,\\"class_name\\":1889,\\"script_name\\":1992,\\"environment\\":2111}
1418
+ - binding should have a string \\"name\\" field.
1419
+ - binding should have a string \\"class_name\\" field.
1420
+ - the field \\"script_name\\", when present, should be a string.
1421
+ - the field \\"environment\\", when present, should be a string.
1422
+
1423
+ - \\"durable_objects.bindings[6]\\": {\\"name\\":1772,\\"class_name\\":1883,\\"environment\\":2112}
1424
+ - binding should have a string \\"name\\" field.
1425
+ - binding should have a string \\"class_name\\" field.
1426
+ - the field \\"environment\\", when present, should be a string.
1427
+ - binding should have a \\"script_name\\" field if \\"environment\\" is present."
1147
1428
  `);
1148
1429
  });
1149
1430
  });
@@ -1358,6 +1639,151 @@ describe("normalizeAndValidateConfig()", () => {
1358
1639
  });
1359
1640
  });
1360
1641
 
1642
+ describe("services field", () => {
1643
+ it("should error if services is an object", () => {
1644
+ const { config, diagnostics } = normalizeAndValidateConfig(
1645
+ { services: {} } as unknown as RawConfig,
1646
+ undefined,
1647
+ { env: undefined }
1648
+ );
1649
+
1650
+ expect(config).toEqual(
1651
+ expect.not.objectContaining({ services: expect.anything })
1652
+ );
1653
+ expect(diagnostics.hasWarnings()).toBe(true);
1654
+ expect(diagnostics.hasErrors()).toBe(true);
1655
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1656
+ "Processing wrangler configuration:
1657
+ - \\"services\\" fields are experimental and may change or break at any time."
1658
+ `);
1659
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1660
+ "Processing wrangler configuration:
1661
+ - The field \\"services\\" should be an array but got {}."
1662
+ `);
1663
+ });
1664
+
1665
+ it("should error if services is a string", () => {
1666
+ const { config, diagnostics } = normalizeAndValidateConfig(
1667
+ { services: "BAD" } as unknown as RawConfig,
1668
+ undefined,
1669
+ { env: undefined }
1670
+ );
1671
+
1672
+ expect(config).toEqual(
1673
+ expect.not.objectContaining({ services: expect.anything })
1674
+ );
1675
+ expect(diagnostics.hasWarnings()).toBe(true);
1676
+ expect(diagnostics.hasErrors()).toBe(true);
1677
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1678
+ "Processing wrangler configuration:
1679
+ - \\"services\\" fields are experimental and may change or break at any time."
1680
+ `);
1681
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1682
+ "Processing wrangler configuration:
1683
+ - The field \\"services\\" should be an array but got \\"BAD\\"."
1684
+ `);
1685
+ });
1686
+
1687
+ it("should error if services is a number", () => {
1688
+ const { config, diagnostics } = normalizeAndValidateConfig(
1689
+ { services: 999 } as unknown as RawConfig,
1690
+ undefined,
1691
+ { env: undefined }
1692
+ );
1693
+
1694
+ expect(config).toEqual(
1695
+ expect.not.objectContaining({ services: expect.anything })
1696
+ );
1697
+ expect(diagnostics.hasWarnings()).toBe(true);
1698
+ expect(diagnostics.hasErrors()).toBe(true);
1699
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1700
+ "Processing wrangler configuration:
1701
+ - \\"services\\" fields are experimental and may change or break at any time."
1702
+ `);
1703
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1704
+ "Processing wrangler configuration:
1705
+ - The field \\"services\\" should be an array but got 999."
1706
+ `);
1707
+ });
1708
+
1709
+ it("should error if services is null", () => {
1710
+ const { config, diagnostics } = normalizeAndValidateConfig(
1711
+ { services: null } as unknown as RawConfig,
1712
+ undefined,
1713
+ { env: undefined }
1714
+ );
1715
+
1716
+ expect(config).toEqual(
1717
+ expect.not.objectContaining({ services: expect.anything })
1718
+ );
1719
+ expect(diagnostics.hasWarnings()).toBe(true);
1720
+ expect(diagnostics.hasErrors()).toBe(true);
1721
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1722
+ "Processing wrangler configuration:
1723
+ - \\"services\\" fields are experimental and may change or break at any time."
1724
+ `);
1725
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1726
+ "Processing wrangler configuration:
1727
+ - The field \\"services\\" should be an array but got null."
1728
+ `);
1729
+ });
1730
+
1731
+ it("should error if services bindings are not valid", () => {
1732
+ const { config, diagnostics } = normalizeAndValidateConfig(
1733
+ {
1734
+ services: [
1735
+ {},
1736
+ { binding: "SERVICE_BINDING_1" },
1737
+ { binding: 123, service: 456 },
1738
+ { binding: 123, service: 456, environment: 789 },
1739
+ { binding: "SERVICE_BINDING_1", service: 456, environment: 789 },
1740
+ {
1741
+ binding: 123,
1742
+ service: "SERVICE_BINDING_SERVICE_1",
1743
+ environment: 789,
1744
+ },
1745
+ {
1746
+ binding: 123,
1747
+ service: 456,
1748
+ environment: "SERVICE_BINDING_ENVIRONMENT_1",
1749
+ },
1750
+ ],
1751
+ } as unknown as RawConfig,
1752
+ undefined,
1753
+ { env: undefined }
1754
+ );
1755
+
1756
+ expect(config).toEqual(
1757
+ expect.not.objectContaining({
1758
+ services: { bindings: expect.anything },
1759
+ })
1760
+ );
1761
+ expect(diagnostics.hasWarnings()).toBe(true);
1762
+ expect(diagnostics.hasErrors()).toBe(true);
1763
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1764
+ "Processing wrangler configuration:
1765
+ - \\"services\\" fields are experimental and may change or break at any time."
1766
+ `);
1767
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1768
+ "Processing wrangler configuration:
1769
+ - \\"services[0]\\" bindings should have a string \\"binding\\" field but got {}.
1770
+ - \\"services[0]\\" bindings should have a string \\"service\\" field but got {}.
1771
+ - \\"services[1]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":\\"SERVICE_BINDING_1\\"}.
1772
+ - \\"services[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456}.
1773
+ - \\"services[2]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":123,\\"service\\":456}.
1774
+ - \\"services[3]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":789}.
1775
+ - \\"services[3]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":789}.
1776
+ - \\"services[3]\\" bindings should have a string \\"environment\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":789}.
1777
+ - \\"services[4]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":\\"SERVICE_BINDING_1\\",\\"service\\":456,\\"environment\\":789}.
1778
+ - \\"services[4]\\" bindings should have a string \\"environment\\" field but got {\\"binding\\":\\"SERVICE_BINDING_1\\",\\"service\\":456,\\"environment\\":789}.
1779
+ - \\"services[5]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":\\"SERVICE_BINDING_SERVICE_1\\",\\"environment\\":789}.
1780
+ - \\"services[5]\\" bindings should have a string \\"environment\\" field but got {\\"binding\\":123,\\"service\\":\\"SERVICE_BINDING_SERVICE_1\\",\\"environment\\":789}.
1781
+ - \\"services[6]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":\\"SERVICE_BINDING_ENVIRONMENT_1\\"}.
1782
+ - \\"services[6]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":\\"SERVICE_BINDING_ENVIRONMENT_1\\"}."
1783
+ `);
1784
+ });
1785
+ });
1786
+
1361
1787
  describe("unsafe field", () => {
1362
1788
  it("should error if unsafe is an array", () => {
1363
1789
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -1622,14 +2048,7 @@ describe("normalizeAndValidateConfig()", () => {
1622
2048
  - Deprecation: \\"zone_id\\":
1623
2049
  This is unnecessary since we can deduce this from routes directly.
1624
2050
  - Deprecation: \\"experimental_services\\":
1625
- The \\"experimental_services\\" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
1626
- \`\`\`
1627
- [[unsafe.bindings]]
1628
- name = \\"mock-name\\"
1629
- type = \\"service\\"
1630
- service = \\"SERVICE\\"
1631
- environment = \\"ENV\\"
1632
- \`\`\`"
2051
+ The \\"experimental_services\\" field is no longer supported. Simply rename the [experimental_services] field to [services]."
1633
2052
  `);
1634
2053
  });
1635
2054
  });
@@ -1722,6 +2141,8 @@ describe("normalizeAndValidateConfig()", () => {
1722
2141
  cwd: "CWD",
1723
2142
  watch_dir: "WATCH_DIR",
1724
2143
  },
2144
+ minify: true,
2145
+ node_compat: true,
1725
2146
  };
1726
2147
 
1727
2148
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -1762,6 +2183,8 @@ describe("normalizeAndValidateConfig()", () => {
1762
2183
  cwd: "ENV_CWD",
1763
2184
  watch_dir: "ENV_WATCH_DIR",
1764
2185
  },
2186
+ minify: false,
2187
+ node_compat: false,
1765
2188
  };
1766
2189
  const rawConfig: RawConfig = {
1767
2190
  name: "mock-name",
@@ -1781,6 +2204,8 @@ describe("normalizeAndValidateConfig()", () => {
1781
2204
  cwd: "CWD",
1782
2205
  watch_dir: "WATCH_DIR",
1783
2206
  },
2207
+ minify: true,
2208
+ node_compat: true,
1784
2209
  env: {
1785
2210
  ENV1: rawEnv,
1786
2211
  },
@@ -2031,6 +2456,8 @@ describe("normalizeAndValidateConfig()", () => {
2031
2456
  cwd: 1555,
2032
2457
  watch_dir: 1666,
2033
2458
  },
2459
+ minify: "INVALID",
2460
+ node_compat: "INVALID",
2034
2461
  } as unknown as RawEnvironment;
2035
2462
 
2036
2463
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -2045,8 +2472,8 @@ describe("normalizeAndValidateConfig()", () => {
2045
2472
  "Processing wrangler configuration:
2046
2473
 
2047
2474
  - \\"env.ENV1\\" environment configuration
2048
- - Expected \\"route\\" to be either a string, or an object with shape { pattern, zone_id | zone_name }, but got 888.
2049
- - Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, zone_id | zone_name }, but these weren't valid: [
2475
+ - Expected \\"route\\" to be either a string, or an object with shape { pattern, custom_domain, zone_id | zone_name }, but got 888.
2476
+ - Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, custom_domain, zone_id | zone_name }, but these weren't valid: [
2050
2477
  666,
2051
2478
  777
2052
2479
  ].
@@ -2063,7 +2490,9 @@ describe("normalizeAndValidateConfig()", () => {
2063
2490
  - Expected \\"tsconfig\\" to be of type string but got 123.
2064
2491
  - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got 111.
2065
2492
  - Expected \\"main\\" to be of type string but got 1333.
2066
- - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\"."
2493
+ - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\".
2494
+ - Expected \\"minify\\" to be of type boolean but got \\"INVALID\\".
2495
+ - Expected \\"node_compat\\" to be of type boolean but got \\"INVALID\\"."
2067
2496
  `);
2068
2497
  });
2069
2498
 
@@ -2285,6 +2714,7 @@ describe("normalizeAndValidateConfig()", () => {
2285
2714
  })
2286
2715
  );
2287
2716
  expect(diagnostics.hasWarnings()).toBe(false);
2717
+ expect(diagnostics.hasErrors()).toBe(true);
2288
2718
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2289
2719
  "Processing wrangler configuration:
2290
2720
 
@@ -2304,7 +2734,7 @@ describe("normalizeAndValidateConfig()", () => {
2304
2734
  - \\"env.ENV1.durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
2305
2735
  - binding should have a string \\"name\\" field.
2306
2736
  - binding should have a string \\"class_name\\" field.
2307
- - binding should, optionally, have a string \\"script_name\\" field."
2737
+ - the field \\"script_name\\", when present, should be a string."
2308
2738
  `);
2309
2739
  });
2310
2740
  });
@@ -2869,14 +3299,7 @@ describe("normalizeAndValidateConfig()", () => {
2869
3299
  - Deprecation: \\"zone_id\\":
2870
3300
  This is unnecessary since we can deduce this from routes directly.
2871
3301
  - Deprecation: \\"experimental_services\\":
2872
- The \\"experimental_services\\" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
2873
- \`\`\`
2874
- [[unsafe.bindings]]
2875
- name = \\"mock-name\\"
2876
- type = \\"service\\"
2877
- service = \\"SERVICE\\"
2878
- environment = \\"ENV\\"
2879
- \`\`\`"
3302
+ The \\"experimental_services\\" field is no longer supported. Simply rename the [experimental_services] field to [services]."
2880
3303
  `);
2881
3304
  });
2882
3305
  });