wrangler 0.0.0-e7a0cd5b → 0.0.0-e7c7235fd

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