wrangler 0.0.0-e0621809 → 0.0.0-e0850ad1

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