wrangler 0.0.0-e41c7e41 → 0.0.0-e44f496a8

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