wrangler 0.0.0-e7cf0caa → 0.0.0-e7ea6005c

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