wrangler 0.0.0-e1e2ee5c → 0.0.0-e1f2576e

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