wrangler 0.0.0-e88a54e → 0.0.0-e89ee2a5

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