wrangler 2.20.0 → 3.0.0

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