wrangler 0.0.0-eab9542 → 0.0.0-eaf71b86c

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 (180) hide show
  1. package/README.md +29 -13
  2. package/bin/wrangler.js +50 -88
  3. package/config-schema.json +3074 -0
  4. package/package.json +196 -157
  5. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  6. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  7. package/templates/__tests__/tsconfig.json +8 -0
  8. package/templates/checked-fetch.js +19 -6
  9. package/templates/facade.d.ts +19 -0
  10. package/templates/gitignore +2 -3
  11. package/templates/init-tests/test-jest-new-worker.js +23 -0
  12. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  13. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  14. package/templates/middleware/common.ts +67 -0
  15. package/templates/middleware/loader-modules.ts +134 -0
  16. package/templates/middleware/loader-sw.ts +229 -0
  17. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  18. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  19. package/templates/middleware/middleware-mock-analytics-engine.d.ts +3 -0
  20. package/templates/middleware/middleware-mock-analytics-engine.ts +30 -0
  21. package/templates/middleware/middleware-pretty-error.ts +40 -0
  22. package/templates/middleware/middleware-scheduled.ts +29 -0
  23. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  24. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  25. package/templates/modules-watch-stub.js +4 -0
  26. package/templates/new-worker-scheduled.ts +1 -1
  27. package/templates/new-worker.js +1 -1
  28. package/templates/new-worker.ts +4 -1
  29. package/templates/pages-dev-pipeline.ts +32 -0
  30. package/templates/pages-dev-util.ts +55 -0
  31. package/templates/pages-shim.ts +9 -0
  32. package/templates/pages-template-plugin.ts +53 -18
  33. package/templates/pages-template-worker.ts +49 -12
  34. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  35. package/templates/startDevWorker/ProxyWorker.ts +336 -0
  36. package/templates/tsconfig-sanity.ts +11 -0
  37. package/templates/tsconfig.init.json +22 -0
  38. package/templates/tsconfig.json +5 -102
  39. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  40. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  41. package/wrangler-dist/ProxyWorker.js +241 -0
  42. package/wrangler-dist/ProxyWorker.js.map +6 -0
  43. package/wrangler-dist/cli.d.ts +26465 -0
  44. package/wrangler-dist/cli.js +198587 -108581
  45. package/wrangler-dist/wasm-sync.wasm +0 -0
  46. package/Cloudflare_CA.pem +0 -18
  47. package/import_meta_url.js +0 -3
  48. package/miniflare-config-stubs/.env.empty +0 -0
  49. package/miniflare-config-stubs/package.empty.json +0 -1
  50. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  51. package/miniflare-dist/index.mjs +0 -4894
  52. package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
  53. package/src/__tests__/config-cache.test.ts +0 -42
  54. package/src/__tests__/configuration.test.ts +0 -3946
  55. package/src/__tests__/dev.test.tsx +0 -1159
  56. package/src/__tests__/guess-worker-format.test.ts +0 -85
  57. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  58. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  59. package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
  60. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  61. package/src/__tests__/helpers/mock-bin.ts +0 -36
  62. package/src/__tests__/helpers/mock-cfetch.ts +0 -211
  63. package/src/__tests__/helpers/mock-console.ts +0 -97
  64. package/src/__tests__/helpers/mock-dialogs.ts +0 -153
  65. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  66. package/src/__tests__/helpers/mock-istty.ts +0 -74
  67. package/src/__tests__/helpers/mock-kv.ts +0 -33
  68. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -250
  69. package/src/__tests__/helpers/mock-process.ts +0 -39
  70. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  71. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  72. package/src/__tests__/helpers/run-in-tmp.ts +0 -39
  73. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  74. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  75. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  76. package/src/__tests__/https-options.test.ts +0 -130
  77. package/src/__tests__/index.test.ts +0 -262
  78. package/src/__tests__/init.test.ts +0 -1992
  79. package/src/__tests__/jest.setup.ts +0 -107
  80. package/src/__tests__/kv.test.ts +0 -1619
  81. package/src/__tests__/logger.test.ts +0 -141
  82. package/src/__tests__/package-manager.test.ts +0 -353
  83. package/src/__tests__/pages.test.ts +0 -1254
  84. package/src/__tests__/parse.test.ts +0 -330
  85. package/src/__tests__/publish.test.ts +0 -6569
  86. package/src/__tests__/pubsub.test.ts +0 -367
  87. package/src/__tests__/r2.test.ts +0 -233
  88. package/src/__tests__/route.test.ts +0 -45
  89. package/src/__tests__/secret.test.ts +0 -486
  90. package/src/__tests__/tail.test.ts +0 -690
  91. package/src/__tests__/user.test.ts +0 -143
  92. package/src/__tests__/whoami.test.tsx +0 -220
  93. package/src/__tests__/worker-namespace.test.ts +0 -327
  94. package/src/abort.d.ts +0 -3
  95. package/src/api/dev.ts +0 -52
  96. package/src/api/index.ts +0 -1
  97. package/src/bundle-reporter.tsx +0 -29
  98. package/src/bundle.ts +0 -212
  99. package/src/cfetch/index.ts +0 -121
  100. package/src/cfetch/internal.ts +0 -149
  101. package/src/cli.ts +0 -27
  102. package/src/config/README.md +0 -107
  103. package/src/config/config.ts +0 -243
  104. package/src/config/diagnostics.ts +0 -80
  105. package/src/config/environment.ts +0 -453
  106. package/src/config/index.ts +0 -238
  107. package/src/config/validation-helpers.ts +0 -584
  108. package/src/config/validation.ts +0 -1745
  109. package/src/config-cache.ts +0 -83
  110. package/src/create-worker-preview.ts +0 -255
  111. package/src/create-worker-upload-form.ts +0 -263
  112. package/src/dev/dev-vars.ts +0 -36
  113. package/src/dev/dev.tsx +0 -417
  114. package/src/dev/local.tsx +0 -352
  115. package/src/dev/remote.tsx +0 -382
  116. package/src/dev/use-esbuild.ts +0 -150
  117. package/src/dev.tsx +0 -538
  118. package/src/dialogs.tsx +0 -135
  119. package/src/durable.ts +0 -102
  120. package/src/entry.ts +0 -328
  121. package/src/environment-variables.ts +0 -35
  122. package/src/errors.ts +0 -11
  123. package/src/generate.ts +0 -33
  124. package/src/git-client.ts +0 -42
  125. package/src/https-options.ts +0 -123
  126. package/src/index.tsx +0 -1871
  127. package/src/init.ts +0 -549
  128. package/src/inspect.ts +0 -662
  129. package/src/intl-polyfill.d.ts +0 -139
  130. package/src/is-interactive.ts +0 -12
  131. package/src/kv.ts +0 -408
  132. package/src/logger.ts +0 -73
  133. package/src/miniflare-cli/README.md +0 -30
  134. package/src/miniflare-cli/enum-keys.ts +0 -17
  135. package/src/miniflare-cli/index.ts +0 -53
  136. package/src/miniflare-cli/request-context.ts +0 -40
  137. package/src/module-collection.ts +0 -258
  138. package/src/open-in-browser.ts +0 -17
  139. package/src/package-manager.ts +0 -174
  140. package/src/pages/build.tsx +0 -202
  141. package/src/pages/constants.ts +0 -7
  142. package/src/pages/deployments.tsx +0 -101
  143. package/src/pages/dev.tsx +0 -964
  144. package/src/pages/functions/buildPlugin.ts +0 -105
  145. package/src/pages/functions/buildWorker.ts +0 -151
  146. package/src/pages/functions/filepath-routing.test.ts +0 -234
  147. package/src/pages/functions/filepath-routing.ts +0 -189
  148. package/src/pages/functions/identifiers.ts +0 -78
  149. package/src/pages/functions/routes.ts +0 -151
  150. package/src/pages/index.tsx +0 -84
  151. package/src/pages/projects.tsx +0 -157
  152. package/src/pages/publish.tsx +0 -335
  153. package/src/pages/types.ts +0 -40
  154. package/src/pages/upload.tsx +0 -384
  155. package/src/pages/utils.ts +0 -12
  156. package/src/parse.ts +0 -286
  157. package/src/paths.ts +0 -26
  158. package/src/preview.ts +0 -31
  159. package/src/proxy.ts +0 -476
  160. package/src/publish.ts +0 -767
  161. package/src/pubsub/index.ts +0 -286
  162. package/src/pubsub/pubsub-commands.tsx +0 -577
  163. package/src/r2.ts +0 -50
  164. package/src/selfsigned.d.ts +0 -29
  165. package/src/sites.tsx +0 -372
  166. package/src/tail/filters.ts +0 -279
  167. package/src/tail/index.ts +0 -299
  168. package/src/tail/printing.ts +0 -67
  169. package/src/update-check.ts +0 -19
  170. package/src/user/choose-account.tsx +0 -60
  171. package/src/user/env-vars.ts +0 -46
  172. package/src/user/generate-auth-url.ts +0 -33
  173. package/src/user/generate-random-state.ts +0 -16
  174. package/src/user/index.ts +0 -3
  175. package/src/user/user.tsx +0 -1161
  176. package/src/whoami.tsx +0 -90
  177. package/src/worker-namespace.ts +0 -190
  178. package/src/worker.ts +0 -191
  179. package/src/zones.ts +0 -76
  180. package/templates/static-asset-facade.js +0 -43
