wrangler 0.0.0-e452a35 → 0.0.0-e4716cc87

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