wrangler 0.0.0-e6e1daba → 0.0.0-e739b7fe

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