@@ -1,3946 +0,0 @@
1
- import path from "node:path";
2
- import { normalizeAndValidateConfig } from "../config/validation";
3
- import { normalizeSlashes } from "./helpers/mock-console";
4
- import type {
5
- ConfigFields,
6
- RawDevConfig,
7
- RawConfig,
8
- RawEnvironment,
9
- } from "../config";
10
-
11
- describe("normalizeAndValidateConfig()", () => {
12
- it("should use defaults for empty configuration", () => {
13
- const { config, diagnostics } = normalizeAndValidateConfig({}, undefined, {
14
- env: undefined,
15
- });
16
-
17
- expect(config).toEqual({
18
- account_id: undefined,
19
- assets: undefined,
20
- build: {
21
- command: undefined,
22
- cwd: undefined,
23
- watch_dir: "./src",
24
- },
25
- compatibility_date: undefined,
26
- compatibility_flags: [],
27
- configPath: undefined,
28
- dev: {
29
- ip: "localhost",
30
- local_protocol: "http",
31
- port: undefined, // the default of 8787 is set at runtime
32
- upstream_protocol: "https",
33
- host: undefined,
34
- },
35
- durable_objects: {
36
- bindings: [],
37
- },
38
- jsx_factory: "React.createElement",
39
- jsx_fragment: "React.Fragment",
40
- tsconfig: undefined,
41
- kv_namespaces: [],
42
- legacy_env: true,
43
- main: undefined,
44
- migrations: [],
45
- name: undefined,
46
- r2_buckets: [],
47
- services: [],
48
- route: undefined,
49
- routes: undefined,
50
- rules: [],
51
- site: undefined,
52
- text_blobs: undefined,
53
- triggers: {
54
- crons: [],
55
- },
56
- unsafe: {
57
- bindings: [],
58
- },
59
- worker_namespaces: [],
60
- usage_model: undefined,
61
- vars: {},
62
- define: {},
63
- wasm_modules: undefined,
64
- data_blobs: undefined,
65
- workers_dev: undefined,
66
- zone_id: undefined,
67
- no_bundle: undefined,
68
- minify: undefined,
69
- node_compat: undefined,
70
- });
71
- expect(diagnostics.hasErrors()).toBe(false);
72
- expect(diagnostics.hasWarnings()).toBe(false);
73
- });
74
-
75
- describe("top-level non-environment configuration", () => {
76
- it("should override config defaults with provided values", () => {
77
- const expectedConfig: Partial<ConfigFields<RawDevConfig>> = {
78
- legacy_env: true,
79
- dev: {
80
- ip: "255.255.255.255",
81
- port: 9999,
82
- local_protocol: "https",
83
- upstream_protocol: "http",
84
- },
85
- };
86
-
87
- const { config, diagnostics } = normalizeAndValidateConfig(
88
- expectedConfig,
89
- undefined,
90
- { env: undefined }
91
- );
92
-
93
- expect(config).toEqual(expect.objectContaining(expectedConfig));
94
- expect(diagnostics.hasErrors()).toBe(false);
95
- expect(diagnostics.hasWarnings()).toBe(false);
96
- });
97
-
98
- it("should error on invalid top level fields", () => {
99
- const expectedConfig = {
100
- legacy_env: "FOO",
101
- dev: {
102
- ip: 222,
103
- port: "FOO",
104
- local_protocol: "wss",
105
- upstream_protocol: "ws",
106
- },
107
- };
108
-
109
- const { config, diagnostics } = normalizeAndValidateConfig(
110
- expectedConfig as unknown as RawConfig,
111
- undefined,
112
- { env: undefined }
113
- );
114
-
115
- expect(config).toEqual(
116
- expect.objectContaining({ ...expectedConfig, main: undefined })
117
- );
118
- expect(diagnostics.hasWarnings()).toBe(false);
119
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
120
- "Processing wrangler configuration:
121
- - Expected \\"legacy_env\\" to be of type boolean but got \\"FOO\\".
122
- - Expected \\"dev.ip\\" to be of type string but got 222.
123
- - Expected \\"dev.port\\" to be of type number but got \\"FOO\\".
124
- - Expected \\"dev.local_protocol\\" field to be one of [\\"http\\",\\"https\\"] but got \\"wss\\".
125
- - Expected \\"dev.upstream_protocol\\" field to be one of [\\"http\\",\\"https\\"] but got \\"ws\\"."
126
- `);
127
- });
128
-
129
- it("should warn on and remove unexpected top level fields", () => {
130
- const expectedConfig = {
131
- unexpected: {
132
- subkey: "some-value",
133
- },
134
- };
135
-
136
- const { config, diagnostics } = normalizeAndValidateConfig(
137
- expectedConfig as unknown as RawConfig,
138
- undefined,
139
- { env: undefined }
140
- );
141
-
142
- expect("unexpected" in config).toBe(false);
143
- expect(diagnostics.hasErrors()).toBe(false);
144
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
145
- "Processing wrangler configuration:
146
- - Unexpected fields found in top-level field: \\"unexpected\\""
147
- `);
148
- });
149
-
150
- it("should report a deprecation warning if `miniflare` appears at the top level", () => {
151
- const expectedConfig = {
152
- miniflare: {
153
- host: "localhost",
154
- },
155
- };
156
-
157
- const { config, diagnostics } = normalizeAndValidateConfig(
158
- expectedConfig as unknown as RawConfig,
159
- undefined,
160
- { env: 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
- - 😶 Ignored: \\"miniflare\\":
168
- Wrangler does not use configuration in the \`miniflare\` section. Unless you are using Miniflare directly you can remove this section."
169
- `);
170
- });
171
-
172
- it("should normalise a blank route value to be undefined", () => {
173
- const expectedConfig = {
174
- route: "",
175
- };
176
-
177
- const { config, diagnostics } = normalizeAndValidateConfig(
178
- expectedConfig as unknown as RawConfig,
179
- undefined,
180
- { env: undefined }
181
- );
182
-
183
- expect(config.route).toBeUndefined();
184
- expect(diagnostics.hasErrors()).toBe(false);
185
- expect(diagnostics.hasWarnings()).toBe(true);
186
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
187
- "Processing wrangler configuration:
188
- - The \\"route\\" field in your configuration is an empty string and will be ignored.
189
- Please remove the \\"route\\" field from your configuration."
190
- `);
191
- });
192
-
193
- it("should normalise a blank account_id value to be undefined", () => {
194
- const expectedConfig = {
195
- account_id: "",
196
- };
197
-
198
- const { config, diagnostics } = normalizeAndValidateConfig(
199
- expectedConfig as unknown as RawConfig,
200
- undefined,
201
- { env: undefined }
202
- );
203
-
204
- expect(config.account_id).toBeUndefined();
205
- expect(diagnostics.hasErrors()).toBe(false);
206
- expect(diagnostics.hasWarnings()).toBe(true);
207
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
208
- "Processing wrangler configuration:
209
- - The \\"account_id\\" field in your configuration is an empty string and will be ignored.
210
- Please remove the \\"account_id\\" field from your configuration."
211
- `);
212
- });
213
-
214
- describe("[migrations]", () => {
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
- { env: undefined }
236
- );
237
-
238
- expect(config).toEqual(expect.objectContaining(expectedConfig));
239
- expect(diagnostics.hasErrors()).toBe(false);
240
- expect(diagnostics.hasWarnings()).toBe(false);
241
- });
242
-
243
- it("should error on invalid `migrations` values", () => {
244
- const expectedConfig = {
245
- migrations: [
246
- {
247
- tag: 111,
248
- new_classes: [222, 333],
249
- renamed_classes: [
250
- {
251
- from: 444,
252
- to: 555,
253
- },
254
- ],
255
- deleted_classes: [666, 777],
256
- },
257
- ],
258
- };
259
-
260
- const { config, diagnostics } = normalizeAndValidateConfig(
261
- expectedConfig as unknown as RawConfig,
262
- undefined,
263
- { env: undefined }
264
- );
265
-
266
- expect(config).toEqual(expect.objectContaining(expectedConfig));
267
- expect(diagnostics.hasWarnings()).toBe(false);
268
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
269
- "Processing wrangler configuration:
270
- - Expected \\"migrations[0].tag\\" to be of type string but got 111.
271
- - Expected \\"migrations[0].new_classes.[0]\\" to be of type string but got 222.
272
- - Expected \\"migrations[0].new_classes.[1]\\" to be of type string but got 333.
273
- - Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
274
- - Expected \\"migrations[0].deleted_classes.[0]\\" to be of type string but got 666.
275
- - Expected \\"migrations[0].deleted_classes.[1]\\" to be of type string but got 777."
276
- `);
277
- });
278
-
279
- it("should warn/error on unexpected fields on `migrations`", async () => {
280
- const expectedConfig = {
281
- migrations: [
282
- {
283
- tag: "TAG",
284
- new_classes: ["CLASS_1", "CLASS_2"],
285
- renamed_classes: [
286
- {
287
- from: "FROM_CLASS",
288
- to: "TO_CLASS",
289
- },
290
- {
291
- a: "something",
292
- b: "someone",
293
- },
294
- ],
295
- deleted_classes: ["CLASS_3", "CLASS_4"],
296
- unrecognized_field: "FOO",
297
- },
298
- ],
299
- };
300
-
301
- const { config, diagnostics } = normalizeAndValidateConfig(
302
- expectedConfig as unknown as RawConfig,
303
- undefined,
304
- { env: undefined }
305
- );
306
-
307
- expect(config).toEqual(expect.objectContaining(expectedConfig));
308
- expect(diagnostics.hasErrors()).toBe(true);
309
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
310
- "Processing wrangler configuration:
311
- - Unexpected fields found in migrations field: \\"unrecognized_field\\""
312
- `);
313
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
314
- "Processing wrangler configuration:
315
- - 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\\"}]."
316
- `);
317
- });
318
- });
319
-
320
- describe("[site]", () => {
321
- it("should override `site` config defaults with provided values", () => {
322
- const expectedConfig: RawConfig = {
323
- site: {
324
- bucket: "BUCKET",
325
- "entry-point": "my-site",
326
- exclude: ["EXCLUDE_1", "EXCLUDE_2"],
327
- include: ["INCLUDE_1", "INCLUDE_2"],
328
- },
329
- };
330
-
331
- const { config, diagnostics } = normalizeAndValidateConfig(
332
- expectedConfig,
333
- undefined,
334
- { env: undefined }
335
- );
336
-
337
- expect(config).toEqual(expect.objectContaining(expectedConfig));
338
- expect(diagnostics.hasErrors()).toBe(false);
339
- expect(diagnostics.hasWarnings()).toBe(true);
340
-
341
- expect(normalizeSlashes(diagnostics.renderWarnings()))
342
- .toMatchInlineSnapshot(`
343
- "Processing wrangler configuration:
344
- - Deprecation: \\"site.entry-point\\":
345
- Delete the \`site.entry-point\` field, then add the top level \`main\` field to your configuration file:
346
- \`\`\`
347
- main = \\"my-site/index.js\\"
348
- \`\`\`"
349
- `);
350
- });
351
-
352
- it("should error if `site` config is missing `bucket`", () => {
353
- const expectedConfig: RawConfig = {
354
- // @ts-expect-error we're intentionally passing an invalid configuration here
355
- site: {
356
- "entry-point": "workers-site",
357
- include: ["INCLUDE_1", "INCLUDE_2"],
358
- exclude: ["EXCLUDE_1", "EXCLUDE_2"],
359
- },
360
- };
361
-
362
- const { config, diagnostics } = normalizeAndValidateConfig(
363
- expectedConfig,
364
- undefined,
365
- { env: undefined }
366
- );
367
-
368
- expect(config).toEqual(expect.objectContaining(expectedConfig));
369
- expect(diagnostics.hasWarnings()).toBe(true);
370
- expect(diagnostics.hasErrors()).toBe(true);
371
-
372
- expect(normalizeSlashes(diagnostics.renderWarnings()))
373
- .toMatchInlineSnapshot(`
374
- "Processing wrangler configuration:
375
- - Deprecation: \\"site.entry-point\\":
376
- Delete the \`site.entry-point\` field, then add the top level \`main\` field to your configuration file:
377
- \`\`\`
378
- main = \\"workers-site/index.js\\"
379
- \`\`\`"
380
- `);
381
-
382
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
383
- "Processing wrangler configuration:
384
- - \\"site.bucket\\" is a required field."
385
- `);
386
- });
387
-
388
- it("should error on invalid `site` values", () => {
389
- const expectedConfig = {
390
- site: {
391
- bucket: "BUCKET",
392
- "entry-point": 111,
393
- include: [222, 333],
394
- exclude: [444, 555],
395
- },
396
- };
397
-
398
- const { config, diagnostics } = normalizeAndValidateConfig(
399
- expectedConfig as unknown as RawConfig,
400
- undefined,
401
- { env: undefined }
402
- );
403
-
404
- expect(config).toEqual(expect.objectContaining(expectedConfig));
405
- expect(diagnostics.hasWarnings()).toBe(true);
406
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
407
- "Processing wrangler configuration:
408
- - Expected \\"sites.include.[0]\\" to be of type string but got 222.
409
- - Expected \\"sites.include.[1]\\" to be of type string but got 333.
410
- - Expected \\"sites.exclude.[0]\\" to be of type string but got 444.
411
- - Expected \\"sites.exclude.[1]\\" to be of type string but got 555.
412
- - Expected \\"site.entry-point\\" to be of type string but got 111."
413
- `);
414
-
415
- expect(normalizeSlashes(diagnostics.renderWarnings()))
416
- .toMatchInlineSnapshot(`
417
- "Processing wrangler configuration:
418
- - Deprecation: \\"site.entry-point\\":
419
- Delete the \`site.entry-point\` field, then add the top level \`main\` field to your configuration file:
420
- \`\`\`
421
- main = \\"111/index.js\\"
422
- \`\`\`"
423
- `);
424
- });
425
-
426
- it("should log a deprecation warning if entry-point is defined", async () => {
427
- const { config, diagnostics } = normalizeAndValidateConfig(
428
- {
429
- site: {
430
- bucket: "some/path",
431
- "entry-point": "some/other/script.js",
432
- },
433
- } as unknown as RawConfig,
434
- undefined,
435
- { env: undefined }
436
- );
437
-
438
- expect(config.site).toMatchInlineSnapshot(`
439
- Object {
440
- "bucket": "some/path",
441
- "entry-point": "some/other/script.js",
442
- "exclude": Array [],
443
- "include": Array [],
444
- }
445
- `);
446
- expect(diagnostics.hasWarnings()).toBe(true);
447
- expect(diagnostics.hasErrors()).toBe(false);
448
-
449
- expect(normalizeSlashes(diagnostics.renderWarnings()))
450
- .toMatchInlineSnapshot(`
451
- "Processing wrangler configuration:
452
- - Deprecation: \\"site.entry-point\\":
453
- Delete the \`site.entry-point\` field, then add the top level \`main\` field to your configuration file:
454
- \`\`\`
455
- main = \\"some/other/script.js\\"
456
- \`\`\`"
457
- `);
458
- });
459
- });
460
-
461
- describe("[assets]", () => {
462
- it("should error if `assets` config is missing `bucket`", () => {
463
- const expectedConfig: RawConfig = {
464
- // @ts-expect-error we're intentionally passing an invalid configuration here
465
- assets: {
466
- include: ["INCLUDE_1", "INCLUDE_2"],
467
- exclude: ["EXCLUDE_1", "EXCLUDE_2"],
468
- },
469
- };
470
-
471
- const { config, diagnostics } = normalizeAndValidateConfig(
472
- expectedConfig,
473
- undefined,
474
- { env: undefined }
475
- );
476
-
477
- expect(config).toEqual(expect.objectContaining(expectedConfig));
478
- expect(diagnostics.hasWarnings()).toBe(true);
479
- expect(diagnostics.hasErrors()).toBe(true);
480
-
481
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
482
- "Processing wrangler configuration:
483
- - \\"assets\\" fields are experimental and may change or break at any time."
484
- `);
485
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
486
- "Processing wrangler configuration:
487
- - \\"assets.bucket\\" is a required field."
488
- `);
489
- });
490
-
491
- it("should error on invalid `assets` values", () => {
492
- const expectedConfig = {
493
- assets: {
494
- bucket: "BUCKET",
495
- include: [222, 333],
496
- exclude: [444, 555],
497
- },
498
- };
499
-
500
- const { config, diagnostics } = normalizeAndValidateConfig(
501
- expectedConfig as unknown as RawConfig,
502
- undefined,
503
- { env: undefined }
504
- );
505
-
506
- expect(config).toEqual(expect.objectContaining(expectedConfig));
507
- expect(diagnostics.hasWarnings()).toBe(true);
508
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
509
- "Processing wrangler configuration:
510
- - \\"assets\\" fields are experimental and may change or break at any time."
511
- `);
512
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
513
- "Processing wrangler configuration:
514
- - Expected \\"assets.include.[0]\\" to be of type string but got 222.
515
- - Expected \\"assets.include.[1]\\" to be of type string but got 333.
516
- - Expected \\"assets.exclude.[0]\\" to be of type string but got 444.
517
- - Expected \\"assets.exclude.[1]\\" to be of type string but got 555."
518
- `);
519
- });
520
- });
521
-
522
- it("should map `wasm_module` paths from relative to the config path to relative to the cwd", () => {
523
- const expectedConfig: RawConfig = {
524
- wasm_modules: {
525
- MODULE_1: "path/to/module_1.mjs",
526
- MODULE_2: "module_2.mjs",
527
- },
528
- };
529
-
530
- const { config, diagnostics } = normalizeAndValidateConfig(
531
- expectedConfig,
532
- "project/wrangler.toml",
533
- { env: undefined }
534
- );
535
-
536
- expect(config).toEqual(
537
- expect.objectContaining({
538
- wasm_modules: {
539
- MODULE_1: path.normalize("project/path/to/module_1.mjs"),
540
- MODULE_2: path.normalize("project/module_2.mjs"),
541
- },
542
- })
543
- );
544
- expect(diagnostics.hasErrors()).toBe(false);
545
- expect(diagnostics.hasWarnings()).toBe(false);
546
- });
547
-
548
- it("should warn on unexpected fields on `triggers`", async () => {
549
- const expectedConfig: RawConfig = {
550
- triggers: {
551
- crons: ["1 * * * *"],
552
- // @ts-expect-error we're purposely adding a field
553
- // that doesn't belong here
554
- someOtherfield: 123,
555
- },
556
- };
557
-
558
- const { config, diagnostics } = normalizeAndValidateConfig(
559
- expectedConfig,
560
- "project/wrangler.toml",
561
- { env: undefined }
562
- );
563
-
564
- expect(config).toEqual(
565
- expect.objectContaining({
566
- triggers: {
567
- crons: ["1 * * * *"],
568
- someOtherfield: 123,
569
- },
570
- })
571
- );
572
- expect(diagnostics.hasErrors()).toBe(false);
573
- expect(diagnostics.hasWarnings()).toBe(true);
574
-
575
- expect(normalizePath(diagnostics.renderWarnings()))
576
- .toMatchInlineSnapshot(`
577
- "Processing project/wrangler.toml configuration:
578
- - Unexpected fields found in triggers field: \\"someOtherfield\\""
579
- `);
580
- });
581
-
582
- it("should error on invalid `wasm_modules` paths", () => {
583
- const expectedConfig = {
584
- wasm_modules: {
585
- MODULE_1: 111,
586
- MODULE_2: 222,
587
- },
588
- };
589
-
590
- const { config, diagnostics } = normalizeAndValidateConfig(
591
- expectedConfig as unknown as RawConfig,
592
- "project/wrangler.toml",
593
- { env: undefined }
594
- );
595
-
596
- expect(config).toEqual(
597
- expect.objectContaining({
598
- wasm_modules: {},
599
- })
600
- );
601
- expect(diagnostics.hasWarnings()).toBe(false);
602
- expect(normalizePath(diagnostics.renderErrors())).toMatchInlineSnapshot(`
603
- "Processing project/wrangler.toml configuration:
604
- - Expected \\"wasm_modules['MODULE_1']\\" to be of type string but got 111.
605
- - Expected \\"wasm_modules['MODULE_2']\\" to be of type string but got 222."
606
- `);
607
- });
608
-
609
- it("should map `text_blobs` paths from relative to the config path to relative to the cwd", () => {
610
- const expectedConfig: RawConfig = {
611
- text_blobs: {
612
- BLOB_1: "path/to/text1.txt",
613
- BLOB_2: "text2.md",
614
- },
615
- };
616
-
617
- const { config, diagnostics } = normalizeAndValidateConfig(
618
- expectedConfig,
619
- "project/wrangler.toml",
620
- { env: undefined }
621
- );
622
-
623
- expect(config).toEqual(
624
- expect.objectContaining({
625
- text_blobs: {
626
- BLOB_1: path.normalize("project/path/to/text1.txt"),
627
- BLOB_2: path.normalize("project/text2.md"),
628
- },
629
- })
630
- );
631
- expect(diagnostics.hasErrors()).toBe(false);
632
- expect(diagnostics.hasWarnings()).toBe(false);
633
- });
634
-
635
- it("should error on invalid `text_blob` paths", () => {
636
- const expectedConfig = {
637
- text_blobs: {
638
- MODULE_1: 111,
639
- MODULE_2: 222,
640
- },
641
- };
642
-
643
- const { config, diagnostics } = normalizeAndValidateConfig(
644
- expectedConfig as unknown as RawConfig,
645
- "project/wrangler.toml",
646
- { env: undefined }
647
- );
648
-
649
- expect(config).toEqual(
650
- expect.objectContaining({
651
- text_blobs: {},
652
- })
653
- );
654
- expect(diagnostics.hasWarnings()).toBe(false);
655
- expect(normalizePath(diagnostics.renderErrors())).toMatchInlineSnapshot(`
656
- "Processing project/wrangler.toml configuration:
657
- - Expected \\"text_blobs['MODULE_1']\\" to be of type string but got 111.
658
- - Expected \\"text_blobs['MODULE_2']\\" to be of type string but got 222."
659
- `);
660
- });
661
-
662
- it("should map `data_blobs` paths from relative to the config path to relative to the cwd", () => {
663
- const expectedConfig: RawConfig = {
664
- data_blobs: {
665
- BLOB_1: "path/to/data1.bin",
666
- BLOB_2: "data2.bin",
667
- },
668
- };
669
-
670
- const { config, diagnostics } = normalizeAndValidateConfig(
671
- expectedConfig,
672
- "project/wrangler.toml",
673
- { env: undefined }
674
- );
675
-
676
- expect(config).toEqual(
677
- expect.objectContaining({
678
- data_blobs: {
679
- BLOB_1: path.normalize("project/path/to/data1.bin"),
680
- BLOB_2: path.normalize("project/data2.bin"),
681
- },
682
- })
683
- );
684
- expect(diagnostics.hasErrors()).toBe(false);
685
- expect(diagnostics.hasWarnings()).toBe(false);
686
- });
687
-
688
- it("should error on invalid `data_blob` paths", () => {
689
- const expectedConfig = {
690
- data_blobs: {
691
- MODULE_1: 111,
692
- MODULE_2: 222,
693
- },
694
- };
695
-
696
- const { config, diagnostics } = normalizeAndValidateConfig(
697
- expectedConfig as unknown as RawConfig,
698
- "project/wrangler.toml",
699
- { env: undefined }
700
- );
701
-
702
- expect(config).toEqual(
703
- expect.objectContaining({
704
- data_blobs: {},
705
- })
706
- );
707
- expect(diagnostics.hasWarnings()).toBe(false);
708
- expect(normalizePath(diagnostics.renderErrors())).toMatchInlineSnapshot(`
709
- "Processing project/wrangler.toml configuration:
710
- - Expected \\"data_blobs['MODULE_1']\\" to be of type string but got 111.
711
- - Expected \\"data_blobs['MODULE_2']\\" to be of type string but got 222."
712
- `);
713
- });
714
-
715
- it("should resolve tsconfig relative to wrangler.toml", async () => {
716
- const expectedConfig: RawEnvironment = {
717
- tsconfig: "path/to/some-tsconfig.json",
718
- };
719
-
720
- const { config, diagnostics } = normalizeAndValidateConfig(
721
- expectedConfig,
722
- "project/wrangler.toml",
723
- { env: undefined }
724
- );
725
-
726
- expect(config).toEqual(
727
- expect.objectContaining({
728
- tsconfig: path.normalize("project/path/to/some-tsconfig.json"),
729
- })
730
- );
731
-
732
- expect(diagnostics.hasErrors()).toBe(false);
733
- expect(diagnostics.hasWarnings()).toBe(false);
734
- });
735
-
736
- describe("(deprecated)", () => {
737
- it("should remove and warn about deprecated properties", () => {
738
- const rawConfig: RawConfig = {
739
- type: "webpack",
740
- webpack_config: "CONFIG",
741
- };
742
-
743
- const { config, diagnostics } = normalizeAndValidateConfig(
744
- rawConfig,
745
- undefined,
746
- { env: undefined }
747
- );
748
-
749
- // Note the `.not.` here...
750
- expect(config).toEqual(
751
- expect.not.objectContaining({
752
- type: expect.anything(),
753
- webpack_config: expect.anything(),
754
- })
755
- );
756
- expect(diagnostics.hasErrors()).toBe(false);
757
- expect(diagnostics.hasWarnings()).toBe(true);
758
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
759
- "Processing wrangler configuration:
760
- - 😶 Ignored: \\"type\\":
761
- 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.
762
- - 😶 Ignored: \\"webpack_config\\":
763
- 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."
764
- `);
765
- });
766
- });
767
- });
768
-
769
- describe("top-level environment configuration", () => {
770
- it("should override config defaults with provided values", () => {
771
- const main = "src/index.ts";
772
- const resolvedMain = path.resolve(process.cwd(), main);
773
-
774
- const expectedConfig: RawEnvironment = {
775
- name: "mock-name",
776
- account_id: "ACCOUNT_ID",
777
- compatibility_date: "2022-01-01",
778
- compatibility_flags: ["FLAG1", "FLAG2"],
779
- workers_dev: false,
780
- routes: [
781
- "ROUTE_1",
782
- "ROUTE_2",
783
- { pattern: "ROUTE3", zone_id: "ZONE_ID_3" },
784
- "ROUTE_4",
785
- ],
786
- jsx_factory: "JSX_FACTORY",
787
- jsx_fragment: "JSX_FRAGMENT",
788
- tsconfig: "path/to/tsconfig",
789
- triggers: { crons: ["CRON_1", "CRON_2"] },
790
- usage_model: "bundled",
791
- main,
792
- build: {
793
- command: "COMMAND",
794
- cwd: "CWD",
795
- watch_dir: "WATCH_DIR",
796
- },
797
- define: {
798
- DEF1: "DEFINE_1",
799
- DEF2: "DEFINE_2",
800
- },
801
- vars: {
802
- VAR1: "VALUE_1",
803
- VAR2: "VALUE_2",
804
- },
805
- durable_objects: {
806
- bindings: [
807
- { name: "DO_BINDING_1", class_name: "CLASS1" },
808
- {
809
- name: "DO_BINDING_2",
810
- class_name: "CLASS2",
811
- script_name: "SCRIPT2",
812
- },
813
- {
814
- name: "DO_BINDING_3",
815
- class_name: "CLASS3",
816
- script_name: "SCRIPT3",
817
- environment: "ENV3",
818
- },
819
- ],
820
- },
821
- kv_namespaces: [
822
- { binding: "KV_BINDING_1", id: "KV_ID_1" },
823
- {
824
- binding: "KV_BINDING_2",
825
- id: "KV_ID_2",
826
- preview_id: "KV_PREVIEW_1",
827
- },
828
- ],
829
- r2_buckets: [
830
- { binding: "R2_BINDING_1", bucket_name: "R2_BUCKET_1" },
831
- {
832
- binding: "R2_BINDING_2",
833
- bucket_name: "R2_BUCKET_2",
834
- preview_bucket_name: "R2_PREVIEW_2",
835
- },
836
- ],
837
- services: [
838
- {
839
- binding: "SERVICE_BINDING_1",
840
- service: "SERVICE_TYPE_1",
841
- environment: "SERVICE_BINDING_ENVIRONMENT_1",
842
- },
843
- ],
844
- unsafe: {
845
- bindings: [
846
- { name: "UNSAFE_BINDING_1", type: "UNSAFE_TYPE_1" },
847
- {
848
- name: "UNSAFE_BINDING_2",
849
- type: "UNSAFE_TYPE_2",
850
- extra: "UNSAFE_EXTRA_1",
851
- },
852
- ],
853
- },
854
- no_bundle: true,
855
- minify: true,
856
- node_compat: true,
857
- };
858
-
859
- const { config, diagnostics } = normalizeAndValidateConfig(
860
- expectedConfig,
861
- undefined,
862
- { env: undefined }
863
- );
864
-
865
- expect(config).toEqual(
866
- expect.objectContaining({ ...expectedConfig, main: resolvedMain })
867
- );
868
- expect(diagnostics.hasErrors()).toBe(false);
869
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
870
- "Processing wrangler configuration:
871
- - \\"unsafe\\" fields are experimental and may change or break at any time.
872
- - \\"services\\" fields are experimental and may change or break at any time.
873
- - 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:
874
-
875
- \`\`\`
876
- [[migrations]]
877
- tag = \\"v1\\" # Should be unique for each entry
878
- new_classes = [\\"CLASS1\\"]
879
- \`\`\`
880
-
881
- Refer to https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml for more details."
882
- `);
883
- });
884
-
885
- it("should error on invalid environment values", () => {
886
- const expectedConfig: RawEnvironment = {
887
- name: 111,
888
- account_id: 222,
889
- compatibility_date: 333,
890
- compatibility_flags: [444, 555],
891
- workers_dev: "BAD",
892
- routes: [
893
- 666,
894
- 777,
895
- // this one's valid, but we add it here to make sure
896
- // it doesn't get included in the error message
897
- "example.com/*",
898
- { pattern: 123, zone_id: "zone_id_1" },
899
- { pattern: "route_2", zone_id: 123 },
900
- { pattern: "route_2", zone_name: 123 },
901
- { pattern: "route_3" },
902
- { zone_id: "zone_id_4" },
903
- { zone_name: "zone_name_4" },
904
- { pattern: undefined },
905
- { pattern: "route_5", zone_id: "zone_id_5", some_other_key: 123 },
906
- { pattern: "route_5", zone_name: "zone_name_5", some_other_key: 123 },
907
- // this one's valid too
908
- { pattern: "route_6", zone_id: "zone_id_6" },
909
- // as well as this one
910
- { pattern: "route_6", zone_name: "zone_name_6" },
911
- ],
912
- route: 888,
913
- jsx_factory: 999,
914
- jsx_fragment: 1000,
915
- tsconfig: true,
916
- triggers: { crons: [1111, 1222] },
917
- usage_model: "INVALID",
918
- main: 1333,
919
- build: {
920
- command: 1444,
921
- cwd: 1555,
922
- watch_dir: 1666,
923
- },
924
- define: {
925
- DEF1: 1777,
926
- },
927
- no_bundle: "INVALID",
928
- minify: "INVALID",
929
- node_compat: "INVALID",
930
- } as unknown as RawEnvironment;
931
-
932
- const { config, diagnostics } = normalizeAndValidateConfig(
933
- expectedConfig,
934
- undefined,
935
- { env: undefined }
936
- );
937
-
938
- expect(config).toEqual(expect.objectContaining(expectedConfig));
939
- expect(diagnostics.hasWarnings()).toBe(false);
940
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
941
- "Processing wrangler configuration:
942
- - Expected \\"route\\" to be either a string, or an object with shape { pattern, custom_domain, zone_id | zone_name }, but got 888.
943
- - Expected \\"account_id\\" to be of type string but got 222.
944
- - 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: [
945
- 666,
946
- 777,
947
- {
948
- \\"pattern\\": 123,
949
- \\"zone_id\\": \\"zone_id_1\\"
950
- },
951
- {
952
- \\"pattern\\": \\"route_2\\",
953
- \\"zone_id\\": 123
954
- },
955
- {
956
- \\"pattern\\": \\"route_2\\",
957
- \\"zone_name\\": 123
958
- },
959
- {
960
- \\"pattern\\": \\"route_3\\"
961
- },
962
- {
963
- \\"zone_id\\": \\"zone_id_4\\"
964
- },
965
- {
966
- \\"zone_name\\": \\"zone_name_4\\"
967
- },
968
- {},
969
- {
970
- \\"pattern\\": \\"route_5\\",
971
- \\"zone_id\\": \\"zone_id_5\\",
972
- \\"some_other_key\\": 123
973
- },
974
- {
975
- \\"pattern\\": \\"route_5\\",
976
- \\"zone_name\\": \\"zone_name_5\\",
977
- \\"some_other_key\\": 123
978
- }
979
- ].
980
- - Expected exactly one of the following fields [\\"routes\\",\\"route\\"].
981
- - Expected \\"workers_dev\\" to be of type boolean but got \\"BAD\\".
982
- - Expected \\"build.command\\" to be of type string but got 1444.
983
- - Expected \\"build.cwd\\" to be of type string but got 1555.
984
- - Expected \\"build.watch_dir\\" to be of type string but got 1666.
985
- - Expected \\"compatibility_date\\" to be of type string but got 333.
986
- - Expected \\"compatibility_flags\\" to be of type string array but got [444,555].
987
- - Expected \\"jsx_factory\\" to be of type string but got 999.
988
- - Expected \\"jsx_fragment\\" to be of type string but got 1000.
989
- - Expected \\"tsconfig\\" to be of type string but got true.
990
- - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got 111.
991
- - Expected \\"main\\" to be of type string but got 1333.
992
- - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\".
993
- - The field \\"define.DEF1\\" should be a string but got 1777.
994
- - Expected \\"no_bundle\\" to be of type boolean but got \\"INVALID\\".
995
- - Expected \\"minify\\" to be of type boolean but got \\"INVALID\\".
996
- - Expected \\"node_compat\\" to be of type boolean but got \\"INVALID\\"."
997
- `);
998
- });
999
-
1000
- describe("name", () => {
1001
- it("should error on invalid `name` value with spaces", () => {
1002
- const expectedConfig: RawEnvironment = {
1003
- name: "NCC 1701 D",
1004
- } as unknown as RawEnvironment;
1005
-
1006
- const { config, diagnostics } = normalizeAndValidateConfig(
1007
- expectedConfig,
1008
- undefined,
1009
- { env: undefined }
1010
- );
1011
-
1012
- expect(config).toEqual(expect.objectContaining(expectedConfig));
1013
- expect(diagnostics.hasWarnings()).toBe(false);
1014
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1015
- "Processing wrangler configuration:
1016
- - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"NCC 1701 D\\"."
1017
- `);
1018
- });
1019
-
1020
- it("should be valid `name` with underscores", () => {
1021
- const expectedConfig: RawEnvironment = {
1022
- name: "enterprise_nx_01",
1023
- } as unknown as RawEnvironment;
1024
-
1025
- const { config, diagnostics } = normalizeAndValidateConfig(
1026
- expectedConfig,
1027
- undefined,
1028
- { env: undefined }
1029
- );
1030
-
1031
- expect(config).toEqual(expect.objectContaining(expectedConfig));
1032
- expect(diagnostics.hasWarnings()).toBe(false);
1033
- expect(diagnostics.hasErrors()).toBe(false);
1034
- });
1035
-
1036
- it("should error on invalid `name` value with special characters", () => {
1037
- const expectedConfig: RawEnvironment = {
1038
- name: "Thy'lek-Shran",
1039
- } as unknown as RawEnvironment;
1040
-
1041
- const { config, diagnostics } = normalizeAndValidateConfig(
1042
- expectedConfig,
1043
- undefined,
1044
- { env: undefined }
1045
- );
1046
-
1047
- expect(config).toEqual(expect.objectContaining(expectedConfig));
1048
- expect(diagnostics.hasWarnings()).toBe(false);
1049
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1050
- "Processing wrangler configuration:
1051
- - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"Thy'lek-Shran\\"."
1052
- `);
1053
- });
1054
-
1055
- it("should error on invalid `name` value with only special characters", () => {
1056
- const expectedConfig: RawEnvironment = {
1057
- name: "!@#$%^&*(()",
1058
- } as unknown as RawEnvironment;
1059
-
1060
- const { config, diagnostics } = normalizeAndValidateConfig(
1061
- expectedConfig,
1062
- undefined,
1063
- { env: undefined }
1064
- );
1065
-
1066
- expect(config).toEqual(expect.objectContaining(expectedConfig));
1067
- expect(diagnostics.hasWarnings()).toBe(false);
1068
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1069
- "Processing wrangler configuration:
1070
- - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"!@#$%^&*(()\\"."
1071
- `);
1072
- });
1073
- });
1074
-
1075
- describe("[build]", () => {
1076
- it("should override build.upload config defaults with provided values and warn about deprecations", () => {
1077
- const expectedConfig: RawEnvironment = {
1078
- build: {
1079
- upload: {
1080
- dir: "src",
1081
- format: "modules",
1082
- main: "index.ts",
1083
- rules: [{ type: "Text", globs: ["GLOB"], fallthrough: true }],
1084
- },
1085
- },
1086
- };
1087
-
1088
- const { config, diagnostics } = normalizeAndValidateConfig(
1089
- expectedConfig,
1090
- path.resolve("project/wrangler.toml"),
1091
- { env: undefined }
1092
- );
1093
-
1094
- expect(config.main).toEqual(path.resolve("project/src/index.ts"));
1095
- expect(config.build.upload).toBeUndefined();
1096
- expect(diagnostics.hasErrors()).toBe(false);
1097
- expect(diagnostics.hasWarnings()).toBe(true);
1098
- expect(normalizePath(diagnostics.renderWarnings()))
1099
- .toMatchInlineSnapshot(`
1100
- "Processing project/wrangler.toml configuration:
1101
- - Deprecation: \\"build.upload.format\\":
1102
- The format is inferred automatically from the code.
1103
- - Deprecation: \\"build.upload.main\\":
1104
- Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
1105
- Then add the top level \`main\` field to your configuration file:
1106
- \`\`\`
1107
- main = \\"src/index.ts\\"
1108
- \`\`\`
1109
- - Deprecation: \\"build.upload.dir\\":
1110
- Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the Worker.
1111
- - 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:
1112
- \`\`\`
1113
- [[rules]]
1114
- type = \\"Text\\"
1115
- globs = [ \\"GLOB\\" ]
1116
- fallthrough = true
1117
- \`\`\`"
1118
- `);
1119
- });
1120
-
1121
- it("should default custom build watch directories to src", () => {
1122
- const expectedConfig: RawEnvironment = {
1123
- build: {
1124
- command: "execute some --build",
1125
- },
1126
- };
1127
-
1128
- const { config, diagnostics } = normalizeAndValidateConfig(
1129
- expectedConfig,
1130
- undefined,
1131
- { env: undefined }
1132
- );
1133
-
1134
- expect(config.build).toEqual(
1135
- expect.objectContaining({
1136
- command: "execute some --build",
1137
- watch_dir: "./src",
1138
- })
1139
- );
1140
-
1141
- expect(diagnostics.hasErrors()).toBe(false);
1142
- expect(diagnostics.hasWarnings()).toBe(false);
1143
- });
1144
-
1145
- it("should resolve custom build watch directories relative to wrangler.toml", async () => {
1146
- const expectedConfig: RawEnvironment = {
1147
- build: {
1148
- command: "execute some --build",
1149
- watch_dir: "some/path",
1150
- },
1151
- };
1152
-
1153
- const { config, diagnostics } = normalizeAndValidateConfig(
1154
- expectedConfig,
1155
- "project/wrangler.toml",
1156
- { env: undefined }
1157
- );
1158
-
1159
- expect(config.build).toEqual(
1160
- expect.objectContaining({
1161
- command: "execute some --build",
1162
- watch_dir: path.normalize("project/some/path"),
1163
- })
1164
- );
1165
-
1166
- expect(diagnostics.hasErrors()).toBe(false);
1167
- expect(diagnostics.hasWarnings()).toBe(false);
1168
- });
1169
-
1170
- it("should allow watch_dir to be an array of paths", () => {
1171
- const expectedConfig: RawEnvironment = {
1172
- build: {
1173
- command: "execute some --build",
1174
- watch_dir: ["some/path/a", "some/path/b", "some/path/c"],
1175
- },
1176
- };
1177
-
1178
- const { config, diagnostics } = normalizeAndValidateConfig(
1179
- expectedConfig,
1180
- "project/wrangler.toml",
1181
- { env: undefined }
1182
- );
1183
-
1184
- expect(config.build).toEqual(
1185
- expect.objectContaining({
1186
- command: "execute some --build",
1187
- watch_dir: [
1188
- path.normalize("project/some/path/a"),
1189
- path.normalize("project/some/path/b"),
1190
- path.normalize("project/some/path/c"),
1191
- ],
1192
- })
1193
- );
1194
-
1195
- expect(diagnostics.hasErrors()).toBe(false);
1196
- expect(diagnostics.hasWarnings()).toBe(false);
1197
- });
1198
-
1199
- it("should error when the watch_dir array isn't an array of strings", () => {
1200
- const expectedConfig: RawEnvironment = {
1201
- build: {
1202
- command: "execute some --build",
1203
- watch_dir: [
1204
- "some/path/a",
1205
- "some/path/b",
1206
- // @ts-expect-error intentionally bad "paths"
1207
- 123,
1208
- "some/path/c",
1209
- // @ts-expect-error intentionally bad "paths"
1210
- false,
1211
- ],
1212
- },
1213
- };
1214
-
1215
- const { config, diagnostics } = normalizeAndValidateConfig(
1216
- expectedConfig,
1217
- "project/wrangler.toml",
1218
- { env: undefined }
1219
- );
1220
-
1221
- expect(config.build).toEqual(
1222
- expect.objectContaining({
1223
- command: "execute some --build",
1224
- watch_dir: [
1225
- path.normalize("project/some/path/a"),
1226
- path.normalize("project/some/path/b"),
1227
- path.normalize("project/123"),
1228
- path.normalize("project/some/path/c"),
1229
- path.normalize("project/false"),
1230
- ],
1231
- })
1232
- );
1233
-
1234
- expect(diagnostics.hasWarnings()).toBe(false);
1235
- expect(diagnostics.hasErrors()).toBe(true);
1236
-
1237
- expect(normalizePath(diagnostics.renderErrors()))
1238
- .toMatchInlineSnapshot(`
1239
- "Processing project/wrangler.toml configuration:
1240
- - Expected \\"build.watch_dir.[2]\\" to be of type string but got 123.
1241
- - Expected \\"build.watch_dir.[4]\\" to be of type string but got false."
1242
- `);
1243
- });
1244
- });
1245
-
1246
- describe("[durable_objects]", () => {
1247
- it("should error if durable_objects is an array", () => {
1248
- const { config, diagnostics } = normalizeAndValidateConfig(
1249
- { durable_objects: [] } as unknown as RawConfig,
1250
- undefined,
1251
- { env: undefined }
1252
- );
1253
-
1254
- expect(config).toEqual(
1255
- expect.not.objectContaining({ durable_objects: expect.anything })
1256
- );
1257
- expect(diagnostics.hasWarnings()).toBe(false);
1258
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1259
- "Processing wrangler configuration:
1260
- - The field \\"durable_objects\\" should be an object but got []."
1261
- `);
1262
- });
1263
-
1264
- it("should error if durable_objects is a string", () => {
1265
- const { config, diagnostics } = normalizeAndValidateConfig(
1266
- { durable_objects: "BAD" } as unknown as RawConfig,
1267
- undefined,
1268
- { env: undefined }
1269
- );
1270
-
1271
- expect(config).toEqual(
1272
- expect.not.objectContaining({ durable_objects: expect.anything })
1273
- );
1274
- expect(diagnostics.hasWarnings()).toBe(false);
1275
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1276
- "Processing wrangler configuration:
1277
- - The field \\"durable_objects\\" should be an object but got \\"BAD\\"."
1278
- `);
1279
- });
1280
-
1281
- it("should error if durable_objects is a number", () => {
1282
- const { config, diagnostics } = normalizeAndValidateConfig(
1283
- { durable_objects: 999 } as unknown as RawConfig,
1284
- undefined,
1285
- { env: undefined }
1286
- );
1287
-
1288
- expect(config).toEqual(
1289
- expect.not.objectContaining({ durable_objects: expect.anything })
1290
- );
1291
- expect(diagnostics.hasWarnings()).toBe(false);
1292
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1293
- "Processing wrangler configuration:
1294
- - The field \\"durable_objects\\" should be an object but got 999."
1295
- `);
1296
- });
1297
-
1298
- it("should error if durable_objects is null", () => {
1299
- const { config, diagnostics } = normalizeAndValidateConfig(
1300
- { durable_objects: null } as unknown as RawConfig,
1301
- undefined,
1302
- { env: undefined }
1303
- );
1304
-
1305
- expect(config).toEqual(
1306
- expect.not.objectContaining({ durable_objects: expect.anything })
1307
- );
1308
- expect(diagnostics.hasWarnings()).toBe(false);
1309
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1310
- "Processing wrangler configuration:
1311
- - The field \\"durable_objects\\" should be an object but got null."
1312
- `);
1313
- });
1314
-
1315
- it("should error if durable_objects.bindings is not defined", () => {
1316
- const { config, diagnostics } = normalizeAndValidateConfig(
1317
- { durable_objects: {} } as unknown as RawConfig,
1318
- undefined,
1319
- { env: undefined }
1320
- );
1321
-
1322
- expect(config).toEqual(
1323
- expect.not.objectContaining({ durable_objects: expect.anything })
1324
- );
1325
- expect(diagnostics.hasWarnings()).toBe(false);
1326
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1327
- "Processing wrangler configuration:
1328
- - The field \\"durable_objects\\" is missing the required \\"bindings\\" property."
1329
- `);
1330
- });
1331
-
1332
- it("should error if durable_objects.bindings is an object", () => {
1333
- const { config, diagnostics } = normalizeAndValidateConfig(
1334
- { durable_objects: { bindings: {} } } as unknown as RawConfig,
1335
- undefined,
1336
- { env: undefined }
1337
- );
1338
-
1339
- expect(config).toEqual(
1340
- expect.not.objectContaining({
1341
- durable_objects: { bindings: expect.anything },
1342
- })
1343
- );
1344
- expect(diagnostics.hasWarnings()).toBe(false);
1345
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1346
- "Processing wrangler configuration:
1347
- - The field \\"durable_objects.bindings\\" should be an array but got {}."
1348
- `);
1349
- });
1350
-
1351
- it("should error if durable_objects.bindings is a string", () => {
1352
- const { config, diagnostics } = normalizeAndValidateConfig(
1353
- { durable_objects: { bindings: "BAD" } } as unknown as RawConfig,
1354
- undefined,
1355
- { env: undefined }
1356
- );
1357
-
1358
- expect(config).toEqual(
1359
- expect.not.objectContaining({
1360
- durable_objects: { bindings: expect.anything },
1361
- })
1362
- );
1363
- expect(diagnostics.hasWarnings()).toBe(false);
1364
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1365
- "Processing wrangler configuration:
1366
- - The field \\"durable_objects.bindings\\" should be an array but got \\"BAD\\"."
1367
- `);
1368
- });
1369
-
1370
- it("should error if durable_objects.bindings is a number", () => {
1371
- const { config, diagnostics } = normalizeAndValidateConfig(
1372
- { durable_objects: { bindings: 999 } } as unknown as RawConfig,
1373
- undefined,
1374
- { env: undefined }
1375
- );
1376
-
1377
- expect(config).toEqual(
1378
- expect.not.objectContaining({
1379
- durable_objects: { bindings: expect.anything },
1380
- })
1381
- );
1382
- expect(diagnostics.hasWarnings()).toBe(false);
1383
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1384
- "Processing wrangler configuration:
1385
- - The field \\"durable_objects.bindings\\" should be an array but got 999."
1386
- `);
1387
- });
1388
-
1389
- it("should error if durable_objects.bindings is null", () => {
1390
- const { config, diagnostics } = normalizeAndValidateConfig(
1391
- { durable_objects: { bindings: null } } as unknown as RawConfig,
1392
- undefined,
1393
- { env: undefined }
1394
- );
1395
-
1396
- expect(config).toEqual(
1397
- expect.not.objectContaining({
1398
- durable_objects: { bindings: expect.anything },
1399
- })
1400
- );
1401
- expect(diagnostics.hasWarnings()).toBe(false);
1402
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1403
- "Processing wrangler configuration:
1404
- - The field \\"durable_objects.bindings\\" should be an array but got null."
1405
- `);
1406
- });
1407
-
1408
- it("should error if durable_objects.bindings are not valid", () => {
1409
- const { config, diagnostics } = normalizeAndValidateConfig(
1410
- {
1411
- durable_objects: {
1412
- bindings: [
1413
- {},
1414
- { name: "MISSING_CLASS" },
1415
- { name: 1555, class_name: 1666 },
1416
- {
1417
- name: 1777,
1418
- class_name: 1888,
1419
- script_name: 1999,
1420
- },
1421
- {
1422
- name: "SOMENAME",
1423
- class_name: "SomeClass",
1424
- environment: "staging",
1425
- },
1426
- {
1427
- name: 1778,
1428
- class_name: 1889,
1429
- script_name: 1992,
1430
- environment: 2111,
1431
- },
1432
- {
1433
- name: 1772,
1434
- class_name: 1883,
1435
- environment: 2112,
1436
- },
1437
- ],
1438
- },
1439
- } as unknown as RawConfig,
1440
- undefined,
1441
- { env: undefined }
1442
- );
1443
-
1444
- expect(config).toEqual(
1445
- expect.not.objectContaining({
1446
- durable_objects: { bindings: expect.anything },
1447
- })
1448
- );
1449
- expect(diagnostics.hasWarnings()).toBe(false);
1450
-
1451
- expect(diagnostics.hasErrors()).toBe(true);
1452
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1453
- "Processing wrangler configuration:
1454
-
1455
- - \\"durable_objects.bindings[0]\\": {}
1456
- - binding should have a string \\"name\\" field.
1457
- - binding should have a string \\"class_name\\" field.
1458
-
1459
- - \\"durable_objects.bindings[1]\\": {\\"name\\":\\"MISSING_CLASS\\"}
1460
- - binding should have a string \\"class_name\\" field.
1461
-
1462
- - \\"durable_objects.bindings[2]\\": {\\"name\\":1555,\\"class_name\\":1666}
1463
- - binding should have a string \\"name\\" field.
1464
- - binding should have a string \\"class_name\\" field.
1465
-
1466
- - \\"durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
1467
- - binding should have a string \\"name\\" field.
1468
- - binding should have a string \\"class_name\\" field.
1469
- - the field \\"script_name\\", when present, should be a string.
1470
-
1471
- - \\"durable_objects.bindings[4]\\": {\\"name\\":\\"SOMENAME\\",\\"class_name\\":\\"SomeClass\\",\\"environment\\":\\"staging\\"}
1472
- - binding should have a \\"script_name\\" field if \\"environment\\" is present.
1473
-
1474
- - \\"durable_objects.bindings[5]\\": {\\"name\\":1778,\\"class_name\\":1889,\\"script_name\\":1992,\\"environment\\":2111}
1475
- - binding should have a string \\"name\\" field.
1476
- - binding should have a string \\"class_name\\" field.
1477
- - the field \\"script_name\\", when present, should be a string.
1478
- - the field \\"environment\\", when present, should be a string.
1479
-
1480
- - \\"durable_objects.bindings[6]\\": {\\"name\\":1772,\\"class_name\\":1883,\\"environment\\":2112}
1481
- - binding should have a string \\"name\\" field.
1482
- - binding should have a string \\"class_name\\" field.
1483
- - the field \\"environment\\", when present, should be a string.
1484
- - binding should have a \\"script_name\\" field if \\"environment\\" is present."
1485
- `);
1486
- });
1487
- });
1488
-
1489
- describe("[kv_namespaces]", () => {
1490
- it("should error if kv_namespaces is an object", () => {
1491
- const { config, diagnostics } = normalizeAndValidateConfig(
1492
- { kv_namespaces: {} } as unknown as RawConfig,
1493
- undefined,
1494
- { env: undefined }
1495
- );
1496
-
1497
- expect(config).toEqual(
1498
- expect.not.objectContaining({ kv_namespaces: expect.anything })
1499
- );
1500
- expect(diagnostics.hasWarnings()).toBe(false);
1501
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1502
- "Processing wrangler configuration:
1503
- - The field \\"kv_namespaces\\" should be an array but got {}."
1504
- `);
1505
- });
1506
-
1507
- it("should error if kv_namespaces is a string", () => {
1508
- const { config, diagnostics } = normalizeAndValidateConfig(
1509
- { kv_namespaces: "BAD" } as unknown as RawConfig,
1510
- undefined,
1511
- { env: undefined }
1512
- );
1513
-
1514
- expect(config).toEqual(
1515
- expect.not.objectContaining({ kv_namespaces: expect.anything })
1516
- );
1517
- expect(diagnostics.hasWarnings()).toBe(false);
1518
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1519
- "Processing wrangler configuration:
1520
- - The field \\"kv_namespaces\\" should be an array but got \\"BAD\\"."
1521
- `);
1522
- });
1523
-
1524
- it("should error if kv_namespaces is a number", () => {
1525
- const { config, diagnostics } = normalizeAndValidateConfig(
1526
- { kv_namespaces: 999 } as unknown as RawConfig,
1527
- undefined,
1528
- { env: undefined }
1529
- );
1530
-
1531
- expect(config).toEqual(
1532
- expect.not.objectContaining({ kv_namespaces: expect.anything })
1533
- );
1534
- expect(diagnostics.hasWarnings()).toBe(false);
1535
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1536
- "Processing wrangler configuration:
1537
- - The field \\"kv_namespaces\\" should be an array but got 999."
1538
- `);
1539
- });
1540
-
1541
- it("should error if kv_namespaces is null", () => {
1542
- const { config, diagnostics } = normalizeAndValidateConfig(
1543
- { kv_namespaces: null } as unknown as RawConfig,
1544
- undefined,
1545
- { env: undefined }
1546
- );
1547
-
1548
- expect(config).toEqual(
1549
- expect.not.objectContaining({ kv_namespaces: expect.anything })
1550
- );
1551
- expect(diagnostics.hasWarnings()).toBe(false);
1552
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1553
- "Processing wrangler configuration:
1554
- - The field \\"kv_namespaces\\" should be an array but got null."
1555
- `);
1556
- });
1557
-
1558
- it("should error if kv_namespaces.bindings are not valid", () => {
1559
- const { config, diagnostics } = normalizeAndValidateConfig(
1560
- {
1561
- kv_namespaces: [
1562
- {},
1563
- { binding: "VALID" },
1564
- { binding: 2000, id: 2111 },
1565
- {
1566
- binding: "KV_BINDING_2",
1567
- id: "KV_ID_2",
1568
- preview_id: 2222,
1569
- },
1570
- ],
1571
- } as unknown as RawConfig,
1572
- undefined,
1573
- { env: undefined }
1574
- );
1575
-
1576
- expect(config).toEqual(
1577
- expect.not.objectContaining({
1578
- kv_namespaces: { bindings: expect.anything },
1579
- })
1580
- );
1581
- expect(diagnostics.hasWarnings()).toBe(false);
1582
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1583
- "Processing wrangler configuration:
1584
- - \\"kv_namespaces[0]\\" bindings should have a string \\"binding\\" field but got {}.
1585
- - \\"kv_namespaces[0]\\" bindings should have a string \\"id\\" field but got {}.
1586
- - \\"kv_namespaces[1]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":\\"VALID\\"}.
1587
- - \\"kv_namespaces[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
1588
- - \\"kv_namespaces[2]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
1589
- - \\"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}."
1590
- `);
1591
- });
1592
- });
1593
-
1594
- describe("[r2_buckets]", () => {
1595
- it("should error if r2_buckets is an object", () => {
1596
- const { config, diagnostics } = normalizeAndValidateConfig(
1597
- { r2_buckets: {} } as unknown as RawConfig,
1598
- undefined,
1599
- { env: undefined }
1600
- );
1601
-
1602
- expect(config).toEqual(
1603
- expect.not.objectContaining({ r2_buckets: expect.anything })
1604
- );
1605
- expect(diagnostics.hasWarnings()).toBe(false);
1606
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1607
- "Processing wrangler configuration:
1608
- - The field \\"r2_buckets\\" should be an array but got {}."
1609
- `);
1610
- });
1611
-
1612
- it("should error if r2_buckets is a string", () => {
1613
- const { config, diagnostics } = normalizeAndValidateConfig(
1614
- { r2_buckets: "BAD" } as unknown as RawConfig,
1615
- undefined,
1616
- { env: undefined }
1617
- );
1618
-
1619
- expect(config).toEqual(
1620
- expect.not.objectContaining({ r2_buckets: expect.anything })
1621
- );
1622
- expect(diagnostics.hasWarnings()).toBe(false);
1623
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1624
- "Processing wrangler configuration:
1625
- - The field \\"r2_buckets\\" should be an array but got \\"BAD\\"."
1626
- `);
1627
- });
1628
-
1629
- it("should error if r2_buckets is a number", () => {
1630
- const { config, diagnostics } = normalizeAndValidateConfig(
1631
- { r2_buckets: 999 } as unknown as RawConfig,
1632
- undefined,
1633
- { env: undefined }
1634
- );
1635
-
1636
- expect(config).toEqual(
1637
- expect.not.objectContaining({ r2_buckets: expect.anything })
1638
- );
1639
- expect(diagnostics.hasWarnings()).toBe(false);
1640
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1641
- "Processing wrangler configuration:
1642
- - The field \\"r2_buckets\\" should be an array but got 999."
1643
- `);
1644
- });
1645
-
1646
- it("should error if r2_buckets is null", () => {
1647
- const { config, diagnostics } = normalizeAndValidateConfig(
1648
- { r2_buckets: null } as unknown as RawConfig,
1649
- undefined,
1650
- { env: undefined }
1651
- );
1652
-
1653
- expect(config).toEqual(
1654
- expect.not.objectContaining({ r2_buckets: expect.anything })
1655
- );
1656
- expect(diagnostics.hasWarnings()).toBe(false);
1657
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1658
- "Processing wrangler configuration:
1659
- - The field \\"r2_buckets\\" should be an array but got null."
1660
- `);
1661
- });
1662
-
1663
- it("should error if r2_buckets.bindings are not valid", () => {
1664
- const { config, diagnostics } = normalizeAndValidateConfig(
1665
- {
1666
- r2_buckets: [
1667
- {},
1668
- { binding: "R2_BINDING_1" },
1669
- { binding: 2333, bucket_name: 2444 },
1670
- {
1671
- binding: "R2_BINDING_2",
1672
- bucket_name: "R2_BUCKET_2",
1673
- preview_bucket_name: 2555,
1674
- },
1675
- ],
1676
- } as unknown as RawConfig,
1677
- undefined,
1678
- { env: undefined }
1679
- );
1680
-
1681
- expect(config).toEqual(
1682
- expect.not.objectContaining({
1683
- r2_buckets: { bindings: expect.anything },
1684
- })
1685
- );
1686
- expect(diagnostics.hasWarnings()).toBe(false);
1687
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1688
- "Processing wrangler configuration:
1689
- - \\"r2_buckets[0]\\" bindings should have a string \\"binding\\" field but got {}.
1690
- - \\"r2_buckets[0]\\" bindings should have a string \\"bucket_name\\" field but got {}.
1691
- - \\"r2_buckets[1]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_1\\"}.
1692
- - \\"r2_buckets[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
1693
- - \\"r2_buckets[2]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
1694
- - \\"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}."
1695
- `);
1696
- });
1697
- });
1698
-
1699
- describe("[services]", () => {
1700
- it("should error if services is an object", () => {
1701
- const { config, diagnostics } = normalizeAndValidateConfig(
1702
- { services: {} } as unknown as RawConfig,
1703
- undefined,
1704
- { env: undefined }
1705
- );
1706
-
1707
- expect(config).toEqual(
1708
- expect.not.objectContaining({ services: expect.anything })
1709
- );
1710
- expect(diagnostics.hasWarnings()).toBe(true);
1711
- expect(diagnostics.hasErrors()).toBe(true);
1712
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1713
- "Processing wrangler configuration:
1714
- - \\"services\\" fields are experimental and may change or break at any time."
1715
- `);
1716
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1717
- "Processing wrangler configuration:
1718
- - The field \\"services\\" should be an array but got {}."
1719
- `);
1720
- });
1721
-
1722
- it("should error if services is a string", () => {
1723
- const { config, diagnostics } = normalizeAndValidateConfig(
1724
- { services: "BAD" } as unknown as RawConfig,
1725
- undefined,
1726
- { env: undefined }
1727
- );
1728
-
1729
- expect(config).toEqual(
1730
- expect.not.objectContaining({ services: expect.anything })
1731
- );
1732
- expect(diagnostics.hasWarnings()).toBe(true);
1733
- expect(diagnostics.hasErrors()).toBe(true);
1734
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1735
- "Processing wrangler configuration:
1736
- - \\"services\\" fields are experimental and may change or break at any time."
1737
- `);
1738
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1739
- "Processing wrangler configuration:
1740
- - The field \\"services\\" should be an array but got \\"BAD\\"."
1741
- `);
1742
- });
1743
-
1744
- it("should error if services is a number", () => {
1745
- const { config, diagnostics } = normalizeAndValidateConfig(
1746
- { services: 999 } as unknown as RawConfig,
1747
- undefined,
1748
- { env: undefined }
1749
- );
1750
-
1751
- expect(config).toEqual(
1752
- expect.not.objectContaining({ services: expect.anything })
1753
- );
1754
- expect(diagnostics.hasWarnings()).toBe(true);
1755
- expect(diagnostics.hasErrors()).toBe(true);
1756
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1757
- "Processing wrangler configuration:
1758
- - \\"services\\" fields are experimental and may change or break at any time."
1759
- `);
1760
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1761
- "Processing wrangler configuration:
1762
- - The field \\"services\\" should be an array but got 999."
1763
- `);
1764
- });
1765
-
1766
- it("should error if services is null", () => {
1767
- const { config, diagnostics } = normalizeAndValidateConfig(
1768
- { services: null } as unknown as RawConfig,
1769
- undefined,
1770
- { env: undefined }
1771
- );
1772
-
1773
- expect(config).toEqual(
1774
- expect.not.objectContaining({ services: expect.anything })
1775
- );
1776
- expect(diagnostics.hasWarnings()).toBe(true);
1777
- expect(diagnostics.hasErrors()).toBe(true);
1778
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1779
- "Processing wrangler configuration:
1780
- - \\"services\\" fields are experimental and may change or break at any time."
1781
- `);
1782
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1783
- "Processing wrangler configuration:
1784
- - The field \\"services\\" should be an array but got null."
1785
- `);
1786
- });
1787
-
1788
- it("should error if services bindings are not valid", () => {
1789
- const { config, diagnostics } = normalizeAndValidateConfig(
1790
- {
1791
- services: [
1792
- {},
1793
- { binding: "SERVICE_BINDING_1" },
1794
- { binding: 123, service: 456 },
1795
- { binding: 123, service: 456, environment: 789 },
1796
- { binding: "SERVICE_BINDING_1", service: 456, environment: 789 },
1797
- {
1798
- binding: 123,
1799
- service: "SERVICE_BINDING_SERVICE_1",
1800
- environment: 789,
1801
- },
1802
- {
1803
- binding: 123,
1804
- service: 456,
1805
- environment: "SERVICE_BINDING_ENVIRONMENT_1",
1806
- },
1807
- ],
1808
- } as unknown as RawConfig,
1809
- undefined,
1810
- { env: undefined }
1811
- );
1812
-
1813
- expect(config).toEqual(
1814
- expect.not.objectContaining({
1815
- services: { bindings: expect.anything },
1816
- })
1817
- );
1818
- expect(diagnostics.hasWarnings()).toBe(true);
1819
- expect(diagnostics.hasErrors()).toBe(true);
1820
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1821
- "Processing wrangler configuration:
1822
- - \\"services\\" fields are experimental and may change or break at any time."
1823
- `);
1824
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1825
- "Processing wrangler configuration:
1826
- - \\"services[0]\\" bindings should have a string \\"binding\\" field but got {}.
1827
- - \\"services[0]\\" bindings should have a string \\"service\\" field but got {}.
1828
- - \\"services[1]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":\\"SERVICE_BINDING_1\\"}.
1829
- - \\"services[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456}.
1830
- - \\"services[2]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":123,\\"service\\":456}.
1831
- - \\"services[3]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":789}.
1832
- - \\"services[3]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":789}.
1833
- - \\"services[3]\\" bindings should have a string \\"environment\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":789}.
1834
- - \\"services[4]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":\\"SERVICE_BINDING_1\\",\\"service\\":456,\\"environment\\":789}.
1835
- - \\"services[4]\\" bindings should have a string \\"environment\\" field but got {\\"binding\\":\\"SERVICE_BINDING_1\\",\\"service\\":456,\\"environment\\":789}.
1836
- - \\"services[5]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":\\"SERVICE_BINDING_SERVICE_1\\",\\"environment\\":789}.
1837
- - \\"services[5]\\" bindings should have a string \\"environment\\" field but got {\\"binding\\":123,\\"service\\":\\"SERVICE_BINDING_SERVICE_1\\",\\"environment\\":789}.
1838
- - \\"services[6]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":\\"SERVICE_BINDING_ENVIRONMENT_1\\"}.
1839
- - \\"services[6]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":\\"SERVICE_BINDING_ENVIRONMENT_1\\"}."
1840
- `);
1841
- });
1842
- });
1843
-
1844
- describe("[worker_namespaces]", () => {
1845
- it("should log an experimental warning when worker_namespaces is used", () => {
1846
- const { config, diagnostics } = normalizeAndValidateConfig(
1847
- {
1848
- worker_namespaces: [
1849
- {
1850
- binding: "BINDING_1",
1851
- namespace: "NAMESPACE_1",
1852
- },
1853
- ],
1854
- } as unknown as RawConfig,
1855
- undefined,
1856
- { env: undefined }
1857
- );
1858
- expect(config).toEqual(
1859
- expect.not.objectContaining({ worker_namespaces: expect.anything })
1860
- );
1861
- expect(diagnostics.hasWarnings()).toBe(true);
1862
- expect(diagnostics.hasErrors()).toBe(false);
1863
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1864
- "Processing wrangler configuration:
1865
- - \\"worker_namespaces\\" fields are experimental and may change or break at any time."
1866
- `);
1867
- });
1868
-
1869
- it("should error if worker_namespaces is not an array", () => {
1870
- const { config, diagnostics } = normalizeAndValidateConfig(
1871
- {
1872
- worker_namespaces: "just a string",
1873
- } as unknown as RawConfig,
1874
- undefined,
1875
- { env: undefined }
1876
- );
1877
-
1878
- expect(config).toEqual(
1879
- expect.not.objectContaining({ worker_namespaces: expect.anything })
1880
- );
1881
- expect(diagnostics.hasWarnings()).toBe(true);
1882
- expect(diagnostics.hasErrors()).toBe(true);
1883
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1884
- "Processing wrangler configuration:
1885
- - \\"worker_namespaces\\" fields are experimental and may change or break at any time."
1886
- `);
1887
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1888
- "Processing wrangler configuration:
1889
- - The field \\"worker_namespaces\\" should be an array but got \\"just a string\\"."
1890
- `);
1891
- });
1892
-
1893
- it("should error on non valid worker_namespaces", () => {
1894
- const { config, diagnostics } = normalizeAndValidateConfig(
1895
- {
1896
- worker_namespaces: [
1897
- "a string",
1898
- 123,
1899
- {
1900
- binding: 123,
1901
- namespace: 456,
1902
- },
1903
- {
1904
- binding: "WORKER_NAMESPACE_BINDING_1",
1905
- namespace: 456,
1906
- },
1907
- // this one is valid
1908
- {
1909
- binding: "WORKER_NAMESPACE_BINDING_1",
1910
- namespace: "WORKER_NAMESPACE_BINDING_NAMESPACE_1",
1911
- },
1912
- {
1913
- binding: 123,
1914
- namespace: "WORKER_NAMESPACE_BINDING_SERVICE_1",
1915
- },
1916
- {
1917
- binding: 123,
1918
- service: 456,
1919
- },
1920
- ],
1921
- } as unknown as RawConfig,
1922
- undefined,
1923
- { env: undefined }
1924
- );
1925
- expect(config).toEqual(
1926
- expect.not.objectContaining({
1927
- worker_namespaces: expect.anything,
1928
- })
1929
- );
1930
- expect(diagnostics.hasWarnings()).toBe(true);
1931
- expect(diagnostics.hasErrors()).toBe(true);
1932
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1933
- "Processing wrangler configuration:
1934
- - \\"worker_namespaces\\" fields are experimental and may change or break at any time."
1935
- `);
1936
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1937
- "Processing wrangler configuration:
1938
- - \\"worker_namespaces[0]\\" binding should be objects, but got \\"a string\\"
1939
- - \\"worker_namespaces[1]\\" binding should be objects, but got 123
1940
- - \\"worker_namespaces[2]\\" should have a string \\"binding\\" field but got {\\"binding\\":123,\\"namespace\\":456}.
1941
- - \\"worker_namespaces[2]\\" should have a string \\"namespace\\" field but got {\\"binding\\":123,\\"namespace\\":456}.
1942
- - \\"worker_namespaces[3]\\" should have a string \\"namespace\\" field but got {\\"binding\\":\\"WORKER_NAMESPACE_BINDING_1\\",\\"namespace\\":456}.
1943
- - \\"worker_namespaces[5]\\" should have a string \\"binding\\" field but got {\\"binding\\":123,\\"namespace\\":\\"WORKER_NAMESPACE_BINDING_SERVICE_1\\"}.
1944
- - \\"worker_namespaces[6]\\" should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456}.
1945
- - \\"worker_namespaces[6]\\" should have a string \\"namespace\\" field but got {\\"binding\\":123,\\"service\\":456}."
1946
- `);
1947
- });
1948
- });
1949
-
1950
- describe("[unsafe.bindings]", () => {
1951
- it("should error if unsafe is an array", () => {
1952
- const { config, diagnostics } = normalizeAndValidateConfig(
1953
- { unsafe: [] } as unknown as RawConfig,
1954
- undefined,
1955
- { env: undefined }
1956
- );
1957
-
1958
- expect(config).toEqual(
1959
- expect.not.objectContaining({ unsafe: expect.anything })
1960
- );
1961
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1962
- "Processing wrangler configuration:
1963
- - \\"unsafe\\" fields are experimental and may change or break at any time."
1964
- `);
1965
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1966
- "Processing wrangler configuration:
1967
- - The field \\"unsafe\\" should be an object but got []."
1968
- `);
1969
- });
1970
-
1971
- it("should error if unsafe is a string", () => {
1972
- const { config, diagnostics } = normalizeAndValidateConfig(
1973
- { unsafe: "BAD" } as unknown as RawConfig,
1974
- undefined,
1975
- { env: undefined }
1976
- );
1977
-
1978
- expect(config).toEqual(
1979
- expect.not.objectContaining({ unsafe: expect.anything })
1980
- );
1981
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1982
- "Processing wrangler configuration:
1983
- - \\"unsafe\\" fields are experimental and may change or break at any time."
1984
- `);
1985
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1986
- "Processing wrangler configuration:
1987
- - The field \\"unsafe\\" should be an object but got \\"BAD\\"."
1988
- `);
1989
- });
1990
-
1991
- it("should error if unsafe is a number", () => {
1992
- const { config, diagnostics } = normalizeAndValidateConfig(
1993
- { unsafe: 999 } as unknown as RawConfig,
1994
- undefined,
1995
- { env: undefined }
1996
- );
1997
-
1998
- expect(config).toEqual(
1999
- expect.not.objectContaining({ unsafe: expect.anything })
2000
- );
2001
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2002
- "Processing wrangler configuration:
2003
- - \\"unsafe\\" fields are experimental and may change or break at any time."
2004
- `);
2005
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2006
- "Processing wrangler configuration:
2007
- - The field \\"unsafe\\" should be an object but got 999."
2008
- `);
2009
- });
2010
-
2011
- it("should error if unsafe is null", () => {
2012
- const { config, diagnostics } = normalizeAndValidateConfig(
2013
- { unsafe: null } as unknown as RawConfig,
2014
- undefined,
2015
- { env: undefined }
2016
- );
2017
-
2018
- expect(config).toEqual(
2019
- expect.not.objectContaining({ unsafe: expect.anything })
2020
- );
2021
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2022
- "Processing wrangler configuration:
2023
- - \\"unsafe\\" fields are experimental and may change or break at any time."
2024
- `);
2025
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2026
- "Processing wrangler configuration:
2027
- - The field \\"unsafe\\" should be an object but got null."
2028
- `);
2029
- });
2030
-
2031
- it("should error if unsafe.bindings is not defined", () => {
2032
- const { config, diagnostics } = normalizeAndValidateConfig(
2033
- { unsafe: {} } as unknown as RawConfig,
2034
- undefined,
2035
- { env: undefined }
2036
- );
2037
-
2038
- expect(config).toEqual(
2039
- expect.not.objectContaining({ unsafe: expect.anything })
2040
- );
2041
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2042
- "Processing wrangler configuration:
2043
- - \\"unsafe\\" fields are experimental and may change or break at any time."
2044
- `);
2045
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2046
- "Processing wrangler configuration:
2047
- - The field \\"unsafe\\" is missing the required \\"bindings\\" property."
2048
- `);
2049
- });
2050
-
2051
- it("should error if unsafe.bindings is an object", () => {
2052
- const { config, diagnostics } = normalizeAndValidateConfig(
2053
- { unsafe: { bindings: {} } } as unknown as RawConfig,
2054
- undefined,
2055
- { env: undefined }
2056
- );
2057
-
2058
- expect(config).toEqual(
2059
- expect.not.objectContaining({
2060
- unsafe: { bindings: expect.anything },
2061
- })
2062
- );
2063
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2064
- "Processing wrangler configuration:
2065
- - \\"unsafe\\" fields are experimental and may change or break at any time."
2066
- `);
2067
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2068
- "Processing wrangler configuration:
2069
- - The field \\"unsafe.bindings\\" should be an array but got {}."
2070
- `);
2071
- });
2072
-
2073
- it("should error if unsafe.bindings is a string", () => {
2074
- const { config, diagnostics } = normalizeAndValidateConfig(
2075
- { unsafe: { bindings: "BAD" } } as unknown as RawConfig,
2076
- undefined,
2077
- { env: undefined }
2078
- );
2079
-
2080
- expect(config).toEqual(
2081
- expect.not.objectContaining({
2082
- unsafe: { bindings: expect.anything },
2083
- })
2084
- );
2085
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2086
- "Processing wrangler configuration:
2087
- - \\"unsafe\\" fields are experimental and may change or break at any time."
2088
- `);
2089
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2090
- "Processing wrangler configuration:
2091
- - The field \\"unsafe.bindings\\" should be an array but got \\"BAD\\"."
2092
- `);
2093
- });
2094
-
2095
- it("should error if unsafe.bindings is a number", () => {
2096
- const { config, diagnostics } = normalizeAndValidateConfig(
2097
- { unsafe: { bindings: 999 } } as unknown as RawConfig,
2098
- undefined,
2099
- { env: undefined }
2100
- );
2101
-
2102
- expect(config).toEqual(
2103
- expect.not.objectContaining({
2104
- unsafe: { bindings: expect.anything },
2105
- })
2106
- );
2107
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2108
- "Processing wrangler configuration:
2109
- - \\"unsafe\\" fields are experimental and may change or break at any time."
2110
- `);
2111
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2112
- "Processing wrangler configuration:
2113
- - The field \\"unsafe.bindings\\" should be an array but got 999."
2114
- `);
2115
- });
2116
-
2117
- it("should error if unsafe.bindings is null", () => {
2118
- const { config, diagnostics } = normalizeAndValidateConfig(
2119
- { unsafe: { bindings: null } } as unknown as RawConfig,
2120
- undefined,
2121
- { env: undefined }
2122
- );
2123
-
2124
- expect(config).toEqual(
2125
- expect.not.objectContaining({
2126
- unsafe: { bindings: expect.anything },
2127
- })
2128
- );
2129
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2130
- "Processing wrangler configuration:
2131
- - \\"unsafe\\" fields are experimental and may change or break at any time."
2132
- `);
2133
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2134
- "Processing wrangler configuration:
2135
- - The field \\"unsafe.bindings\\" should be an array but got null."
2136
- `);
2137
- });
2138
-
2139
- it("should error if durable_objects.bindings are not valid", () => {
2140
- const { config, diagnostics } = normalizeAndValidateConfig(
2141
- {
2142
- unsafe: {
2143
- bindings: [
2144
- {},
2145
- { name: "UNSAFE_BINDING_1" },
2146
- { name: 2666, type: 2777 },
2147
- {
2148
- name: "UNSAFE_BINDING_2",
2149
- type: "UNSAFE_TYPE_2",
2150
- extra: 2888,
2151
- },
2152
- ],
2153
- },
2154
- } as unknown as RawConfig,
2155
- undefined,
2156
- { env: undefined }
2157
- );
2158
-
2159
- expect(config).toEqual(
2160
- expect.not.objectContaining({
2161
- durable_objects: { bindings: expect.anything },
2162
- })
2163
- );
2164
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2165
- "Processing wrangler configuration:
2166
- - \\"unsafe\\" fields are experimental and may change or break at any time."
2167
- `);
2168
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2169
- "Processing wrangler configuration:
2170
-
2171
- - \\"unsafe.bindings[0]\\": {}
2172
- - binding should have a string \\"name\\" field.
2173
- - binding should have a string \\"type\\" field.
2174
-
2175
- - \\"unsafe.bindings[1]\\": {\\"name\\":\\"UNSAFE_BINDING_1\\"}
2176
- - binding should have a string \\"type\\" field.
2177
-
2178
- - \\"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 rawConfig: RawConfig = {
2188
- zone_id: "ZONE_ID",
2189
- experimental_services: [
2190
- {
2191
- name: "mock-name",
2192
- service: "SERVICE",
2193
- environment: "ENV",
2194
- },
2195
- ],
2196
- };
2197
-
2198
- const { config, diagnostics } = normalizeAndValidateConfig(
2199
- rawConfig,
2200
- undefined,
2201
- { env: undefined }
2202
- );
2203
-
2204
- expect("experimental_services" in config).toBe(false);
2205
- // Zone is not removed yet, since `route` commands might use it
2206
- expect(config.zone_id).toEqual("ZONE_ID");
2207
- expect(diagnostics.hasErrors()).toBe(false);
2208
- expect(diagnostics.hasWarnings()).toBe(true);
2209
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2210
- "Processing wrangler configuration:
2211
- - Deprecation: \\"zone_id\\":
2212
- This is unnecessary since we can deduce this from routes directly.
2213
- - Deprecation: \\"experimental_services\\":
2214
- The \\"experimental_services\\" field is no longer supported. Simply rename the [experimental_services] field to [services]."
2215
- `);
2216
- });
2217
- });
2218
-
2219
- describe("route & routes fields", () => {
2220
- it("should error if both route and routes are specified", () => {
2221
- const rawConfig: RawConfig = {
2222
- route: "route1",
2223
- routes: ["route2", "route3"],
2224
- };
2225
-
2226
- const { diagnostics } = normalizeAndValidateConfig(
2227
- rawConfig,
2228
- undefined,
2229
- { env: undefined }
2230
- );
2231
-
2232
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2233
- "Processing wrangler configuration:
2234
- - Expected exactly one of the following fields [\\"routes\\",\\"route\\"]."
2235
- `);
2236
- });
2237
- });
2238
- });
2239
-
2240
- describe("named environments", () => {
2241
- it("should warn if we specify an environment but there are no named environments", () => {
2242
- const rawConfig: RawConfig = {};
2243
- const { diagnostics } = normalizeAndValidateConfig(rawConfig, undefined, {
2244
- env: "DEV",
2245
- });
2246
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2247
- "Processing wrangler configuration:
2248
- "
2249
- `);
2250
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2251
- "Processing wrangler configuration:
2252
- - No environment found in configuration with name \\"DEV\\".
2253
- Before using \`--env=DEV\` there should be an equivalent environment section in the configuration.
2254
-
2255
- Consider adding an environment configuration section to the wrangler.toml file:
2256
- \`\`\`
2257
- [env.DEV]
2258
- \`\`\`
2259
- "
2260
- `);
2261
- });
2262
-
2263
- it("should error if we specify an environment that does not match the named environments", () => {
2264
- const rawConfig: RawConfig = { env: { ENV1: {} } };
2265
- const { diagnostics } = normalizeAndValidateConfig(rawConfig, undefined, {
2266
- env: "DEV",
2267
- });
2268
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2269
- "Processing wrangler configuration:
2270
- - No environment found in configuration with name \\"DEV\\".
2271
- Before using \`--env=DEV\` there should be an equivalent environment section in the configuration.
2272
- The available configured environment names are: [\\"ENV1\\"]
2273
-
2274
- Consider adding an environment configuration section to the wrangler.toml file:
2275
- \`\`\`
2276
- [env.DEV]
2277
- \`\`\`
2278
- "
2279
- `);
2280
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2281
- "Processing wrangler configuration:
2282
- "
2283
- `);
2284
- });
2285
-
2286
- it("should use top-level values for inheritable config fields", () => {
2287
- const main = "src/index.ts";
2288
- const resolvedMain = path.resolve(process.cwd(), main);
2289
- const rawConfig: RawConfig = {
2290
- name: "mock-name",
2291
- account_id: "ACCOUNT_ID",
2292
- compatibility_date: "2022-01-01",
2293
- compatibility_flags: ["FLAG1", "FLAG2"],
2294
- workers_dev: false,
2295
- routes: ["ROUTE_1", "ROUTE_2"],
2296
- jsx_factory: "JSX_FACTORY",
2297
- jsx_fragment: "JSX_FRAGMENT",
2298
- tsconfig: "path/to/tsconfig.json",
2299
- triggers: { crons: ["CRON_1", "CRON_2"] },
2300
- usage_model: "bundled",
2301
- main,
2302
- build: {
2303
- command: "COMMAND",
2304
- cwd: "CWD",
2305
- watch_dir: "WATCH_DIR",
2306
- },
2307
- no_bundle: true,
2308
- minify: true,
2309
- node_compat: true,
2310
- };
2311
-
2312
- const { config, diagnostics } = normalizeAndValidateConfig(
2313
- { ...rawConfig, env: { dev: {} } },
2314
- undefined,
2315
- { env: "dev" }
2316
- );
2317
-
2318
- expect(config).toEqual(
2319
- expect.objectContaining({
2320
- ...rawConfig,
2321
- main: resolvedMain,
2322
- name: "mock-name-dev",
2323
- })
2324
- );
2325
- expect(diagnostics.hasErrors()).toBe(false);
2326
- expect(diagnostics.hasWarnings()).toBe(false);
2327
- });
2328
-
2329
- it("should override top-level values for inheritable config fields", () => {
2330
- const main = "src/index.ts";
2331
- const resolvedMain = path.resolve(process.cwd(), main);
2332
- const rawEnv: RawEnvironment = {
2333
- name: "mock-env-name",
2334
- account_id: "ENV_ACCOUNT_ID",
2335
- compatibility_date: "2022-02-02",
2336
- compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
2337
- workers_dev: true,
2338
- routes: ["ENV_ROUTE_1", "ENV_ROUTE_2"],
2339
- jsx_factory: "ENV_JSX_FACTORY",
2340
- jsx_fragment: "ENV_JSX_FRAGMENT",
2341
- tsconfig: "ENV_path/to/tsconfig.json",
2342
- triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
2343
- usage_model: "unbound",
2344
- main,
2345
- build: {
2346
- command: "ENV_COMMAND",
2347
- cwd: "ENV_CWD",
2348
- watch_dir: "ENV_WATCH_DIR",
2349
- },
2350
- no_bundle: false,
2351
- minify: false,
2352
- node_compat: false,
2353
- };
2354
- const rawConfig: RawConfig = {
2355
- name: "mock-name",
2356
- account_id: "ACCOUNT_ID",
2357
- compatibility_date: "2022-01-01",
2358
- compatibility_flags: ["FLAG1", "FLAG2"],
2359
- workers_dev: false,
2360
- routes: ["ROUTE_1", "ROUTE_2"],
2361
- jsx_factory: "JSX_FACTORY",
2362
- jsx_fragment: "JSX_FRAGMENT",
2363
- tsconfig: "path/to/tsconfig.json",
2364
- triggers: { crons: ["CRON_1", "CRON_2"] },
2365
- usage_model: "bundled",
2366
- main: "top-level.js",
2367
- build: {
2368
- command: "COMMAND",
2369
- cwd: "CWD",
2370
- watch_dir: "WATCH_DIR",
2371
- },
2372
- no_bundle: true,
2373
- minify: true,
2374
- node_compat: true,
2375
- env: {
2376
- ENV1: rawEnv,
2377
- },
2378
- };
2379
-
2380
- const { config, diagnostics } = normalizeAndValidateConfig(
2381
- rawConfig,
2382
- undefined,
2383
- { env: "ENV1" }
2384
- );
2385
-
2386
- expect(config).toEqual(
2387
- expect.objectContaining({ ...rawEnv, main: resolvedMain })
2388
- );
2389
- expect(diagnostics.hasErrors()).toBe(false);
2390
- expect(diagnostics.hasWarnings()).toBe(false);
2391
- });
2392
-
2393
- describe("non-legacy", () => {
2394
- it("should use top-level `name` field", () => {
2395
- const rawConfig: RawConfig = {
2396
- name: "mock-name",
2397
- legacy_env: false,
2398
- env: { DEV: {} },
2399
- };
2400
-
2401
- const { config, diagnostics } = normalizeAndValidateConfig(
2402
- rawConfig,
2403
- undefined,
2404
- { env: "DEV" }
2405
- );
2406
-
2407
- expect(config.name).toEqual("mock-name");
2408
- expect(diagnostics.hasErrors()).toBe(false);
2409
- expect(diagnostics.hasWarnings()).toBe(true);
2410
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2411
- "Processing wrangler configuration:
2412
- - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in the future. DO NOT USE IN PRODUCTION."
2413
- `);
2414
- });
2415
-
2416
- it("should error if named environment contains a `name` field, even if there is no top-level name", () => {
2417
- const rawConfig: RawConfig = {
2418
- legacy_env: false,
2419
- env: {
2420
- DEV: {
2421
- name: "mock-env-name",
2422
- },
2423
- },
2424
- };
2425
-
2426
- const { config, diagnostics } = normalizeAndValidateConfig(
2427
- rawConfig,
2428
- undefined,
2429
- { env: "DEV" }
2430
- );
2431
-
2432
- expect(config.name).toBeUndefined();
2433
- expect(diagnostics.hasWarnings()).toBe(true);
2434
- expect(diagnostics.hasErrors()).toBe(true);
2435
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2436
- "Processing wrangler configuration:
2437
- - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in the future. DO NOT USE IN PRODUCTION."
2438
- `);
2439
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2440
- "Processing wrangler configuration:
2441
-
2442
- - \\"env.DEV\\" environment configuration
2443
- - The \\"name\\" field is not allowed in named service environments.
2444
- Please remove the field from this environment."
2445
- `);
2446
- });
2447
-
2448
- it("should error if top-level config and a named environment both contain a `name` field", () => {
2449
- const rawConfig: RawConfig = {
2450
- name: "mock-name",
2451
- legacy_env: false,
2452
- env: {
2453
- DEV: {
2454
- name: "mock-env-name",
2455
- },
2456
- },
2457
- };
2458
-
2459
- const { config, diagnostics } = normalizeAndValidateConfig(
2460
- rawConfig,
2461
- undefined,
2462
- { env: "DEV" }
2463
- );
2464
-
2465
- expect(config.name).toEqual("mock-name");
2466
- expect(diagnostics.hasWarnings()).toBe(true);
2467
- expect(diagnostics.hasErrors()).toBe(true);
2468
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2469
- "Processing wrangler configuration:
2470
- - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in the future. DO NOT USE IN PRODUCTION."
2471
- `);
2472
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2473
- "Processing wrangler configuration:
2474
-
2475
- - \\"env.DEV\\" environment configuration
2476
- - The \\"name\\" field is not allowed in named service environments.
2477
- Please remove the field from this environment."
2478
- `);
2479
- });
2480
- });
2481
-
2482
- it("should error if named environment contains a `account_id` field, even if there is no top-level name", () => {
2483
- const rawConfig: RawConfig = {
2484
- legacy_env: false,
2485
- env: {
2486
- DEV: {
2487
- account_id: "some_account_id",
2488
- },
2489
- },
2490
- };
2491
-
2492
- const { config, diagnostics } = normalizeAndValidateConfig(
2493
- rawConfig,
2494
- undefined,
2495
- { env: "DEV" }
2496
- );
2497
-
2498
- expect(diagnostics.hasWarnings()).toBe(true);
2499
- expect(config.account_id).toBeUndefined();
2500
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2501
- "Processing wrangler configuration:
2502
- - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in the future. DO NOT USE IN PRODUCTION."
2503
- `);
2504
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2505
- "Processing wrangler configuration:
2506
-
2507
- - \\"env.DEV\\" environment configuration
2508
- - The \\"account_id\\" field is not allowed in named service environments.
2509
- Please remove the field from this environment."
2510
- `);
2511
- });
2512
-
2513
- it("should error if top-level config and a named environment both contain a `account_id` field", () => {
2514
- const rawConfig: RawConfig = {
2515
- account_id: "ACCOUNT_ID",
2516
- legacy_env: false,
2517
- env: {
2518
- DEV: {
2519
- account_id: "ENV_ACCOUNT_ID",
2520
- },
2521
- },
2522
- };
2523
-
2524
- const { config, diagnostics } = normalizeAndValidateConfig(
2525
- rawConfig,
2526
- undefined,
2527
- { env: "DEV" }
2528
- );
2529
-
2530
- expect(config.account_id).toEqual("ACCOUNT_ID");
2531
- expect(diagnostics.hasErrors()).toBe(true);
2532
- expect(diagnostics.hasWarnings()).toBe(true);
2533
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2534
- "Processing wrangler configuration:
2535
- - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in the future. DO NOT USE IN PRODUCTION."
2536
- `);
2537
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2538
- "Processing wrangler configuration:
2539
-
2540
- - \\"env.DEV\\" environment configuration
2541
- - The \\"account_id\\" field is not allowed in named service environments.
2542
- Please remove the field from this environment."
2543
- `);
2544
- });
2545
-
2546
- it("should warn for non-inherited fields that are missing in environments", () => {
2547
- const define: RawConfig["define"] = {
2548
- abc: "123",
2549
- };
2550
- const vars: RawConfig["vars"] = {
2551
- FOO: "foo",
2552
- };
2553
- const durable_objects: RawConfig["durable_objects"] = {
2554
- bindings: [],
2555
- };
2556
- const kv_namespaces: RawConfig["kv_namespaces"] = [];
2557
- const r2_buckets: RawConfig["r2_buckets"] = [];
2558
- const unsafe: RawConfig["unsafe"] = { bindings: [] };
2559
- const rawConfig: RawConfig = {
2560
- define,
2561
- vars,
2562
- durable_objects,
2563
- kv_namespaces,
2564
- r2_buckets,
2565
- unsafe,
2566
- env: {
2567
- ENV1: {},
2568
- },
2569
- };
2570
-
2571
- const { config, diagnostics } = normalizeAndValidateConfig(
2572
- rawConfig,
2573
- undefined,
2574
- { env: "ENV1" }
2575
- );
2576
-
2577
- expect(config).toEqual(
2578
- expect.not.objectContaining({
2579
- define,
2580
- vars,
2581
- durable_objects,
2582
- kv_namespaces,
2583
- r2_buckets,
2584
- unsafe,
2585
- })
2586
- );
2587
- expect(diagnostics.hasErrors()).toBe(false);
2588
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2589
- "Processing wrangler configuration:
2590
- - \\"unsafe\\" fields are experimental and may change or break at any time.
2591
- - \\"env.ENV1\\" environment configuration
2592
- - \\"vars\\" exists at the top level, but not on \\"env.ENV1\\".
2593
- This is not what you probably want, since \\"vars\\" is not inherited by environments.
2594
- Please add \\"vars\\" to \\"env.ENV1\\".
2595
- - \\"define\\" exists at the top level, but not on \\"env.ENV1\\".
2596
- This is not what you probably want, since \\"define\\" is not inherited by environments.
2597
- Please add \\"define\\" to \\"env.ENV1\\".
2598
- - \\"durable_objects\\" exists at the top level, but not on \\"env.ENV1\\".
2599
- This is not what you probably want, since \\"durable_objects\\" is not inherited by environments.
2600
- Please add \\"durable_objects\\" to \\"env.ENV1\\".
2601
- - \\"kv_namespaces\\" exists at the top level, but not on \\"env.ENV1\\".
2602
- This is not what you probably want, since \\"kv_namespaces\\" is not inherited by environments.
2603
- Please add \\"kv_namespaces\\" to \\"env.ENV1\\".
2604
- - \\"r2_buckets\\" exists at the top level, but not on \\"env.ENV1\\".
2605
- This is not what you probably want, since \\"r2_buckets\\" is not inherited by environments.
2606
- Please add \\"r2_buckets\\" to \\"env.ENV1\\".
2607
- - \\"unsafe\\" exists at the top level, but not on \\"env.ENV1\\".
2608
- This is not what you probably want, since \\"unsafe\\" is not inherited by environments.
2609
- Please add \\"unsafe\\" to \\"env.ENV1\\"."
2610
- `);
2611
- });
2612
-
2613
- it("should error on invalid environment values", () => {
2614
- const expectedConfig: RawEnvironment = {
2615
- name: 111,
2616
- account_id: 222,
2617
- compatibility_date: 333,
2618
- compatibility_flags: [444, 555],
2619
- workers_dev: "BAD",
2620
- routes: [666, 777],
2621
- route: 888,
2622
- jsx_factory: 999,
2623
- jsx_fragment: 1000,
2624
- tsconfig: 123,
2625
- triggers: { crons: [1111, 1222] },
2626
- usage_model: "INVALID",
2627
- main: 1333,
2628
- build: {
2629
- command: 1444,
2630
- cwd: 1555,
2631
- watch_dir: 1666,
2632
- },
2633
- no_bundle: "INVALID",
2634
- minify: "INVALID",
2635
- node_compat: "INVALID",
2636
- } as unknown as RawEnvironment;
2637
-
2638
- const { config, diagnostics } = normalizeAndValidateConfig(
2639
- { env: { ENV1: expectedConfig } },
2640
- undefined,
2641
- { env: "ENV1" }
2642
- );
2643
-
2644
- expect(config).toEqual(expect.objectContaining(expectedConfig));
2645
- expect(diagnostics.hasWarnings()).toBe(false);
2646
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2647
- "Processing wrangler configuration:
2648
-
2649
- - \\"env.ENV1\\" environment configuration
2650
- - Expected \\"route\\" to be either a string, or an object with shape { pattern, custom_domain, zone_id | zone_name }, but got 888.
2651
- - Expected \\"account_id\\" to be of type string but got 222.
2652
- - 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: [
2653
- 666,
2654
- 777
2655
- ].
2656
- - Expected exactly one of the following fields [\\"routes\\",\\"route\\"].
2657
- - Expected \\"workers_dev\\" to be of type boolean but got \\"BAD\\".
2658
- - Expected \\"build.command\\" to be of type string but got 1444.
2659
- - Expected \\"build.cwd\\" to be of type string but got 1555.
2660
- - Expected \\"build.watch_dir\\" to be of type string but got 1666.
2661
- - Expected \\"compatibility_date\\" to be of type string but got 333.
2662
- - Expected \\"compatibility_flags\\" to be of type string array but got [444,555].
2663
- - Expected \\"jsx_factory\\" to be of type string but got 999.
2664
- - Expected \\"jsx_fragment\\" to be of type string but got 1000.
2665
- - Expected \\"tsconfig\\" to be of type string but got 123.
2666
- - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got 111.
2667
- - Expected \\"main\\" to be of type string but got 1333.
2668
- - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\".
2669
- - Expected \\"no_bundle\\" to be of type boolean but got \\"INVALID\\".
2670
- - Expected \\"minify\\" to be of type boolean but got \\"INVALID\\".
2671
- - Expected \\"node_compat\\" to be of type boolean but got \\"INVALID\\"."
2672
- `);
2673
- });
2674
-
2675
- describe("[define]", () => {
2676
- it("should accept valid values for config.define", () => {
2677
- const rawConfig: RawConfig = {
2678
- define: {
2679
- abc: "def",
2680
- ghi: "123",
2681
- },
2682
- };
2683
- const { config, diagnostics } = normalizeAndValidateConfig(
2684
- rawConfig,
2685
- undefined,
2686
- { env: undefined }
2687
- );
2688
-
2689
- expect(config).toEqual(expect.objectContaining(rawConfig));
2690
- expect(diagnostics.hasWarnings()).toBe(false);
2691
- expect(diagnostics.hasErrors()).toBe(false);
2692
- });
2693
-
2694
- it("should error if config.define is not an object", () => {
2695
- const rawConfig: RawConfig = {
2696
- // @ts-expect-error purposely using an invalid value
2697
- define: 123,
2698
- };
2699
- const { config, diagnostics } = normalizeAndValidateConfig(
2700
- rawConfig,
2701
- undefined,
2702
- { env: undefined }
2703
- );
2704
-
2705
- expect(config).toEqual(expect.objectContaining(rawConfig));
2706
- expect(diagnostics.hasWarnings()).toBe(false);
2707
- expect(diagnostics.hasErrors()).toBe(true);
2708
-
2709
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2710
- "Processing wrangler configuration:
2711
- - The field \\"define\\" should be an object but got 123.
2712
- "
2713
- `);
2714
- });
2715
-
2716
- it("should error if the values on config.define are not strings", () => {
2717
- const rawConfig: RawConfig = {
2718
- define: {
2719
- // @ts-expect-error purposely using an invalid value
2720
- abc: 123,
2721
- // This one's valid
2722
- def: "xyz",
2723
- // @ts-expect-error purposely using an invalid value
2724
- ghi: true,
2725
- // @ts-expect-error purposely using an invalid value
2726
- jkl: {
2727
- nested: "value",
2728
- },
2729
- },
2730
- };
2731
- const { config, diagnostics } = normalizeAndValidateConfig(
2732
- rawConfig,
2733
- undefined,
2734
- { env: undefined }
2735
- );
2736
-
2737
- expect(config).toEqual(expect.objectContaining(rawConfig));
2738
- expect(diagnostics.hasWarnings()).toBe(false);
2739
- expect(diagnostics.hasErrors()).toBe(true);
2740
-
2741
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2742
- "Processing wrangler configuration:
2743
- - The field \\"define.abc\\" should be a string but got 123.
2744
- - The field \\"define.ghi\\" should be a string but got true.
2745
- - The field \\"define.jkl\\" should be a string but got {\\"nested\\":\\"value\\"}."
2746
- `);
2747
- });
2748
-
2749
- describe("named environments", () => {
2750
- it("should accept valid values for config.define inside an environment", () => {
2751
- const rawConfig: RawConfig = {
2752
- define: {
2753
- abc: "def",
2754
- ghi: "123",
2755
- },
2756
- env: {
2757
- ENV1: {
2758
- define: {
2759
- abc: "xyz",
2760
- ghi: "456",
2761
- },
2762
- },
2763
- },
2764
- };
2765
- const { config, diagnostics } = normalizeAndValidateConfig(
2766
- rawConfig,
2767
- undefined,
2768
- { env: "ENV1" }
2769
- );
2770
-
2771
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2772
- expect(config).toEqual(expect.objectContaining(rawConfig.env!.ENV1));
2773
- expect(diagnostics.hasWarnings()).toBe(false);
2774
- expect(diagnostics.hasErrors()).toBe(false);
2775
- });
2776
-
2777
- it("should error if config.define is not an object inside an environment", () => {
2778
- const rawConfig: RawConfig = {
2779
- define: {
2780
- abc: "def",
2781
- ghi: "123",
2782
- },
2783
- env: {
2784
- ENV1: {
2785
- // @ts-expect-error purposely using an invalid value
2786
- define: 123,
2787
- },
2788
- },
2789
- };
2790
- const { config, diagnostics } = normalizeAndValidateConfig(
2791
- rawConfig,
2792
- undefined,
2793
- { env: "ENV1" }
2794
- );
2795
-
2796
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2797
- expect(config).toEqual(expect.objectContaining(rawConfig.env!.ENV1));
2798
- expect(diagnostics.hasWarnings()).toBe(false);
2799
- expect(diagnostics.hasErrors()).toBe(true);
2800
-
2801
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2802
- "Processing wrangler configuration:
2803
-
2804
- - \\"env.ENV1\\" environment configuration
2805
- - The field \\"env.ENV1.define\\" should be an object but got 123.
2806
- "
2807
- `);
2808
- });
2809
-
2810
- it("should warn if if the shape of .define inside an environment doesn't match the shape of the top level .define", () => {
2811
- const rawConfig: RawConfig = {
2812
- define: {
2813
- abc: "def",
2814
- ghi: "123",
2815
- },
2816
- env: {
2817
- ENV1: {
2818
- define: {
2819
- abc: "def",
2820
- xyz: "123",
2821
- },
2822
- },
2823
- },
2824
- };
2825
- const { config, diagnostics } = normalizeAndValidateConfig(
2826
- rawConfig,
2827
- undefined,
2828
- { env: "ENV1" }
2829
- );
2830
-
2831
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2832
- expect(config).toEqual(expect.objectContaining(rawConfig.env!.ENV1));
2833
- expect(diagnostics.hasWarnings()).toBe(true);
2834
- expect(diagnostics.hasErrors()).toBe(false);
2835
-
2836
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2837
- "Processing wrangler configuration:
2838
-
2839
- - \\"env.ENV1\\" environment configuration
2840
- - \\"define.ghi\\" exists at the top level, but not on \\"env.ENV1.define\\".
2841
- This is not what you probably want, since \\"define\\" configuration is not inherited by environments.
2842
- Please add \\"define.ghi\\" to \\"env.ENV1\\".
2843
- - \\"xyz\\" exists on \\"env.ENV1\\", but not on the top level.
2844
- This is not what you probably want, since \\"define\\" configuration within environments can only override existing top level \\"define\\" configuration
2845
- Please remove \\"env.ENV1.define.xyz\\", or add \\"define.xyz\\"."
2846
- `);
2847
- });
2848
-
2849
- it("should error if the values on config.define in an environment are not strings", () => {
2850
- const rawConfig: RawConfig = {
2851
- define: {
2852
- abc: "123",
2853
- def: "xyz",
2854
- ghi: "true",
2855
- jkl: "some value",
2856
- },
2857
- env: {
2858
- ENV1: {
2859
- define: {
2860
- // @ts-expect-error purposely using an invalid value
2861
- abc: 123,
2862
- // This one's valid
2863
- def: "xyz",
2864
- // @ts-expect-error purposely using an invalid value
2865
- ghi: true,
2866
- // @ts-expect-error purposely using an invalid value
2867
- jkl: {
2868
- nested: "value",
2869
- },
2870
- },
2871
- },
2872
- },
2873
- };
2874
- const { config, diagnostics } = normalizeAndValidateConfig(
2875
- rawConfig,
2876
- undefined,
2877
- { env: "ENV1" }
2878
- );
2879
-
2880
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2881
- expect(config).toEqual(expect.objectContaining(rawConfig.env!.ENV1));
2882
- expect(diagnostics.hasWarnings()).toBe(false);
2883
- expect(diagnostics.hasErrors()).toBe(true);
2884
-
2885
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2886
- "Processing wrangler configuration:
2887
-
2888
- - \\"env.ENV1\\" environment configuration
2889
- - The field \\"env.ENV1.define.abc\\" should be a string but got 123.
2890
- - The field \\"env.ENV1.define.ghi\\" should be a string but got true.
2891
- - The field \\"env.ENV1.define.jkl\\" should be a string but got {\\"nested\\":\\"value\\"}."
2892
- `);
2893
- });
2894
- });
2895
- });
2896
-
2897
- describe("[durable_objects]", () => {
2898
- it("should error if durable_objects is an array", () => {
2899
- const { config, diagnostics } = normalizeAndValidateConfig(
2900
- { env: { ENV1: { durable_objects: [] } } } as unknown as RawConfig,
2901
- undefined,
2902
- { env: "ENV1" }
2903
- );
2904
-
2905
- expect(config).toEqual(
2906
- expect.not.objectContaining({ durable_objects: expect.anything })
2907
- );
2908
- expect(diagnostics.hasWarnings()).toBe(false);
2909
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2910
- "Processing wrangler configuration:
2911
-
2912
- - \\"env.ENV1\\" environment configuration
2913
- - The field \\"env.ENV1.durable_objects\\" should be an object but got []."
2914
- `);
2915
- });
2916
-
2917
- it("should error if durable_objects is a string", () => {
2918
- const { config, diagnostics } = normalizeAndValidateConfig(
2919
- { env: { ENV1: { durable_objects: "BAD" } } } as unknown as RawConfig,
2920
- undefined,
2921
- { env: "ENV1" }
2922
- );
2923
-
2924
- expect(config).toEqual(
2925
- expect.not.objectContaining({ durable_objects: expect.anything })
2926
- );
2927
- expect(diagnostics.hasWarnings()).toBe(false);
2928
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2929
- "Processing wrangler configuration:
2930
-
2931
- - \\"env.ENV1\\" environment configuration
2932
- - The field \\"env.ENV1.durable_objects\\" should be an object but got \\"BAD\\"."
2933
- `);
2934
- });
2935
-
2936
- it("should error if durable_objects is a number", () => {
2937
- const { config, diagnostics } = normalizeAndValidateConfig(
2938
- { env: { ENV1: { durable_objects: 999 } } } as unknown as RawConfig,
2939
- undefined,
2940
- { env: "ENV1" }
2941
- );
2942
-
2943
- expect(config).toEqual(
2944
- expect.not.objectContaining({ durable_objects: expect.anything })
2945
- );
2946
- expect(diagnostics.hasWarnings()).toBe(false);
2947
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2948
- "Processing wrangler configuration:
2949
-
2950
- - \\"env.ENV1\\" environment configuration
2951
- - The field \\"env.ENV1.durable_objects\\" should be an object but got 999."
2952
- `);
2953
- });
2954
-
2955
- it("should error if durable_objects is null", () => {
2956
- const { config, diagnostics } = normalizeAndValidateConfig(
2957
- { env: { ENV1: { durable_objects: null } } } as unknown as RawConfig,
2958
- undefined,
2959
- { env: "ENV1" }
2960
- );
2961
-
2962
- expect(config).toEqual(
2963
- expect.not.objectContaining({ durable_objects: expect.anything })
2964
- );
2965
- expect(diagnostics.hasWarnings()).toBe(false);
2966
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2967
- "Processing wrangler configuration:
2968
-
2969
- - \\"env.ENV1\\" environment configuration
2970
- - The field \\"env.ENV1.durable_objects\\" should be an object but got null."
2971
- `);
2972
- });
2973
-
2974
- it("should error if durable_objects.bindings is not defined", () => {
2975
- const { config, diagnostics } = normalizeAndValidateConfig(
2976
- { env: { ENV1: { durable_objects: {} } } } as unknown as RawConfig,
2977
- undefined,
2978
- { env: "ENV1" }
2979
- );
2980
-
2981
- expect(config).toEqual(
2982
- expect.not.objectContaining({ durable_objects: expect.anything })
2983
- );
2984
- expect(diagnostics.hasWarnings()).toBe(false);
2985
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2986
- "Processing wrangler configuration:
2987
-
2988
- - \\"env.ENV1\\" environment configuration
2989
- - The field \\"env.ENV1.durable_objects\\" is missing the required \\"bindings\\" property."
2990
- `);
2991
- });
2992
-
2993
- it("should error if durable_objects.bindings is an object", () => {
2994
- const { config, diagnostics } = normalizeAndValidateConfig(
2995
- {
2996
- env: { ENV1: { durable_objects: { bindings: {} } } },
2997
- } as unknown as RawConfig,
2998
- undefined,
2999
- { env: "ENV1" }
3000
- );
3001
-
3002
- expect(config).toEqual(
3003
- expect.not.objectContaining({
3004
- durable_objects: { bindings: expect.anything },
3005
- })
3006
- );
3007
- expect(diagnostics.hasWarnings()).toBe(false);
3008
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3009
- "Processing wrangler configuration:
3010
-
3011
- - \\"env.ENV1\\" environment configuration
3012
- - The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got {}."
3013
- `);
3014
- });
3015
-
3016
- it("should error if durable_objects.bindings is a string", () => {
3017
- const { config, diagnostics } = normalizeAndValidateConfig(
3018
- {
3019
- env: { ENV1: { durable_objects: { bindings: "BAD" } } },
3020
- } as unknown as RawConfig,
3021
- undefined,
3022
- { env: "ENV1" }
3023
- );
3024
-
3025
- expect(config).toEqual(
3026
- expect.not.objectContaining({
3027
- durable_objects: { bindings: expect.anything },
3028
- })
3029
- );
3030
- expect(diagnostics.hasWarnings()).toBe(false);
3031
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3032
- "Processing wrangler configuration:
3033
-
3034
- - \\"env.ENV1\\" environment configuration
3035
- - The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got \\"BAD\\"."
3036
- `);
3037
- });
3038
-
3039
- it("should error if durable_objects.bindings is a number", () => {
3040
- const { config, diagnostics } = normalizeAndValidateConfig(
3041
- {
3042
- env: { ENV1: { durable_objects: { bindings: 999 } } },
3043
- } as unknown as RawConfig,
3044
- undefined,
3045
- { env: "ENV1" }
3046
- );
3047
-
3048
- expect(config).toEqual(
3049
- expect.not.objectContaining({
3050
- durable_objects: { bindings: expect.anything },
3051
- })
3052
- );
3053
- expect(diagnostics.hasWarnings()).toBe(false);
3054
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3055
- "Processing wrangler configuration:
3056
-
3057
- - \\"env.ENV1\\" environment configuration
3058
- - The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got 999."
3059
- `);
3060
- });
3061
-
3062
- it("should error if durable_objects.bindings is null", () => {
3063
- const { config, diagnostics } = normalizeAndValidateConfig(
3064
- {
3065
- env: { ENV1: { durable_objects: { bindings: null } } },
3066
- } as unknown as RawConfig,
3067
- undefined,
3068
- { env: "ENV1" }
3069
- );
3070
-
3071
- expect(config).toEqual(
3072
- expect.not.objectContaining({
3073
- durable_objects: { bindings: expect.anything },
3074
- })
3075
- );
3076
- expect(diagnostics.hasWarnings()).toBe(false);
3077
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3078
- "Processing wrangler configuration:
3079
-
3080
- - \\"env.ENV1\\" environment configuration
3081
- - The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got null."
3082
- `);
3083
- });
3084
-
3085
- it("should error if durable_objects.bindings are not valid", () => {
3086
- const { config, diagnostics } = normalizeAndValidateConfig(
3087
- {
3088
- env: {
3089
- ENV1: {
3090
- durable_objects: {
3091
- bindings: [
3092
- {},
3093
- { name: "VALID" },
3094
- { name: 1555, class_name: 1666 },
3095
- {
3096
- name: 1777,
3097
- class_name: 1888,
3098
- script_name: 1999,
3099
- },
3100
- ],
3101
- },
3102
- },
3103
- },
3104
- } as unknown as RawConfig,
3105
- undefined,
3106
- { env: "ENV1" }
3107
- );
3108
-
3109
- expect(config).toEqual(
3110
- expect.not.objectContaining({
3111
- durable_objects: { bindings: expect.anything },
3112
- })
3113
- );
3114
- expect(diagnostics.hasWarnings()).toBe(false);
3115
- expect(diagnostics.hasErrors()).toBe(true);
3116
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3117
- "Processing wrangler configuration:
3118
-
3119
- - \\"env.ENV1\\" environment configuration
3120
-
3121
- - \\"env.ENV1.durable_objects.bindings[0]\\": {}
3122
- - binding should have a string \\"name\\" field.
3123
- - binding should have a string \\"class_name\\" field.
3124
-
3125
- - \\"env.ENV1.durable_objects.bindings[1]\\": {\\"name\\":\\"VALID\\"}
3126
- - binding should have a string \\"class_name\\" field.
3127
-
3128
- - \\"env.ENV1.durable_objects.bindings[2]\\": {\\"name\\":1555,\\"class_name\\":1666}
3129
- - binding should have a string \\"name\\" field.
3130
- - binding should have a string \\"class_name\\" field.
3131
-
3132
- - \\"env.ENV1.durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
3133
- - binding should have a string \\"name\\" field.
3134
- - binding should have a string \\"class_name\\" field.
3135
- - the field \\"script_name\\", when present, should be a string."
3136
- `);
3137
- });
3138
- });
3139
-
3140
- describe("[kv_namespaces]", () => {
3141
- it("should error if kv_namespaces is an object", () => {
3142
- const { config, diagnostics } = normalizeAndValidateConfig(
3143
- { env: { ENV1: { kv_namespaces: {} } } } as unknown as RawConfig,
3144
- undefined,
3145
- { env: "ENV1" }
3146
- );
3147
-
3148
- expect(config).toEqual(
3149
- expect.not.objectContaining({ kv_namespaces: expect.anything })
3150
- );
3151
- expect(diagnostics.hasWarnings()).toBe(false);
3152
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3153
- "Processing wrangler configuration:
3154
-
3155
- - \\"env.ENV1\\" environment configuration
3156
- - The field \\"env.ENV1.kv_namespaces\\" should be an array but got {}."
3157
- `);
3158
- });
3159
-
3160
- it("should error if kv_namespaces is a string", () => {
3161
- const { config, diagnostics } = normalizeAndValidateConfig(
3162
- { env: { ENV1: { kv_namespaces: "BAD" } } } as unknown as RawConfig,
3163
- undefined,
3164
- { env: "ENV1" }
3165
- );
3166
-
3167
- expect(config).toEqual(
3168
- expect.not.objectContaining({ kv_namespaces: expect.anything })
3169
- );
3170
- expect(diagnostics.hasWarnings()).toBe(false);
3171
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3172
- "Processing wrangler configuration:
3173
-
3174
- - \\"env.ENV1\\" environment configuration
3175
- - The field \\"env.ENV1.kv_namespaces\\" should be an array but got \\"BAD\\"."
3176
- `);
3177
- });
3178
-
3179
- it("should error if kv_namespaces is a number", () => {
3180
- const { config, diagnostics } = normalizeAndValidateConfig(
3181
- { env: { ENV1: { kv_namespaces: 999 } } } as unknown as RawConfig,
3182
- undefined,
3183
- { env: "ENV1" }
3184
- );
3185
-
3186
- expect(config).toEqual(
3187
- expect.not.objectContaining({ kv_namespaces: expect.anything })
3188
- );
3189
- expect(diagnostics.hasWarnings()).toBe(false);
3190
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3191
- "Processing wrangler configuration:
3192
-
3193
- - \\"env.ENV1\\" environment configuration
3194
- - The field \\"env.ENV1.kv_namespaces\\" should be an array but got 999."
3195
- `);
3196
- });
3197
-
3198
- it("should error if kv_namespaces is null", () => {
3199
- const { config, diagnostics } = normalizeAndValidateConfig(
3200
- { env: { ENV1: { kv_namespaces: null } } } as unknown as RawConfig,
3201
- undefined,
3202
- { env: "ENV1" }
3203
- );
3204
-
3205
- expect(config).toEqual(
3206
- expect.not.objectContaining({ kv_namespaces: expect.anything })
3207
- );
3208
- expect(diagnostics.hasWarnings()).toBe(false);
3209
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3210
- "Processing wrangler configuration:
3211
-
3212
- - \\"env.ENV1\\" environment configuration
3213
- - The field \\"env.ENV1.kv_namespaces\\" should be an array but got null."
3214
- `);
3215
- });
3216
-
3217
- it("should error if kv_namespaces.bindings are not valid", () => {
3218
- const { config, diagnostics } = normalizeAndValidateConfig(
3219
- {
3220
- env: {
3221
- ENV1: {
3222
- kv_namespaces: [
3223
- {},
3224
- { binding: "VALID" },
3225
- { binding: 2000, id: 2111 },
3226
- {
3227
- binding: "KV_BINDING_2",
3228
- id: "KV_ID_2",
3229
- preview_id: 2222,
3230
- },
3231
- ],
3232
- },
3233
- },
3234
- } as unknown as RawConfig,
3235
- undefined,
3236
- { env: "ENV1" }
3237
- );
3238
-
3239
- expect(config).toEqual(
3240
- expect.not.objectContaining({
3241
- kv_namespaces: { bindings: expect.anything },
3242
- })
3243
- );
3244
- expect(diagnostics.hasWarnings()).toBe(false);
3245
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3246
- "Processing wrangler configuration:
3247
-
3248
- - \\"env.ENV1\\" environment configuration
3249
- - \\"env.ENV1.kv_namespaces[0]\\" bindings should have a string \\"binding\\" field but got {}.
3250
- - \\"env.ENV1.kv_namespaces[0]\\" bindings should have a string \\"id\\" field but got {}.
3251
- - \\"env.ENV1.kv_namespaces[1]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":\\"VALID\\"}.
3252
- - \\"env.ENV1.kv_namespaces[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
3253
- - \\"env.ENV1.kv_namespaces[2]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
3254
- - \\"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}."
3255
- `);
3256
- });
3257
- });
3258
-
3259
- describe("[r2_buckets]", () => {
3260
- it("should error if r2_buckets is an object", () => {
3261
- const { config, diagnostics } = normalizeAndValidateConfig(
3262
- { env: { ENV1: { r2_buckets: {} } } } as unknown as RawConfig,
3263
- undefined,
3264
- { env: "ENV1" }
3265
- );
3266
-
3267
- expect(config).toEqual(
3268
- expect.not.objectContaining({ r2_buckets: expect.anything })
3269
- );
3270
- expect(diagnostics.hasWarnings()).toBe(false);
3271
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3272
- "Processing wrangler configuration:
3273
-
3274
- - \\"env.ENV1\\" environment configuration
3275
- - The field \\"env.ENV1.r2_buckets\\" should be an array but got {}."
3276
- `);
3277
- });
3278
-
3279
- it("should error if r2_buckets is a string", () => {
3280
- const { config, diagnostics } = normalizeAndValidateConfig(
3281
- { env: { ENV1: { r2_buckets: "BAD" } } } as unknown as RawConfig,
3282
- undefined,
3283
- { env: "ENV1" }
3284
- );
3285
-
3286
- expect(config).toEqual(
3287
- expect.not.objectContaining({ r2_buckets: expect.anything })
3288
- );
3289
- expect(diagnostics.hasWarnings()).toBe(false);
3290
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3291
- "Processing wrangler configuration:
3292
-
3293
- - \\"env.ENV1\\" environment configuration
3294
- - The field \\"env.ENV1.r2_buckets\\" should be an array but got \\"BAD\\"."
3295
- `);
3296
- });
3297
-
3298
- it("should error if r2_buckets is a number", () => {
3299
- const { config, diagnostics } = normalizeAndValidateConfig(
3300
- { env: { ENV1: { r2_buckets: 999 } } } as unknown as RawConfig,
3301
- undefined,
3302
- { env: "ENV1" }
3303
- );
3304
-
3305
- expect(config).toEqual(
3306
- expect.not.objectContaining({ r2_buckets: expect.anything })
3307
- );
3308
- expect(diagnostics.hasWarnings()).toBe(false);
3309
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3310
- "Processing wrangler configuration:
3311
-
3312
- - \\"env.ENV1\\" environment configuration
3313
- - The field \\"env.ENV1.r2_buckets\\" should be an array but got 999."
3314
- `);
3315
- });
3316
-
3317
- it("should error if r2_buckets is null", () => {
3318
- const { config, diagnostics } = normalizeAndValidateConfig(
3319
- { env: { ENV1: { r2_buckets: null } } } as unknown as RawConfig,
3320
- undefined,
3321
- { env: "ENV1" }
3322
- );
3323
-
3324
- expect(config).toEqual(
3325
- expect.not.objectContaining({ r2_buckets: expect.anything })
3326
- );
3327
- expect(diagnostics.hasWarnings()).toBe(false);
3328
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3329
- "Processing wrangler configuration:
3330
-
3331
- - \\"env.ENV1\\" environment configuration
3332
- - The field \\"env.ENV1.r2_buckets\\" should be an array but got null."
3333
- `);
3334
- });
3335
-
3336
- it("should error if r2_buckets.bindings are not valid", () => {
3337
- const { config, diagnostics } = normalizeAndValidateConfig(
3338
- {
3339
- env: {
3340
- ENV1: {
3341
- r2_buckets: [
3342
- {},
3343
- { binding: "R2_BINDING_1" },
3344
- { binding: 2333, bucket_name: 2444 },
3345
- {
3346
- binding: "R2_BINDING_2",
3347
- bucket_name: "R2_BUCKET_2",
3348
- preview_bucket_name: 2555,
3349
- },
3350
- ],
3351
- },
3352
- },
3353
- } as unknown as RawConfig,
3354
- undefined,
3355
- { env: "ENV1" }
3356
- );
3357
-
3358
- expect(config).toEqual(
3359
- expect.not.objectContaining({
3360
- r2_buckets: { bindings: expect.anything },
3361
- })
3362
- );
3363
- expect(diagnostics.hasWarnings()).toBe(false);
3364
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3365
- "Processing wrangler configuration:
3366
-
3367
- - \\"env.ENV1\\" environment configuration
3368
- - \\"env.ENV1.r2_buckets[0]\\" bindings should have a string \\"binding\\" field but got {}.
3369
- - \\"env.ENV1.r2_buckets[0]\\" bindings should have a string \\"bucket_name\\" field but got {}.
3370
- - \\"env.ENV1.r2_buckets[1]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_1\\"}.
3371
- - \\"env.ENV1.r2_buckets[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
3372
- - \\"env.ENV1.r2_buckets[2]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
3373
- - \\"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}."
3374
- `);
3375
- });
3376
- });
3377
-
3378
- describe("[unsafe.bindings]", () => {
3379
- it("should error if unsafe is an array", () => {
3380
- const { config, diagnostics } = normalizeAndValidateConfig(
3381
- { env: { ENV1: { unsafe: [] } } } as unknown as RawConfig,
3382
- undefined,
3383
- { env: "ENV1" }
3384
- );
3385
-
3386
- expect(config).toEqual(
3387
- expect.not.objectContaining({ unsafe: expect.anything })
3388
- );
3389
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
3390
- "Processing wrangler configuration:
3391
-
3392
- - \\"env.ENV1\\" environment configuration
3393
- - \\"unsafe\\" fields are experimental and may change or break at any time."
3394
- `);
3395
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3396
- "Processing wrangler configuration:
3397
-
3398
- - \\"env.ENV1\\" environment configuration
3399
- - The field \\"env.ENV1.unsafe\\" should be an object but got []."
3400
- `);
3401
- });
3402
-
3403
- it("should error if unsafe is a string", () => {
3404
- const { config, diagnostics } = normalizeAndValidateConfig(
3405
- { env: { ENV1: { unsafe: "BAD" } } } as unknown as RawConfig,
3406
- undefined,
3407
- { env: "ENV1" }
3408
- );
3409
-
3410
- expect(config).toEqual(
3411
- expect.not.objectContaining({ unsafe: expect.anything })
3412
- );
3413
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
3414
- "Processing wrangler configuration:
3415
-
3416
- - \\"env.ENV1\\" environment configuration
3417
- - \\"unsafe\\" fields are experimental and may change or break at any time."
3418
- `);
3419
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3420
- "Processing wrangler configuration:
3421
-
3422
- - \\"env.ENV1\\" environment configuration
3423
- - The field \\"env.ENV1.unsafe\\" should be an object but got \\"BAD\\"."
3424
- `);
3425
- });
3426
-
3427
- it("should error if unsafe is a number", () => {
3428
- const { config, diagnostics } = normalizeAndValidateConfig(
3429
- { env: { ENV1: { unsafe: 999 } } } as unknown as RawConfig,
3430
- undefined,
3431
- { env: "ENV1" }
3432
- );
3433
-
3434
- expect(config).toEqual(
3435
- expect.not.objectContaining({ unsafe: expect.anything })
3436
- );
3437
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
3438
- "Processing wrangler configuration:
3439
-
3440
- - \\"env.ENV1\\" environment configuration
3441
- - \\"unsafe\\" fields are experimental and may change or break at any time."
3442
- `);
3443
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3444
- "Processing wrangler configuration:
3445
-
3446
- - \\"env.ENV1\\" environment configuration
3447
- - The field \\"env.ENV1.unsafe\\" should be an object but got 999."
3448
- `);
3449
- });
3450
-
3451
- it("should error if unsafe is null", () => {
3452
- const { config, diagnostics } = normalizeAndValidateConfig(
3453
- { env: { ENV1: { unsafe: null } } } as unknown as RawConfig,
3454
- undefined,
3455
- { env: "ENV1" }
3456
- );
3457
-
3458
- expect(config).toEqual(
3459
- expect.not.objectContaining({ unsafe: expect.anything })
3460
- );
3461
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
3462
- "Processing wrangler configuration:
3463
-
3464
- - \\"env.ENV1\\" environment configuration
3465
- - \\"unsafe\\" fields are experimental and may change or break at any time."
3466
- `);
3467
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3468
- "Processing wrangler configuration:
3469
-
3470
- - \\"env.ENV1\\" environment configuration
3471
- - The field \\"env.ENV1.unsafe\\" should be an object but got null."
3472
- `);
3473
- });
3474
-
3475
- it("should error if unsafe.bindings is not defined", () => {
3476
- const { config, diagnostics } = normalizeAndValidateConfig(
3477
- { env: { ENV1: { unsafe: {} } } } as unknown as RawConfig,
3478
- undefined,
3479
- { env: "ENV1" }
3480
- );
3481
-
3482
- expect(config).toEqual(
3483
- expect.not.objectContaining({ unsafe: expect.anything })
3484
- );
3485
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
3486
- "Processing wrangler configuration:
3487
-
3488
- - \\"env.ENV1\\" environment configuration
3489
- - \\"unsafe\\" fields are experimental and may change or break at any time."
3490
- `);
3491
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3492
- "Processing wrangler configuration:
3493
-
3494
- - \\"env.ENV1\\" environment configuration
3495
- - The field \\"env.ENV1.unsafe\\" is missing the required \\"bindings\\" property."
3496
- `);
3497
- });
3498
-
3499
- it("should error if unsafe.bindings is an object", () => {
3500
- const { config, diagnostics } = normalizeAndValidateConfig(
3501
- {
3502
- env: { ENV1: { unsafe: { bindings: {} } } },
3503
- } as unknown as RawConfig,
3504
- undefined,
3505
- { env: "ENV1" }
3506
- );
3507
-
3508
- expect(config).toEqual(
3509
- expect.not.objectContaining({
3510
- unsafe: { bindings: expect.anything },
3511
- })
3512
- );
3513
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
3514
- "Processing wrangler configuration:
3515
-
3516
- - \\"env.ENV1\\" environment configuration
3517
- - \\"unsafe\\" fields are experimental and may change or break at any time."
3518
- `);
3519
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3520
- "Processing wrangler configuration:
3521
-
3522
- - \\"env.ENV1\\" environment configuration
3523
- - The field \\"env.ENV1.unsafe.bindings\\" should be an array but got {}."
3524
- `);
3525
- });
3526
-
3527
- it("should error if unsafe.bindings is a string", () => {
3528
- const { config, diagnostics } = normalizeAndValidateConfig(
3529
- {
3530
- env: { ENV1: { unsafe: { bindings: "BAD" } } },
3531
- } as unknown as RawConfig,
3532
- undefined,
3533
- { env: "ENV1" }
3534
- );
3535
-
3536
- expect(config).toEqual(
3537
- expect.not.objectContaining({
3538
- unsafe: { bindings: expect.anything },
3539
- })
3540
- );
3541
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
3542
- "Processing wrangler configuration:
3543
-
3544
- - \\"env.ENV1\\" environment configuration
3545
- - \\"unsafe\\" fields are experimental and may change or break at any time."
3546
- `);
3547
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3548
- "Processing wrangler configuration:
3549
-
3550
- - \\"env.ENV1\\" environment configuration
3551
- - The field \\"env.ENV1.unsafe.bindings\\" should be an array but got \\"BAD\\"."
3552
- `);
3553
- });
3554
-
3555
- it("should error if unsafe.bindings is a number", () => {
3556
- const { config, diagnostics } = normalizeAndValidateConfig(
3557
- {
3558
- env: { ENV1: { unsafe: { bindings: 999 } } },
3559
- } as unknown as RawConfig,
3560
- undefined,
3561
- { env: "ENV1" }
3562
- );
3563
-
3564
- expect(config).toEqual(
3565
- expect.not.objectContaining({
3566
- unsafe: { bindings: expect.anything },
3567
- })
3568
- );
3569
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
3570
- "Processing wrangler configuration:
3571
-
3572
- - \\"env.ENV1\\" environment configuration
3573
- - \\"unsafe\\" fields are experimental and may change or break at any time."
3574
- `);
3575
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3576
- "Processing wrangler configuration:
3577
-
3578
- - \\"env.ENV1\\" environment configuration
3579
- - The field \\"env.ENV1.unsafe.bindings\\" should be an array but got 999."
3580
- `);
3581
- });
3582
-
3583
- it("should error if unsafe.bindings is null", () => {
3584
- const { config, diagnostics } = normalizeAndValidateConfig(
3585
- {
3586
- env: { ENV1: { unsafe: { bindings: null } } },
3587
- } as unknown as RawConfig,
3588
- undefined,
3589
- { env: "ENV1" }
3590
- );
3591
-
3592
- expect(config).toEqual(
3593
- expect.not.objectContaining({
3594
- unsafe: { bindings: expect.anything },
3595
- })
3596
- );
3597
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
3598
- "Processing wrangler configuration:
3599
-
3600
- - \\"env.ENV1\\" environment configuration
3601
- - \\"unsafe\\" fields are experimental and may change or break at any time."
3602
- `);
3603
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3604
- "Processing wrangler configuration:
3605
-
3606
- - \\"env.ENV1\\" environment configuration
3607
- - The field \\"env.ENV1.unsafe.bindings\\" should be an array but got null."
3608
- `);
3609
- });
3610
-
3611
- it("should error if unsafe.bindings are not valid", () => {
3612
- const { config, diagnostics } = normalizeAndValidateConfig(
3613
- {
3614
- env: {
3615
- ENV1: {
3616
- unsafe: {
3617
- bindings: [
3618
- {},
3619
- { name: "UNSAFE_BINDING_1" },
3620
- { name: 2666, type: 2777 },
3621
- {
3622
- name: "UNSAFE_BINDING_2",
3623
- type: "UNSAFE_TYPE_2",
3624
- extra: 2888,
3625
- },
3626
- ],
3627
- },
3628
- },
3629
- },
3630
- } as unknown as RawConfig,
3631
- undefined,
3632
- { env: "ENV1" }
3633
- );
3634
-
3635
- expect(config).toEqual(
3636
- expect.not.objectContaining({
3637
- durable_objects: { bindings: expect.anything },
3638
- })
3639
- );
3640
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
3641
- "Processing wrangler configuration:
3642
-
3643
- - \\"env.ENV1\\" environment configuration
3644
- - \\"unsafe\\" fields are experimental and may change or break at any time."
3645
- `);
3646
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3647
- "Processing wrangler configuration:
3648
-
3649
- - \\"env.ENV1\\" environment configuration
3650
-
3651
- - \\"env.ENV1.unsafe.bindings[0]\\": {}
3652
- - binding should have a string \\"name\\" field.
3653
- - binding should have a string \\"type\\" field.
3654
-
3655
- - \\"env.ENV1.unsafe.bindings[1]\\": {\\"name\\":\\"UNSAFE_BINDING_1\\"}
3656
- - binding should have a string \\"type\\" field.
3657
-
3658
- - \\"env.ENV1.unsafe.bindings[2]\\": {\\"name\\":2666,\\"type\\":2777}
3659
- - binding should have a string \\"name\\" field.
3660
- - binding should have a string \\"type\\" field."
3661
- `);
3662
- });
3663
- });
3664
-
3665
- describe("(deprecated)", () => {
3666
- it("should remove and warn about deprecated properties", () => {
3667
- const environment: RawEnvironment = {
3668
- zone_id: "ZONE_ID",
3669
- experimental_services: [
3670
- {
3671
- name: "mock-name",
3672
- service: "SERVICE",
3673
- environment: "ENV",
3674
- },
3675
- ],
3676
- };
3677
-
3678
- const { config, diagnostics } = normalizeAndValidateConfig(
3679
- {
3680
- env: {
3681
- ENV1: environment,
3682
- },
3683
- },
3684
- undefined,
3685
- { env: "ENV1" }
3686
- );
3687
-
3688
- expect("experimental_services" in config).toBe(false);
3689
- // Zone is not removed yet, since `route` commands might use it
3690
- expect(config.zone_id).toEqual("ZONE_ID");
3691
- expect(diagnostics.hasErrors()).toBe(false);
3692
- expect(diagnostics.hasWarnings()).toBe(true);
3693
- expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
3694
- "Processing wrangler configuration:
3695
-
3696
- - \\"env.ENV1\\" environment configuration
3697
- - Deprecation: \\"zone_id\\":
3698
- This is unnecessary since we can deduce this from routes directly.
3699
- - Deprecation: \\"experimental_services\\":
3700
- The \\"experimental_services\\" field is no longer supported. Simply rename the [experimental_services] field to [services]."
3701
- `);
3702
- });
3703
- });
3704
-
3705
- describe("route & routes fields", () => {
3706
- it("should error if both route and routes are specified in the same environment", () => {
3707
- const environment: RawEnvironment = {
3708
- name: "mock-env-name",
3709
- account_id: "ENV_ACCOUNT_ID",
3710
- compatibility_date: "2022-02-02",
3711
- compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
3712
- workers_dev: true,
3713
- route: "ENV_ROUTE_1",
3714
- routes: ["ENV_ROUTE_2", "ENV_ROUTE_3"],
3715
- jsx_factory: "ENV_JSX_FACTORY",
3716
- jsx_fragment: "ENV_JSX_FRAGMENT",
3717
- triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
3718
- usage_model: "unbound",
3719
- };
3720
- const expectedConfig: RawConfig = {
3721
- name: "mock-name",
3722
- account_id: "ACCOUNT_ID",
3723
- compatibility_date: "2022-01-01",
3724
- compatibility_flags: ["FLAG1", "FLAG2"],
3725
- workers_dev: false,
3726
- routes: ["ROUTE_1", "ROUTE_2"],
3727
- jsx_factory: "JSX_FACTORY",
3728
- jsx_fragment: "JSX_FRAGMENT",
3729
- triggers: { crons: ["CRON_1", "CRON_2"] },
3730
- usage_model: "bundled",
3731
- env: {
3732
- ENV1: environment,
3733
- },
3734
- };
3735
-
3736
- const { config, diagnostics } = normalizeAndValidateConfig(
3737
- expectedConfig,
3738
- undefined,
3739
- { env: "ENV1" }
3740
- );
3741
-
3742
- expect(config).toEqual(expect.objectContaining(environment));
3743
- expect(diagnostics.hasErrors()).toBe(true);
3744
- expect(diagnostics.hasWarnings()).toBe(false);
3745
-
3746
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3747
- "Processing wrangler configuration:
3748
-
3749
- - \\"env.ENV1\\" environment configuration
3750
- - Expected exactly one of the following fields [\\"routes\\",\\"route\\"]."
3751
- `);
3752
- });
3753
-
3754
- it("should error if both route and routes are specified in the top-level environment", () => {
3755
- const environment: RawEnvironment = {
3756
- name: "mock-env-name",
3757
- account_id: "ENV_ACCOUNT_ID",
3758
- compatibility_date: "2022-02-02",
3759
- compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
3760
- workers_dev: true,
3761
- routes: ["ENV_ROUTE_1", "ENV_ROUTE_2"],
3762
- jsx_factory: "ENV_JSX_FACTORY",
3763
- jsx_fragment: "ENV_JSX_FRAGMENT",
3764
- triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
3765
- usage_model: "unbound",
3766
- };
3767
- const expectedConfig: RawConfig = {
3768
- name: "mock-name",
3769
- account_id: "ACCOUNT_ID",
3770
- compatibility_date: "2022-01-01",
3771
- compatibility_flags: ["FLAG1", "FLAG2"],
3772
- workers_dev: false,
3773
- route: "ROUTE_1",
3774
- routes: ["ROUTE_2", "ROUTE_3"],
3775
- jsx_factory: "JSX_FACTORY",
3776
- jsx_fragment: "JSX_FRAGMENT",
3777
- triggers: { crons: ["CRON_1", "CRON_2"] },
3778
- usage_model: "bundled",
3779
- env: {
3780
- ENV1: environment,
3781
- },
3782
- };
3783
-
3784
- const { config, diagnostics } = normalizeAndValidateConfig(
3785
- expectedConfig,
3786
- undefined,
3787
- { env: "ENV1" }
3788
- );
3789
-
3790
- expect(config).toEqual(expect.objectContaining(environment));
3791
- expect(diagnostics.hasErrors()).toBe(true);
3792
- expect(diagnostics.hasWarnings()).toBe(false);
3793
-
3794
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3795
- "Processing wrangler configuration:
3796
- - Expected exactly one of the following fields [\\"routes\\",\\"route\\"]."
3797
- `);
3798
- });
3799
-
3800
- it("should not error if <env>.route and <top-level>.routes are specified", () => {
3801
- const environment: RawEnvironment = {
3802
- name: "mock-env-name",
3803
- account_id: "ENV_ACCOUNT_ID",
3804
- compatibility_date: "2022-02-02",
3805
- compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
3806
- workers_dev: true,
3807
- route: "ENV_ROUTE_1",
3808
- jsx_factory: "ENV_JSX_FACTORY",
3809
- jsx_fragment: "ENV_JSX_FRAGMENT",
3810
- triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
3811
- usage_model: "unbound",
3812
- };
3813
- const expectedConfig: RawConfig = {
3814
- name: "mock-name",
3815
- account_id: "ACCOUNT_ID",
3816
- compatibility_date: "2022-01-01",
3817
- compatibility_flags: ["FLAG1", "FLAG2"],
3818
- workers_dev: false,
3819
- routes: ["ROUTE_1", "ROUTE_2"],
3820
- jsx_factory: "JSX_FACTORY",
3821
- jsx_fragment: "JSX_FRAGMENT",
3822
- triggers: { crons: ["CRON_1", "CRON_2"] },
3823
- usage_model: "bundled",
3824
- env: {
3825
- ENV1: environment,
3826
- },
3827
- };
3828
-
3829
- const { config, diagnostics } = normalizeAndValidateConfig(
3830
- expectedConfig,
3831
- undefined,
3832
- { env: "ENV1" }
3833
- );
3834
-
3835
- expect(config).toEqual(expect.objectContaining(environment));
3836
- expect(diagnostics.hasErrors()).toBe(false);
3837
- expect(diagnostics.hasWarnings()).toBe(false);
3838
- });
3839
-
3840
- it("should not error if <env>.routes and <top-level>.route are specified", () => {
3841
- const environment: RawEnvironment = {
3842
- name: "mock-env-name",
3843
- account_id: "ENV_ACCOUNT_ID",
3844
- compatibility_date: "2022-02-02",
3845
- compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
3846
- workers_dev: true,
3847
- routes: ["ENV_ROUTE_1", "ENV_ROUTE_2"],
3848
- jsx_factory: "ENV_JSX_FACTORY",
3849
- jsx_fragment: "ENV_JSX_FRAGMENT",
3850
- triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
3851
- usage_model: "unbound",
3852
- };
3853
- const expectedConfig: RawConfig = {
3854
- name: "mock-name",
3855
- account_id: "ACCOUNT_ID",
3856
- compatibility_date: "2022-01-01",
3857
- compatibility_flags: ["FLAG1", "FLAG2"],
3858
- workers_dev: false,
3859
- route: "ROUTE_1",
3860
- jsx_factory: "JSX_FACTORY",
3861
- jsx_fragment: "JSX_FRAGMENT",
3862
- triggers: { crons: ["CRON_1", "CRON_2"] },
3863
- usage_model: "bundled",
3864
- env: {
3865
- ENV1: environment,
3866
- },
3867
- };
3868
-
3869
- const { config, diagnostics } = normalizeAndValidateConfig(
3870
- expectedConfig,
3871
- undefined,
3872
- { env: "ENV1" }
3873
- );
3874
-
3875
- expect(config).toEqual(expect.objectContaining(environment));
3876
- expect(diagnostics.hasErrors()).toBe(false);
3877
- expect(diagnostics.hasWarnings()).toBe(false);
3878
- });
3879
-
3880
- it("should not error if <env1>.route and <env2>.routes are specified", () => {
3881
- const environment1: RawEnvironment = {
3882
- name: "mock-env-name",
3883
- account_id: "ENV_ACCOUNT_ID",
3884
- compatibility_date: "2022-02-02",
3885
- compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
3886
- workers_dev: true,
3887
- routes: ["ENV1_ROUTE_1", "ENV2_ROUTE_2"],
3888
- jsx_factory: "ENV_JSX_FACTORY",
3889
- jsx_fragment: "ENV_JSX_FRAGMENT",
3890
- triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
3891
- usage_model: "unbound",
3892
- };
3893
- const environment2: RawEnvironment = {
3894
- name: "mock-env-name",
3895
- account_id: "ENV_ACCOUNT_ID",
3896
- compatibility_date: "2022-02-02",
3897
- compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
3898
- workers_dev: true,
3899
- route: "ENV2_ROUTE_1",
3900
- jsx_factory: "ENV_JSX_FACTORY",
3901
- jsx_fragment: "ENV_JSX_FRAGMENT",
3902
- triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
3903
- usage_model: "unbound",
3904
- };
3905
- const expectedConfig: RawConfig = {
3906
- name: "mock-name",
3907
- account_id: "ACCOUNT_ID",
3908
- compatibility_date: "2022-01-01",
3909
- compatibility_flags: ["FLAG1", "FLAG2"],
3910
- workers_dev: false,
3911
- route: "ROUTE_1",
3912
- jsx_factory: "JSX_FACTORY",
3913
- jsx_fragment: "JSX_FRAGMENT",
3914
- triggers: { crons: ["CRON_1", "CRON_2"] },
3915
- usage_model: "bundled",
3916
- env: {
3917
- ENV1: environment1,
3918
- ENV2: environment2,
3919
- },
3920
- };
3921
-
3922
- const result1 = normalizeAndValidateConfig(expectedConfig, undefined, {
3923
- env: "ENV1",
3924
- });
3925
-
3926
- expect(result1.config).toEqual(expect.objectContaining(environment1));
3927
- expect(result1.diagnostics.hasErrors()).toBe(false);
3928
- expect(result1.diagnostics.hasWarnings()).toBe(false);
3929
-
3930
- const result2 = normalizeAndValidateConfig(expectedConfig, undefined, {
3931
- env: "ENV2",
3932
- });
3933
-
3934
- expect(result2.config).toEqual(expect.objectContaining(environment2));
3935
- expect(result2.diagnostics.hasErrors()).toBe(false);
3936
- expect(result2.diagnostics.hasWarnings()).toBe(false);
3937
- });
3938
- });
3939
- });
3940
- });
3941
-
3942
- function normalizePath(text: string): string {
3943
- return text
3944
- .replace("project\\wrangler.toml", "project/wrangler.toml")
3945
- .replace("src\\index.ts", "src/index.ts");
3946
- }