wrangler 0.0.0-e6c71262 → 0.0.0-e6ddf8a7

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