wrangler 0.0.0-e87ad068 → 0.0.0-e8997b87

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