wrangler 0.0.0-e464fcdb → 0.0.0-e4716cc87

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 (331) hide show
  1. package/README.md +29 -43
  2. package/bin/wrangler.js +13 -102
  3. package/config-schema.json +3305 -0
  4. package/package.json +183 -199
  5. package/templates/__tests__/tsconfig.json +1 -1
  6. package/templates/checked-fetch.js +11 -4
  7. package/templates/facade.d.ts +7 -2
  8. package/templates/gitignore +2 -4
  9. package/templates/init-tests/test-vitest-new-worker.js +1 -1
  10. package/templates/init-tests/test-vitest-new-worker.ts +3 -3
  11. package/templates/middleware/common.ts +9 -4
  12. package/templates/middleware/loader-modules.ts +94 -44
  13. package/templates/middleware/loader-sw.ts +6 -10
  14. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  15. package/templates/middleware/middleware-mock-analytics-engine.d.ts +3 -0
  16. package/templates/middleware/middleware-mock-analytics-engine.ts +30 -0
  17. package/templates/middleware/middleware-patch-console-prefix.d.ts +3 -0
  18. package/templates/middleware/middleware-patch-console-prefix.ts +21 -0
  19. package/templates/middleware/middleware-scheduled.ts +15 -1
  20. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  21. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  22. package/templates/modules-watch-stub.js +4 -0
  23. package/templates/new-worker-scheduled.ts +1 -1
  24. package/templates/new-worker.ts +1 -1
  25. package/templates/pages-dev-pipeline.ts +2 -1
  26. package/templates/pages-dev-util.ts +4 -1
  27. package/templates/pages-shim.ts +0 -3
  28. package/templates/pages-template-plugin.ts +14 -4
  29. package/templates/pages-template-worker.ts +12 -3
  30. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  31. package/templates/startDevWorker/ProxyWorker.ts +336 -0
  32. package/templates/tsconfig.init.json +4 -87
  33. package/templates/tsconfig.json +1 -1
  34. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  35. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  36. package/wrangler-dist/ProxyWorker.js +241 -0
  37. package/wrangler-dist/ProxyWorker.js.map +6 -0
  38. package/wrangler-dist/cli.d.ts +25358 -285
  39. package/wrangler-dist/cli.js +148181 -120816
  40. package/Cloudflare_CA.pem +0 -18
  41. package/import_meta_url.js +0 -3
  42. package/miniflare-config-stubs/.env.empty +0 -0
  43. package/miniflare-config-stubs/package.empty.json +0 -1
  44. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  45. package/miniflare-dist/index.mjs +0 -6442
  46. package/src/__tests__/access.test.ts +0 -25
  47. package/src/__tests__/api-dev.test.ts +0 -238
  48. package/src/__tests__/api-devregistry.test.ts +0 -121
  49. package/src/__tests__/api.test.ts +0 -102
  50. package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
  51. package/src/__tests__/config-cache.test.ts +0 -42
  52. package/src/__tests__/configuration.test.ts +0 -4509
  53. package/src/__tests__/constellation.test.ts +0 -371
  54. package/src/__tests__/d1/d1.test.ts +0 -82
  55. package/src/__tests__/d1/execute.test.ts +0 -66
  56. package/src/__tests__/d1/migrate.test.ts +0 -257
  57. package/src/__tests__/d1/splitter.test.ts +0 -255
  58. package/src/__tests__/delete.test.ts +0 -272
  59. package/src/__tests__/deployments.test.ts +0 -369
  60. package/src/__tests__/dev.test.tsx +0 -1617
  61. package/src/__tests__/generate.test.ts +0 -237
  62. package/src/__tests__/get-host-from-url.test.ts +0 -16
  63. package/src/__tests__/guess-worker-format.test.ts +0 -120
  64. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  65. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  66. package/src/__tests__/helpers/end-event-loop.ts +0 -6
  67. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  68. package/src/__tests__/helpers/mock-auth-domain.ts +0 -20
  69. package/src/__tests__/helpers/mock-bin.ts +0 -36
  70. package/src/__tests__/helpers/mock-console.ts +0 -112
  71. package/src/__tests__/helpers/mock-dialogs.ts +0 -139
  72. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +0 -25
  73. package/src/__tests__/helpers/mock-get-zone-from-host.ts +0 -11
  74. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  75. package/src/__tests__/helpers/mock-istty.ts +0 -74
  76. package/src/__tests__/helpers/mock-known-routes.ts +0 -12
  77. package/src/__tests__/helpers/mock-kv.ts +0 -46
  78. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -263
  79. package/src/__tests__/helpers/mock-process.ts +0 -34
  80. package/src/__tests__/helpers/mock-set-timeout.ts +0 -16
  81. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  82. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  83. package/src/__tests__/helpers/msw/blob-worker.cjs +0 -19
  84. package/src/__tests__/helpers/msw/handlers/access.ts +0 -13
  85. package/src/__tests__/helpers/msw/handlers/deployments.ts +0 -160
  86. package/src/__tests__/helpers/msw/handlers/namespaces.ts +0 -81
  87. package/src/__tests__/helpers/msw/handlers/oauth.ts +0 -31
  88. package/src/__tests__/helpers/msw/handlers/r2.ts +0 -60
  89. package/src/__tests__/helpers/msw/handlers/script.ts +0 -56
  90. package/src/__tests__/helpers/msw/handlers/user.ts +0 -52
  91. package/src/__tests__/helpers/msw/handlers/zones.ts +0 -20
  92. package/src/__tests__/helpers/msw/index.ts +0 -52
  93. package/src/__tests__/helpers/msw/read-file-sync.js +0 -61
  94. package/src/__tests__/helpers/run-in-tmp.ts +0 -38
  95. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  96. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +0 -28
  97. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +0 -1
  98. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +0 -5
  99. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +0 -1
  100. package/src/__tests__/helpers/worker-scripts/parent-worker.js +0 -11
  101. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +0 -5
  102. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  103. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  104. package/src/__tests__/https-options.test.ts +0 -163
  105. package/src/__tests__/index.test.ts +0 -282
  106. package/src/__tests__/init.test.ts +0 -3196
  107. package/src/__tests__/jest.setup.ts +0 -179
  108. package/src/__tests__/kv.test.ts +0 -1799
  109. package/src/__tests__/logger.test.ts +0 -207
  110. package/src/__tests__/logout.test.ts +0 -47
  111. package/src/__tests__/metrics.test.ts +0 -493
  112. package/src/__tests__/middleware.scheduled.test.ts +0 -145
  113. package/src/__tests__/middleware.test.ts +0 -816
  114. package/src/__tests__/mtls-certificates.test.ts +0 -589
  115. package/src/__tests__/package-manager.test.ts +0 -353
  116. package/src/__tests__/pages/deployment-list.test.ts +0 -80
  117. package/src/__tests__/pages/functions-build.test.ts +0 -452
  118. package/src/__tests__/pages/pages.test.ts +0 -81
  119. package/src/__tests__/pages/project-create.test.ts +0 -63
  120. package/src/__tests__/pages/project-list.test.ts +0 -110
  121. package/src/__tests__/pages/project-upload.test.ts +0 -500
  122. package/src/__tests__/pages/publish.test.ts +0 -2864
  123. package/src/__tests__/pages-deployment-tail.test.ts +0 -955
  124. package/src/__tests__/parse.test.ts +0 -436
  125. package/src/__tests__/paths.test.ts +0 -39
  126. package/src/__tests__/publish.test.ts +0 -8849
  127. package/src/__tests__/pubsub.test.ts +0 -496
  128. package/src/__tests__/queues.test.ts +0 -532
  129. package/src/__tests__/r2.test.ts +0 -374
  130. package/src/__tests__/route.test.ts +0 -45
  131. package/src/__tests__/secret.test.ts +0 -693
  132. package/src/__tests__/tail.test.ts +0 -958
  133. package/src/__tests__/test-old-node-version.js +0 -31
  134. package/src/__tests__/traverse-module-graph.test.ts +0 -220
  135. package/src/__tests__/tsconfig-sanity.ts +0 -12
  136. package/src/__tests__/tsconfig.json +0 -8
  137. package/src/__tests__/tsconfig.tsbuildinfo +0 -1
  138. package/src/__tests__/type-generation.test.ts +0 -234
  139. package/src/__tests__/user.test.ts +0 -118
  140. package/src/__tests__/utils-collectKeyValues.test.ts +0 -47
  141. package/src/__tests__/validate-dev-props.test.ts +0 -56
  142. package/src/__tests__/version.test.ts +0 -35
  143. package/src/__tests__/whoami.test.tsx +0 -172
  144. package/src/__tests__/worker-namespace.test.ts +0 -340
  145. package/src/abort.d.ts +0 -3
  146. package/src/api/dev.ts +0 -316
  147. package/src/api/index.ts +0 -11
  148. package/src/api/mtls-certificate.ts +0 -148
  149. package/src/api/pages/create-worker-bundle-contents.ts +0 -76
  150. package/src/api/pages/index.ts +0 -5
  151. package/src/api/pages/publish.tsx +0 -355
  152. package/src/bundle-reporter.ts +0 -68
  153. package/src/bundle.ts +0 -908
  154. package/src/cfetch/index.ts +0 -158
  155. package/src/cfetch/internal.ts +0 -258
  156. package/src/cli.ts +0 -28
  157. package/src/config/README.md +0 -107
  158. package/src/config/config.ts +0 -282
  159. package/src/config/diagnostics.ts +0 -80
  160. package/src/config/environment.ts +0 -618
  161. package/src/config/index.ts +0 -403
  162. package/src/config/validation-helpers.ts +0 -597
  163. package/src/config/validation.ts +0 -2342
  164. package/src/config-cache.ts +0 -85
  165. package/src/constellation/createProject.tsx +0 -51
  166. package/src/constellation/deleteProject.ts +0 -51
  167. package/src/constellation/deleteProjectModel.ts +0 -68
  168. package/src/constellation/index.ts +0 -75
  169. package/src/constellation/listCatalog.tsx +0 -35
  170. package/src/constellation/listModel.tsx +0 -41
  171. package/src/constellation/listProject.tsx +0 -28
  172. package/src/constellation/listRuntime.tsx +0 -28
  173. package/src/constellation/options.ts +0 -17
  174. package/src/constellation/types.ts +0 -17
  175. package/src/constellation/uploadModel.tsx +0 -64
  176. package/src/constellation/utils.ts +0 -90
  177. package/src/create-worker-preview.ts +0 -293
  178. package/src/create-worker-upload-form.ts +0 -359
  179. package/src/d1/backups.tsx +0 -219
  180. package/src/d1/constants.ts +0 -6
  181. package/src/d1/create.tsx +0 -103
  182. package/src/d1/delete.ts +0 -53
  183. package/src/d1/execute.tsx +0 -371
  184. package/src/d1/formatTimeAgo.ts +0 -14
  185. package/src/d1/index.ts +0 -100
  186. package/src/d1/list.tsx +0 -62
  187. package/src/d1/migrations/apply.tsx +0 -235
  188. package/src/d1/migrations/create.tsx +0 -79
  189. package/src/d1/migrations/helpers.ts +0 -171
  190. package/src/d1/migrations/index.ts +0 -3
  191. package/src/d1/migrations/list.tsx +0 -95
  192. package/src/d1/migrations/options.ts +0 -23
  193. package/src/d1/options.ts +0 -22
  194. package/src/d1/splitter.ts +0 -161
  195. package/src/d1/types.ts +0 -32
  196. package/src/d1/utils.ts +0 -49
  197. package/src/delete.ts +0 -100
  198. package/src/deployments.ts +0 -368
  199. package/src/deprecated/index.ts +0 -144
  200. package/src/dev/dev-vars.ts +0 -39
  201. package/src/dev/dev.tsx +0 -600
  202. package/src/dev/get-local-persistence-path.ts +0 -31
  203. package/src/dev/local.tsx +0 -948
  204. package/src/dev/remote.tsx +0 -632
  205. package/src/dev/start-server.ts +0 -534
  206. package/src/dev/use-esbuild.ts +0 -203
  207. package/src/dev/validate-dev-props.ts +0 -40
  208. package/src/dev-registry.ts +0 -202
  209. package/src/dev.tsx +0 -929
  210. package/src/dialogs.ts +0 -136
  211. package/src/dispatch-namespace.ts +0 -211
  212. package/src/docs/helpers.ts +0 -50
  213. package/src/docs/index.ts +0 -54
  214. package/src/durable.ts +0 -102
  215. package/src/entry.ts +0 -337
  216. package/src/environment-variables/factory.ts +0 -89
  217. package/src/environment-variables/misc-variables.ts +0 -30
  218. package/src/errors.ts +0 -11
  219. package/src/generate/index.ts +0 -298
  220. package/src/git-client.ts +0 -135
  221. package/src/global-wrangler-config-path.ts +0 -26
  222. package/src/https-options.ts +0 -127
  223. package/src/index.ts +0 -768
  224. package/src/init.ts +0 -1032
  225. package/src/inspect.ts +0 -782
  226. package/src/intl-polyfill.d.ts +0 -139
  227. package/src/is-ci.ts +0 -14
  228. package/src/is-interactive.ts +0 -16
  229. package/src/jest.d.ts +0 -4
  230. package/src/kv/helpers.ts +0 -433
  231. package/src/kv/index.ts +0 -594
  232. package/src/logger.ts +0 -123
  233. package/src/metrics/index.ts +0 -5
  234. package/src/metrics/metrics-config.ts +0 -239
  235. package/src/metrics/metrics-dispatcher.ts +0 -96
  236. package/src/metrics/metrics-usage-headers.ts +0 -24
  237. package/src/metrics/send-event.ts +0 -99
  238. package/src/miniflare-cli/README.md +0 -30
  239. package/src/miniflare-cli/assets.ts +0 -251
  240. package/src/miniflare-cli/index.ts +0 -210
  241. package/src/miniflare-cli/request-context.ts +0 -40
  242. package/src/miniflare-cli/tsconfig.json +0 -9
  243. package/src/miniflare-cli/tsconfig.tsbuildinfo +0 -1
  244. package/src/miniflare-cli/types.ts +0 -11
  245. package/src/module-collection.ts +0 -333
  246. package/src/mtls-certificate/cli.ts +0 -155
  247. package/src/open-in-browser.ts +0 -17
  248. package/src/package-manager.ts +0 -219
  249. package/src/pages/build.ts +0 -410
  250. package/src/pages/buildFunctions.ts +0 -140
  251. package/src/pages/constants.ts +0 -18
  252. package/src/pages/deployment-tails.ts +0 -281
  253. package/src/pages/deployments.tsx +0 -84
  254. package/src/pages/dev.ts +0 -716
  255. package/src/pages/errors.ts +0 -67
  256. package/src/pages/functions/buildPlugin.ts +0 -113
  257. package/src/pages/functions/buildWorker.ts +0 -291
  258. package/src/pages/functions/filepath-routing.test.ts +0 -234
  259. package/src/pages/functions/filepath-routing.ts +0 -189
  260. package/src/pages/functions/identifiers.ts +0 -78
  261. package/src/pages/functions/routes-consolidation.test.ts +0 -250
  262. package/src/pages/functions/routes-consolidation.ts +0 -73
  263. package/src/pages/functions/routes-transformation.test.ts +0 -282
  264. package/src/pages/functions/routes-transformation.ts +0 -115
  265. package/src/pages/functions/routes-validation.test.ts +0 -403
  266. package/src/pages/functions/routes-validation.ts +0 -202
  267. package/src/pages/functions/routes.ts +0 -151
  268. package/src/pages/functions/tsconfig.json +0 -8
  269. package/src/pages/functions/tsconfig.tsbuildinfo +0 -1
  270. package/src/pages/functions.ts +0 -86
  271. package/src/pages/hash.ts +0 -13
  272. package/src/pages/index.ts +0 -102
  273. package/src/pages/projects.tsx +0 -159
  274. package/src/pages/prompt-select-project.tsx +0 -31
  275. package/src/pages/publish.tsx +0 -267
  276. package/src/pages/types.ts +0 -46
  277. package/src/pages/upload.tsx +0 -469
  278. package/src/pages/utils.ts +0 -23
  279. package/src/parse.ts +0 -308
  280. package/src/paths.ts +0 -71
  281. package/src/proxy.ts +0 -694
  282. package/src/publish/index.ts +0 -274
  283. package/src/publish/publish.ts +0 -1060
  284. package/src/pubsub/index.ts +0 -286
  285. package/src/pubsub/pubsub-commands.ts +0 -623
  286. package/src/queues/cli/commands/consumer/add.ts +0 -71
  287. package/src/queues/cli/commands/consumer/index.ts +0 -19
  288. package/src/queues/cli/commands/consumer/remove.ts +0 -31
  289. package/src/queues/cli/commands/create.ts +0 -25
  290. package/src/queues/cli/commands/delete.ts +0 -26
  291. package/src/queues/cli/commands/index.ts +0 -35
  292. package/src/queues/cli/commands/list.ts +0 -25
  293. package/src/queues/client.ts +0 -136
  294. package/src/queues/utils.ts +0 -18
  295. package/src/r2/constants.ts +0 -4
  296. package/src/r2/helpers.ts +0 -132
  297. package/src/r2/index.ts +0 -289
  298. package/src/routes.ts +0 -140
  299. package/src/secret/index.ts +0 -376
  300. package/src/selfsigned.d.ts +0 -29
  301. package/src/sites.ts +0 -484
  302. package/src/tail/createTail.ts +0 -406
  303. package/src/tail/filters.ts +0 -277
  304. package/src/tail/index.ts +0 -211
  305. package/src/tail/printing.ts +0 -122
  306. package/src/traverse-module-graph.ts +0 -53
  307. package/src/tsconfig-sanity.ts +0 -16
  308. package/src/type-generation.ts +0 -181
  309. package/src/update-check.ts +0 -19
  310. package/src/user/access.ts +0 -68
  311. package/src/user/auth-variables.ts +0 -113
  312. package/src/user/choose-account.tsx +0 -39
  313. package/src/user/generate-auth-url.ts +0 -33
  314. package/src/user/generate-random-state.ts +0 -16
  315. package/src/user/index.ts +0 -2
  316. package/src/user/user.ts +0 -1234
  317. package/src/utils/collectKeyValues.ts +0 -14
  318. package/src/utils/render.ts +0 -93
  319. package/src/whoami.ts +0 -135
  320. package/src/worker.ts +0 -274
  321. package/src/yargs-types.ts +0 -37
  322. package/src/zones.ts +0 -191
  323. package/templates/__tests__/tsconfig.tsbuildinfo +0 -1
  324. package/templates/d1-beta-facade.js +0 -244
  325. package/templates/first-party-worker-module-facade.ts +0 -19
  326. package/templates/format-dev-errors.ts +0 -34
  327. package/templates/serve-static-assets.ts +0 -66
  328. package/templates/service-bindings-module-facade.js +0 -55
  329. package/templates/service-bindings-sw-facade.js +0 -42
  330. package/templates/tsconfig.tsbuildinfo +0 -1
  331. package/wrangler-dist/wasm-sync.wasm +0 -0
@@ -1,1617 +0,0 @@
1
- import * as fs from "node:fs";
2
- import getPort from "get-port";
3
- import { rest } from "msw";
4
- import patchConsole from "patch-console";
5
- import dedent from "ts-dedent";
6
- import Dev from "../dev/dev";
7
- import { CI } from "../is-ci";
8
- import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
9
- import { mockConsoleMethods } from "./helpers/mock-console";
10
- import {
11
- msw,
12
- mswSuccessOauthHandlers,
13
- mswSuccessUserHandlers,
14
- mswZoneHandlers,
15
- } from "./helpers/msw";
16
- import { runInTempDir } from "./helpers/run-in-tmp";
17
- import { runWrangler } from "./helpers/run-wrangler";
18
- import writeWranglerToml from "./helpers/write-wrangler-toml";
19
-
20
- describe("wrangler dev", () => {
21
- beforeEach(() => {
22
- msw.use(
23
- ...mswZoneHandlers,
24
- ...mswSuccessOauthHandlers,
25
- ...mswSuccessUserHandlers
26
- );
27
- });
28
-
29
- runInTempDir();
30
- mockAccountId();
31
- mockApiToken();
32
- const std = mockConsoleMethods();
33
- afterEach(() => {
34
- (Dev as jest.Mock).mockClear();
35
- patchConsole(() => {});
36
- msw.resetHandlers();
37
- });
38
-
39
- describe("authorization", () => {
40
- mockApiToken({ apiToken: null });
41
- const isCISpy = jest.spyOn(CI, "isCI").mockReturnValue(true);
42
-
43
- it("should kick you to the login flow when running wrangler dev in remote mode without authorization", async () => {
44
- fs.writeFileSync("index.js", `export default {};`);
45
- await expect(
46
- runWrangler("dev index.js")
47
- ).rejects.toThrowErrorMatchingInlineSnapshot(
48
- `"You must be logged in to use wrangler dev in remote mode. Try logging in, or run wrangler dev --local."`
49
- );
50
- });
51
-
52
- isCISpy.mockClear();
53
- });
54
-
55
- describe("compatibility-date", () => {
56
- it("should not warn if there is no wrangler.toml and no compatibility-date specified", async () => {
57
- fs.writeFileSync("index.js", `export default {};`);
58
- await runWrangler("dev index.js");
59
- expect(std.out).toMatchInlineSnapshot(`""`);
60
- expect(std.warn).toMatchInlineSnapshot(`""`);
61
- expect(std.err).toMatchInlineSnapshot(`""`);
62
- });
63
-
64
- it("should warn if there is a wrangler.toml but no compatibility-date", async () => {
65
- writeWranglerToml({
66
- main: "index.js",
67
- compatibility_date: undefined,
68
- });
69
- fs.writeFileSync("index.js", `export default {};`);
70
- await runWrangler("dev");
71
- const currentDate = new Date().toISOString().substring(0, 10);
72
- expect(std.out).toMatchInlineSnapshot(`""`);
73
- expect(std.warn.replaceAll(currentDate, "<current-date>"))
74
- .toMatchInlineSnapshot(`
75
- "▲ [WARNING] No compatibility_date was specified. Using today's date: <current-date>.
76
-
77
- Add one to your wrangler.toml file:
78
- \`\`\`
79
- compatibility_date = \\"<current-date>\\"
80
- \`\`\`
81
- or pass it in your terminal:
82
- \`\`\`
83
- --compatibility-date=<current-date>
84
- \`\`\`
85
- See https://developers.cloudflare.com/workers/platform/compatibility-dates/ for more information.
86
-
87
- "
88
- `);
89
- expect(std.err).toMatchInlineSnapshot(`""`);
90
- });
91
-
92
- it("should not warn if there is a wrangler.toml but compatibility-date is specified at the command line", async () => {
93
- writeWranglerToml({
94
- main: "index.js",
95
- compatibility_date: undefined,
96
- });
97
- fs.writeFileSync("index.js", `export default {};`);
98
- await runWrangler("dev --compatibility-date=2020-01-01");
99
- expect(std.out).toMatchInlineSnapshot(`""`);
100
- expect(std.warn).toMatchInlineSnapshot(`""`);
101
- expect(std.err).toMatchInlineSnapshot(`""`);
102
- });
103
- });
104
-
105
- describe("usage-model", () => {
106
- it("should read wrangler.toml's usage_model", async () => {
107
- writeWranglerToml({
108
- main: "index.js",
109
- usage_model: "unbound",
110
- });
111
- fs.writeFileSync("index.js", `export default {};`);
112
- await runWrangler("dev");
113
- expect((Dev as jest.Mock).mock.calls[0][0].usageModel).toEqual("unbound");
114
- });
115
-
116
- it("should read wrangler.toml's usage_model in local mode", async () => {
117
- writeWranglerToml({
118
- main: "index.js",
119
- usage_model: "unbound",
120
- });
121
- fs.writeFileSync("index.js", `export default {};`);
122
- await runWrangler("dev --local");
123
- expect((Dev as jest.Mock).mock.calls[0][0].usageModel).toEqual("unbound");
124
- });
125
- });
126
-
127
- describe("entry-points", () => {
128
- it("should error if there is no entry-point specified", async () => {
129
- writeWranglerToml();
130
-
131
- await expect(
132
- runWrangler("dev")
133
- ).rejects.toThrowErrorMatchingInlineSnapshot(
134
- `"Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler dev path/to/script\`) or the \`main\` config field."`
135
- );
136
-
137
- expect(std.out).toMatchInlineSnapshot(`
138
- "
139
- If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
140
- `);
141
- expect(std.err).toMatchInlineSnapshot(`
142
- "X [ERROR] Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler dev path/to/script\`) or the \`main\` config field.
143
-
144
- "
145
- `);
146
- });
147
-
148
- it("should use `main` from the top-level environment", async () => {
149
- writeWranglerToml({
150
- main: "index.js",
151
- });
152
- fs.writeFileSync("index.js", `export default {};`);
153
- await runWrangler("dev");
154
- expect((Dev as jest.Mock).mock.calls[0][0].entry.file).toMatch(
155
- /index\.js$/
156
- );
157
- expect(std.out).toMatchInlineSnapshot(`""`);
158
- expect(std.warn).toMatchInlineSnapshot(`""`);
159
- expect(std.err).toMatchInlineSnapshot(`""`);
160
- });
161
-
162
- it("should use `main` from a named environment", async () => {
163
- writeWranglerToml({
164
- env: {
165
- ENV1: {
166
- main: "index.js",
167
- },
168
- },
169
- });
170
- fs.writeFileSync("index.js", `export default {};`);
171
- await runWrangler("dev --env=ENV1");
172
- expect((Dev as jest.Mock).mock.calls[0][0].entry.file).toMatch(
173
- /index\.js$/
174
- );
175
- expect(std.out).toMatchInlineSnapshot(`""`);
176
- expect(std.warn).toMatchInlineSnapshot(`""`);
177
- expect(std.err).toMatchInlineSnapshot(`""`);
178
- });
179
-
180
- it("should use `main` from a named environment, rather than the top-level", async () => {
181
- writeWranglerToml({
182
- main: "other.js",
183
- env: {
184
- ENV1: {
185
- main: "index.js",
186
- },
187
- },
188
- });
189
- fs.writeFileSync("index.js", `export default {};`);
190
- await runWrangler("dev --env=ENV1");
191
- expect((Dev as jest.Mock).mock.calls[0][0].entry.file).toMatch(
192
- /index\.js$/
193
- );
194
- expect(std.out).toMatchInlineSnapshot(`""`);
195
- expect(std.warn).toMatchInlineSnapshot(`""`);
196
- expect(std.err).toMatchInlineSnapshot(`""`);
197
- });
198
- });
199
-
200
- describe("routes", () => {
201
- it("should pass routes to <Dev/>", async () => {
202
- fs.writeFileSync("index.js", `export default {};`);
203
-
204
- // config.routes
205
- mockGetZones("5.some-host.com", [{ id: "some-zone-id-5" }]);
206
- writeWranglerToml({
207
- main: "index.js",
208
- routes: ["http://5.some-host.com/some/path/*"],
209
- });
210
- await runWrangler("dev");
211
- expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
212
- expect.objectContaining({
213
- host: "5.some-host.com",
214
- zone: "some-zone-id-5",
215
- routes: ["http://5.some-host.com/some/path/*"],
216
- })
217
- );
218
- });
219
- });
220
- describe("host", () => {
221
- it("should resolve a host to its zone", async () => {
222
- writeWranglerToml({
223
- main: "index.js",
224
- });
225
- fs.writeFileSync("index.js", `export default {};`);
226
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
227
- await runWrangler("dev --host some-host.com");
228
- expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
229
- expect.objectContaining({
230
- host: "some-host.com",
231
- zone: "some-zone-id",
232
- })
233
- );
234
- });
235
-
236
- it("should read wrangler.toml's dev.host", async () => {
237
- writeWranglerToml({
238
- main: "index.js",
239
- dev: {
240
- host: "some-host.com",
241
- },
242
- });
243
- fs.writeFileSync("index.js", `export default {};`);
244
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
245
- await runWrangler("dev");
246
- expect((Dev as jest.Mock).mock.calls[0][0].host).toEqual("some-host.com");
247
- });
248
-
249
- it("should read --route", async () => {
250
- writeWranglerToml({
251
- main: "index.js",
252
- });
253
- fs.writeFileSync("index.js", `export default {};`);
254
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
255
- await runWrangler("dev --route http://some-host.com/some/path/*");
256
- expect((Dev as jest.Mock).mock.calls[0][0].host).toEqual("some-host.com");
257
- });
258
-
259
- it("should read wrangler.toml's routes", async () => {
260
- writeWranglerToml({
261
- main: "index.js",
262
- routes: [
263
- "http://some-host.com/some/path/*",
264
- "http://some-other-host.com/path/*",
265
- ],
266
- });
267
- fs.writeFileSync("index.js", `export default {};`);
268
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
269
- await runWrangler("dev");
270
- expect((Dev as jest.Mock).mock.calls[0][0].host).toEqual("some-host.com");
271
- });
272
-
273
- it("should read wrangler.toml's environment specific routes", async () => {
274
- writeWranglerToml({
275
- main: "index.js",
276
- routes: [
277
- "http://a-host.com/some/path/*",
278
- "http://another-host.com/path/*",
279
- ],
280
- env: {
281
- staging: {
282
- routes: [
283
- "http://some-host.com/some/path/*",
284
- "http://some-other-host.com/path/*",
285
- ],
286
- },
287
- },
288
- });
289
- fs.writeFileSync("index.js", `export default {};`);
290
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
291
- await runWrangler("dev --env staging");
292
- expect((Dev as jest.Mock).mock.calls[0][0].host).toEqual("some-host.com");
293
- });
294
-
295
- it("should strip leading `*` from given host when deducing a zone id", async () => {
296
- writeWranglerToml({
297
- main: "index.js",
298
- route: "*some-host.com/some/path/*",
299
- });
300
- fs.writeFileSync("index.js", `export default {};`);
301
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
302
- await runWrangler("dev");
303
- expect((Dev as jest.Mock).mock.calls[0][0].host).toEqual("some-host.com");
304
- });
305
-
306
- it("should strip leading `*.` from given host when deducing a zone id", async () => {
307
- writeWranglerToml({
308
- main: "index.js",
309
- route: "*.some-host.com/some/path/*",
310
- });
311
- fs.writeFileSync("index.js", `export default {};`);
312
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
313
- await runWrangler("dev");
314
- expect((Dev as jest.Mock).mock.calls[0][0].host).toEqual("some-host.com");
315
- });
316
-
317
- it("should, when provided, use a configured zone_id", async () => {
318
- writeWranglerToml({
319
- main: "index.js",
320
- routes: [
321
- { pattern: "https://some-domain.com/*", zone_id: "some-zone-id" },
322
- ],
323
- });
324
- fs.writeFileSync("index.js", `export default {};`);
325
- await runWrangler("dev");
326
- expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
327
- expect.objectContaining({
328
- host: "some-domain.com",
329
- zone: "some-zone-id",
330
- })
331
- );
332
- });
333
-
334
- it("should, when provided, use a zone_name to get a zone_id", async () => {
335
- writeWranglerToml({
336
- main: "index.js",
337
- routes: [
338
- {
339
- pattern: "https://some-zone.com/*",
340
- zone_name: "some-zone.com",
341
- },
342
- ],
343
- });
344
- fs.writeFileSync("index.js", `export default {};`);
345
- mockGetZones("some-zone.com", [{ id: "a-zone-id" }]);
346
- await runWrangler("dev");
347
- expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
348
- expect.objectContaining({
349
- // note that it uses the provided zone_name as a host too
350
- host: "some-zone.com",
351
- zone: "a-zone-id",
352
- })
353
- );
354
- });
355
-
356
- it("should find the host from the given pattern, not zone_name", async () => {
357
- writeWranglerToml({
358
- main: "index.js",
359
- routes: [
360
- {
361
- pattern: "https://subdomain.exists.com/*",
362
- zone_name: "does-not-exist.com",
363
- },
364
- ],
365
- });
366
- await fs.promises.writeFile("index.js", `export default {};`);
367
- await runWrangler("dev");
368
- expect(std.out).toMatchInlineSnapshot(`""`);
369
- expect(std.err).toMatchInlineSnapshot(`""`);
370
- });
371
-
372
- it("should fail for non-existing zones", async () => {
373
- writeWranglerToml({
374
- main: "index.js",
375
- routes: [
376
- {
377
- pattern: "https://subdomain.does-not-exist.com/*",
378
- zone_name: "exists.com",
379
- },
380
- ],
381
- });
382
- await fs.promises.writeFile("index.js", `export default {};`);
383
- await expect(runWrangler("dev")).rejects.toEqual(
384
- new Error("Could not find zone for subdomain.does-not-exist.com")
385
- );
386
- });
387
-
388
- it("should fail for non-existing zones, when falling back from */*", async () => {
389
- writeWranglerToml({
390
- main: "index.js",
391
- routes: [
392
- {
393
- pattern: "*/*",
394
- zone_name: "does-not-exist.com",
395
- },
396
- ],
397
- });
398
- await fs.promises.writeFile("index.js", `export default {};`);
399
- await expect(runWrangler("dev")).rejects.toEqual(
400
- new Error("Could not find zone for does-not-exist.com")
401
- );
402
- });
403
-
404
- it("should fallback to zone_name when given the pattern */*", async () => {
405
- writeWranglerToml({
406
- main: "index.js",
407
- routes: [
408
- {
409
- pattern: "*/*",
410
- zone_name: "exists.com",
411
- },
412
- ],
413
- });
414
- await fs.promises.writeFile("index.js", `export default {};`);
415
- await runWrangler("dev");
416
- expect(std.out).toMatchInlineSnapshot(`""`);
417
- expect(std.err).toMatchInlineSnapshot(`""`);
418
- });
419
- it("fails when given the pattern */* and no zone_name", async () => {
420
- writeWranglerToml({
421
- main: "index.js",
422
- routes: [
423
- {
424
- pattern: "*/*",
425
- zone_id: "exists-com",
426
- },
427
- ],
428
- });
429
- await fs.promises.writeFile("index.js", `export default {};`);
430
- const err = new TypeError() as unknown as { code: string; input: string };
431
- err.code = "ERR_INVALID_URL";
432
- err.input = "http:///";
433
-
434
- await expect(runWrangler("dev")).rejects.toEqual(err);
435
- });
436
-
437
- it("given a long host, it should use the longest subdomain that resolves to a zone", async () => {
438
- writeWranglerToml({
439
- main: "index.js",
440
- });
441
- fs.writeFileSync("index.js", `export default {};`);
442
-
443
- msw.use(
444
- rest.get("*/zones", (req, res, ctx) => {
445
- let zone: [] | [{ id: "some-zone-id" }] = [];
446
- if (
447
- req.url.searchParams.get("name") === "111.222.333.some-host.com"
448
- ) {
449
- zone = [];
450
- } else if (
451
- req.url.searchParams.get("name") === "222.333.some-host.com"
452
- ) {
453
- zone = [];
454
- } else if (req.url.searchParams.get("name") === "333.some-host.com") {
455
- zone = [{ id: "some-zone-id" }];
456
- }
457
-
458
- return res(
459
- ctx.status(200),
460
- ctx.json({
461
- success: true,
462
- errors: [],
463
- messages: [],
464
- result: zone,
465
- })
466
- );
467
- })
468
- );
469
-
470
- await runWrangler("dev --host 111.222.333.some-host.com");
471
-
472
- const devMockCall = (Dev as jest.Mock).mock.calls[0][0];
473
-
474
- expect(devMockCall).toHaveProperty("host", "111.222.333.some-host.com");
475
- expect(devMockCall).toHaveProperty(
476
- "localUpstream",
477
- "111.222.333.some-host.com"
478
- );
479
- expect(devMockCall).toHaveProperty("zone", "some-zone-id");
480
- });
481
-
482
- it("should, in order, use args.host/config.dev.host/args.routes/(config.route|config.routes)", async () => {
483
- // This test might seem like it's testing implementation details, but let's be specific and consider it a spec
484
-
485
- fs.writeFileSync("index.js", `export default {};`);
486
-
487
- // config.routes
488
- mockGetZones("5.some-host.com", [{ id: "some-zone-id-5" }]);
489
- writeWranglerToml({
490
- main: "index.js",
491
- routes: ["http://5.some-host.com/some/path/*"],
492
- });
493
- await runWrangler("dev");
494
- expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
495
- expect.objectContaining({
496
- host: "5.some-host.com",
497
- zone: "some-zone-id-5",
498
- })
499
- );
500
- (Dev as jest.Mock).mockClear();
501
-
502
- // config.route
503
- mockGetZones("4.some-host.com", [{ id: "some-zone-id-4" }]);
504
- writeWranglerToml({
505
- main: "index.js",
506
- route: "https://4.some-host.com/some/path/*",
507
- });
508
- await runWrangler("dev");
509
- expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
510
- expect.objectContaining({
511
- host: "4.some-host.com",
512
- zone: "some-zone-id-4",
513
- })
514
- );
515
- (Dev as jest.Mock).mockClear();
516
-
517
- // --routes
518
- mockGetZones("3.some-host.com", [{ id: "some-zone-id-3" }]);
519
- writeWranglerToml({
520
- main: "index.js",
521
- route: "https://4.some-host.com/some/path/*",
522
- });
523
- await runWrangler("dev --routes http://3.some-host.com/some/path/*");
524
- expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
525
- expect.objectContaining({
526
- host: "3.some-host.com",
527
- zone: "some-zone-id-3",
528
- })
529
- );
530
- (Dev as jest.Mock).mockClear();
531
-
532
- // config.dev.host
533
- mockGetZones("2.some-host.com", [{ id: "some-zone-id-2" }]);
534
- writeWranglerToml({
535
- main: "index.js",
536
- dev: {
537
- host: `2.some-host.com`,
538
- },
539
- route: "4.some-host.com/some/path/*",
540
- });
541
- await runWrangler("dev --routes http://3.some-host.com/some/path/*");
542
- expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
543
- expect.objectContaining({
544
- host: "2.some-host.com",
545
- zone: "some-zone-id-2",
546
- })
547
- );
548
- (Dev as jest.Mock).mockClear();
549
-
550
- // --host
551
- mockGetZones("1.some-host.com", [{ id: "some-zone-id-1" }]);
552
- writeWranglerToml({
553
- main: "index.js",
554
- dev: {
555
- host: `2.some-host.com`,
556
- },
557
- route: "4.some-host.com/some/path/*",
558
- });
559
- await runWrangler(
560
- "dev --routes http://3.some-host.com/some/path/* --host 1.some-host.com"
561
- );
562
- expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
563
- expect.objectContaining({
564
- host: "1.some-host.com",
565
- zone: "some-zone-id-1",
566
- })
567
- );
568
- (Dev as jest.Mock).mockClear();
569
- });
570
-
571
- it("should error if a host can't resolve to a zone", async () => {
572
- writeWranglerToml({
573
- main: "index.js",
574
- });
575
- fs.writeFileSync("index.js", `export default {};`);
576
- mockGetZones("some-host.com", []);
577
- await expect(
578
- runWrangler("dev --host some-host.com")
579
- ).rejects.toThrowErrorMatchingInlineSnapshot(
580
- `"Could not find zone for some-host.com"`
581
- );
582
- });
583
-
584
- it("should not try to resolve a zone when starting in local mode", async () => {
585
- writeWranglerToml({
586
- main: "index.js",
587
- });
588
- fs.writeFileSync("index.js", `export default {};`);
589
- await runWrangler("dev --host some-host.com --local");
590
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual(undefined);
591
- });
592
- });
593
-
594
- describe("local upstream", () => {
595
- it("should use dev.host from toml by default", async () => {
596
- writeWranglerToml({
597
- main: "index.js",
598
- dev: {
599
- host: `2.some-host.com`,
600
- },
601
- });
602
- fs.writeFileSync("index.js", `export default {};`);
603
- await runWrangler("dev --local");
604
- expect((Dev as jest.Mock).mock.calls[0][0].localUpstream).toEqual(
605
- "2.some-host.com"
606
- );
607
- });
608
-
609
- it("should use route from toml by default", async () => {
610
- writeWranglerToml({
611
- main: "index.js",
612
- route: "https://4.some-host.com/some/path/*",
613
- });
614
- fs.writeFileSync("index.js", `export default {};`);
615
- await runWrangler("dev --local");
616
- expect((Dev as jest.Mock).mock.calls[0][0].host).toEqual(
617
- "4.some-host.com"
618
- );
619
- });
620
-
621
- it("should respect the option when provided", async () => {
622
- writeWranglerToml({
623
- main: "index.js",
624
- route: `2.some-host.com`,
625
- });
626
- fs.writeFileSync("index.js", `export default {};`);
627
- await runWrangler("dev --local-upstream some-host.com --local");
628
- expect((Dev as jest.Mock).mock.calls[0][0].localUpstream).toEqual(
629
- "some-host.com"
630
- );
631
- });
632
- });
633
-
634
- describe("custom builds", () => {
635
- it("should run a custom build before starting `dev`", async () => {
636
- writeWranglerToml({
637
- build: {
638
- command: `node -e "4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')"`,
639
- },
640
- });
641
-
642
- await runWrangler("dev index.js");
643
-
644
- expect(fs.readFileSync("index.js", "utf-8")).toMatchInlineSnapshot(
645
- `"export default { fetch(){ return new Response(123) } }"`
646
- );
647
-
648
- // and the command would pass through
649
- expect((Dev as jest.Mock).mock.calls[0][0].build).toEqual({
650
- command:
651
- "node -e \"4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\"",
652
- cwd: undefined,
653
- watch_dir: "src",
654
- });
655
- expect(std.out).toMatchInlineSnapshot(
656
- `"Running custom build: node -e \\"4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\""`
657
- );
658
- expect(std.err).toMatchInlineSnapshot(`""`);
659
- expect(std.warn).toMatchInlineSnapshot(`""`);
660
- });
661
-
662
- if (process.platform !== "win32") {
663
- it("should run a custom build of multiple steps combined by && before starting `dev`", async () => {
664
- writeWranglerToml({
665
- build: {
666
- command: `echo "export default { fetch(){ return new Response(123) } }" > index.js`,
667
- },
668
- });
669
-
670
- await runWrangler("dev index.js");
671
-
672
- expect(fs.readFileSync("index.js", "utf-8")).toMatchInlineSnapshot(`
673
- "export default { fetch(){ return new Response(123) } }
674
- "
675
- `);
676
-
677
- expect(std.out).toMatchInlineSnapshot(
678
- `"Running custom build: echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js"`
679
- );
680
- expect(std.err).toMatchInlineSnapshot(`""`);
681
- expect(std.warn).toMatchInlineSnapshot(`""`);
682
- });
683
- }
684
-
685
- it("should throw an error if the entry doesn't exist after the build finishes", async () => {
686
- writeWranglerToml({
687
- main: "index.js",
688
- build: {
689
- command: `node -e "4+4;"`,
690
- },
691
- });
692
-
693
- await expect(runWrangler("dev")).rejects
694
- .toThrowErrorMatchingInlineSnapshot(`
695
- "The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"4+4;\\".
696
- The \`main\` property in wrangler.toml should point to the file generated by the custom build."
697
- `);
698
- expect(std.out).toMatchInlineSnapshot(`
699
- "Running custom build: node -e \\"4+4;\\"
700
-
701
- If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
702
- `);
703
- expect(std.err).toMatchInlineSnapshot(`
704
- "X [ERROR] The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"4+4;\\".
705
-
706
- The \`main\` property in wrangler.toml should point to the file generated by the custom build.
707
-
708
- "
709
- `);
710
- expect(std.warn).toMatchInlineSnapshot(`""`);
711
- });
712
-
713
- describe(".env", () => {
714
- beforeEach(() => {
715
- fs.writeFileSync(".env", "CUSTOM_BUILD_VAR=default");
716
- fs.writeFileSync(".env.custom", "CUSTOM_BUILD_VAR=custom");
717
- fs.writeFileSync("index.js", `export default {};`);
718
- writeWranglerToml({
719
- main: "index.js",
720
- env: { custom: {} },
721
- build: {
722
- // Ideally, we'd just log the var here and match it in `std.out`,
723
- // but stdout from custom builds is piped directly to
724
- // `process.stdout` which we don't capture.
725
- command: `node -e "require('fs').writeFileSync('var.txt', process.env.CUSTOM_BUILD_VAR)"`,
726
- },
727
- });
728
-
729
- // We won't overwrite existing process.env keys with .env values (to
730
- // allow .env overrides to specified on then shell), so make sure this
731
- // key definitely doesn't exist.
732
- delete process.env.CUSTOM_BUILD_VAR;
733
- });
734
-
735
- it("should load environment variables from `.env`", async () => {
736
- await runWrangler("dev");
737
- const output = fs.readFileSync("var.txt", "utf8");
738
- expect(output).toMatch("default");
739
- });
740
- it("should prefer to load environment variables from `.env.<environment>` if `--env <environment>` is set", async () => {
741
- await runWrangler("dev --env custom");
742
- const output = fs.readFileSync("var.txt", "utf8");
743
- expect(output).toMatch("custom");
744
- });
745
- });
746
- });
747
-
748
- describe("upstream-protocol", () => {
749
- it("should default upstream-protocol to `https`", async () => {
750
- writeWranglerToml({
751
- main: "index.js",
752
- });
753
- fs.writeFileSync("index.js", `export default {};`);
754
- await runWrangler("dev");
755
- expect((Dev as jest.Mock).mock.calls[0][0].upstreamProtocol).toEqual(
756
- "https"
757
- );
758
- expect(std.out).toMatchInlineSnapshot(`""`);
759
- expect(std.warn).toMatchInlineSnapshot(`""`);
760
- expect(std.err).toMatchInlineSnapshot(`""`);
761
- });
762
-
763
- it("should warn if `--upstream-protocol=http` is used", async () => {
764
- writeWranglerToml({
765
- main: "index.js",
766
- });
767
- fs.writeFileSync("index.js", `export default {};`);
768
- await runWrangler("dev --upstream-protocol=http");
769
- expect((Dev as jest.Mock).mock.calls[0][0].upstreamProtocol).toEqual(
770
- "http"
771
- );
772
- expect(std.out).toMatchInlineSnapshot(`""`);
773
- expect(std.warn).toMatchInlineSnapshot(`
774
- "▲ [WARNING] Setting upstream-protocol to http is not currently implemented.
775
-
776
- If this is required in your project, please add your use case to the following issue:
777
- https://github.com/cloudflare/workers-sdk/issues/583.
778
-
779
- "
780
- `);
781
- expect(std.err).toMatchInlineSnapshot(`""`);
782
- });
783
- });
784
-
785
- describe("local-protocol", () => {
786
- it("should default local-protocol to `http`", async () => {
787
- writeWranglerToml({
788
- main: "index.js",
789
- });
790
- fs.writeFileSync("index.js", `export default {};`);
791
- await runWrangler("dev");
792
- expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual("http");
793
- expect(std.out).toMatchInlineSnapshot(`""`);
794
- expect(std.warn).toMatchInlineSnapshot(`""`);
795
- expect(std.err).toMatchInlineSnapshot(`""`);
796
- });
797
-
798
- it("should use `local_protocol` from `wrangler.toml`, if available", async () => {
799
- writeWranglerToml({
800
- main: "index.js",
801
- dev: {
802
- local_protocol: "https",
803
- },
804
- });
805
- fs.writeFileSync("index.js", `export default {};`);
806
- await runWrangler("dev");
807
- expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual(
808
- "https"
809
- );
810
- expect(std.out).toMatchInlineSnapshot(`""`);
811
- expect(std.warn).toMatchInlineSnapshot(`""`);
812
- expect(std.err).toMatchInlineSnapshot(`""`);
813
- });
814
-
815
- it("should use --local-protocol command line arg, if provided", async () => {
816
- // Here we show that the command line overrides the wrangler.toml by
817
- // setting the config to https, and then setting it back to http on the command line.
818
- writeWranglerToml({
819
- main: "index.js",
820
- dev: {
821
- local_protocol: "https",
822
- },
823
- });
824
- fs.writeFileSync("index.js", `export default {};`);
825
- await runWrangler("dev --local-protocol=http");
826
- expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual("http");
827
- expect(std.out).toMatchInlineSnapshot(`""`);
828
- expect(std.warn).toMatchInlineSnapshot(`""`);
829
- expect(std.err).toMatchInlineSnapshot(`""`);
830
- });
831
- });
832
-
833
- describe("ip", () => {
834
- it("should default ip to 0.0.0.0", async () => {
835
- writeWranglerToml({
836
- main: "index.js",
837
- });
838
- fs.writeFileSync("index.js", `export default {};`);
839
- await runWrangler("dev");
840
- expect((Dev as jest.Mock).mock.calls[0][0].initialIp).toEqual("0.0.0.0");
841
- expect(std.out).toMatchInlineSnapshot(`""`);
842
- expect(std.warn).toMatchInlineSnapshot(`""`);
843
- expect(std.err).toMatchInlineSnapshot(`""`);
844
- });
845
-
846
- it("should use to `ip` from `wrangler.toml`, if available", async () => {
847
- writeWranglerToml({
848
- main: "index.js",
849
- dev: {
850
- ip: "1.2.3.4",
851
- },
852
- });
853
- fs.writeFileSync("index.js", `export default {};`);
854
- await runWrangler("dev");
855
- expect((Dev as jest.Mock).mock.calls[0][0].initialIp).toEqual("1.2.3.4");
856
- expect(std.out).toMatchInlineSnapshot(`""`);
857
- expect(std.warn).toMatchInlineSnapshot(`""`);
858
- expect(std.err).toMatchInlineSnapshot(`""`);
859
- });
860
-
861
- it("should use --ip command line arg, if provided", async () => {
862
- writeWranglerToml({
863
- main: "index.js",
864
- dev: {
865
- ip: "1.2.3.4",
866
- },
867
- });
868
- fs.writeFileSync("index.js", `export default {};`);
869
- await runWrangler("dev --ip=5.6.7.8");
870
- expect((Dev as jest.Mock).mock.calls[0][0].initialIp).toEqual("5.6.7.8");
871
- expect(std.out).toMatchInlineSnapshot(`""`);
872
- expect(std.warn).toMatchInlineSnapshot(`""`);
873
- expect(std.err).toMatchInlineSnapshot(`""`);
874
- });
875
- });
876
-
877
- describe("inspector port", () => {
878
- it("should connect WebSocket server with --experimental-local", async () => {
879
- writeWranglerToml({
880
- main: "./index.js",
881
- });
882
- fs.writeFileSync(
883
- "index.js",
884
- `export default {
885
- async fetch(request, env, ctx ){
886
- console.log('Hello World LOGGING');
887
- },
888
- };`
889
- );
890
- await runWrangler("dev --experimental-local");
891
-
892
- expect((Dev as jest.Mock).mock.calls[0][0].inspectorPort).toEqual(9229);
893
- expect(std).toMatchInlineSnapshot(`
894
- Object {
895
- "debug": "",
896
- "err": "",
897
- "info": "",
898
- "out": "",
899
- "warn": "",
900
- }
901
- `);
902
- });
903
-
904
- it("should use 9229 as the default port", async () => {
905
- writeWranglerToml({
906
- main: "index.js",
907
- });
908
- fs.writeFileSync("index.js", `export default {};`);
909
- await runWrangler("dev");
910
- expect((Dev as jest.Mock).mock.calls[0][0].inspectorPort).toEqual(9229);
911
- expect(std).toMatchInlineSnapshot(`
912
- Object {
913
- "debug": "",
914
- "err": "",
915
- "info": "",
916
- "out": "",
917
- "warn": "",
918
- }
919
- `);
920
- });
921
-
922
- it("should read --inspector-port", async () => {
923
- writeWranglerToml({
924
- main: "index.js",
925
- });
926
- fs.writeFileSync("index.js", `export default {};`);
927
- await runWrangler("dev --inspector-port=9999");
928
- expect((Dev as jest.Mock).mock.calls[0][0].inspectorPort).toEqual(9999);
929
- expect(std).toMatchInlineSnapshot(`
930
- Object {
931
- "debug": "",
932
- "err": "",
933
- "info": "",
934
- "out": "",
935
- "warn": "",
936
- }
937
- `);
938
- });
939
-
940
- it("should read dev.inspector_port from wrangler.toml", async () => {
941
- writeWranglerToml({
942
- main: "index.js",
943
- dev: {
944
- inspector_port: 9999,
945
- },
946
- });
947
- fs.writeFileSync("index.js", `export default {};`);
948
- await runWrangler("dev");
949
- expect((Dev as jest.Mock).mock.calls[0][0].inspectorPort).toEqual(9999);
950
- expect(std).toMatchInlineSnapshot(`
951
- Object {
952
- "debug": "",
953
- "err": "",
954
- "info": "",
955
- "out": "",
956
- "warn": "",
957
- }
958
- `);
959
- });
960
-
961
- it("should error if a bad dev.inspector_port config is provided", async () => {
962
- writeWranglerToml({
963
- main: "index.js",
964
- dev: {
965
- // @ts-expect-error intentionally bad port
966
- inspector_port: "some string",
967
- },
968
- });
969
- fs.writeFileSync("index.js", `export default {};`);
970
- await expect(runWrangler("dev")).rejects
971
- .toThrowErrorMatchingInlineSnapshot(`
972
- "Processing wrangler.toml configuration:
973
- - Expected \\"dev.inspector_port\\" to be of type number but got \\"some string\\"."
974
- `);
975
- });
976
- });
977
-
978
- describe("port", () => {
979
- it("should default port to 8787 if it is not in use", async () => {
980
- writeWranglerToml({
981
- main: "index.js",
982
- });
983
- fs.writeFileSync("index.js", `export default {};`);
984
- await runWrangler("dev");
985
- expect((Dev as jest.Mock).mock.calls[0][0].initialPort).toEqual(8787);
986
- expect(std.out).toMatchInlineSnapshot(`""`);
987
- expect(std.warn).toMatchInlineSnapshot(`""`);
988
- expect(std.err).toMatchInlineSnapshot(`""`);
989
- });
990
-
991
- it("should use `port` from `wrangler.toml`, if available", async () => {
992
- writeWranglerToml({
993
- main: "index.js",
994
- dev: {
995
- port: 8888,
996
- },
997
- });
998
- fs.writeFileSync("index.js", `export default {};`);
999
- // Mock `getPort()` to resolve to a completely different port.
1000
- (getPort as jest.Mock).mockResolvedValue(98765);
1001
-
1002
- await runWrangler("dev");
1003
- expect((Dev as jest.Mock).mock.calls[0][0].initialPort).toEqual(8888);
1004
- expect(std.out).toMatchInlineSnapshot(`""`);
1005
- expect(std.warn).toMatchInlineSnapshot(`""`);
1006
- expect(std.err).toMatchInlineSnapshot(`""`);
1007
- });
1008
-
1009
- it("should error if a bad dev.port config is provided", async () => {
1010
- writeWranglerToml({
1011
- main: "index.js",
1012
- dev: {
1013
- // @ts-expect-error intentionally bad port
1014
- port: "some string",
1015
- },
1016
- });
1017
- fs.writeFileSync("index.js", `export default {};`);
1018
- await expect(runWrangler("dev")).rejects
1019
- .toThrowErrorMatchingInlineSnapshot(`
1020
- "Processing wrangler.toml configuration:
1021
- - Expected \\"dev.port\\" to be of type number but got \\"some string\\"."
1022
- `);
1023
- });
1024
-
1025
- it("should use --port command line arg, if provided", async () => {
1026
- writeWranglerToml({
1027
- main: "index.js",
1028
- dev: {
1029
- port: 8888,
1030
- },
1031
- });
1032
- fs.writeFileSync("index.js", `export default {};`);
1033
- // Mock `getPort()` to resolve to a completely different port.
1034
- (getPort as jest.Mock).mockResolvedValue(98765);
1035
-
1036
- await runWrangler("dev --port=9999");
1037
- expect((Dev as jest.Mock).mock.calls[0][0].initialPort).toEqual(9999);
1038
- expect(std.out).toMatchInlineSnapshot(`""`);
1039
- expect(std.warn).toMatchInlineSnapshot(`""`);
1040
- expect(std.err).toMatchInlineSnapshot(`""`);
1041
- });
1042
-
1043
- it("should use a different port to the default if it is in use", async () => {
1044
- writeWranglerToml({
1045
- main: "index.js",
1046
- });
1047
- fs.writeFileSync("index.js", `export default {};`);
1048
- // Mock `getPort()` to resolve to a completely different port.
1049
- (getPort as jest.Mock).mockResolvedValue(98765);
1050
-
1051
- await runWrangler("dev");
1052
- expect((Dev as jest.Mock).mock.calls[0][0].initialPort).toEqual(98765);
1053
- expect(std.out).toMatchInlineSnapshot(`""`);
1054
- expect(std.warn).toMatchInlineSnapshot(`""`);
1055
- expect(std.err).toMatchInlineSnapshot(`""`);
1056
- });
1057
- });
1058
-
1059
- describe("durable_objects", () => {
1060
- it("should warn if there are remote Durable Objects, or missing migrations for local Durable Objects", async () => {
1061
- writeWranglerToml({
1062
- main: "index.js",
1063
- durable_objects: {
1064
- bindings: [
1065
- { name: "NAME_1", class_name: "CLASS_1" },
1066
- {
1067
- name: "NAME_2",
1068
- class_name: "CLASS_2",
1069
- script_name: "SCRIPT_A",
1070
- },
1071
- { name: "NAME_3", class_name: "CLASS_3" },
1072
- {
1073
- name: "NAME_4",
1074
- class_name: "CLASS_4",
1075
- script_name: "SCRIPT_B",
1076
- },
1077
- ],
1078
- },
1079
- });
1080
- fs.writeFileSync("index.js", `export default {};`);
1081
- await runWrangler("dev");
1082
- expect((Dev as jest.Mock).mock.calls[0][0].initialIp).toEqual("0.0.0.0");
1083
- expect(std.out).toMatchInlineSnapshot(`
1084
- "Your worker has access to the following bindings:
1085
- - Durable Objects:
1086
- - NAME_1: CLASS_1
1087
- - NAME_2: CLASS_2 (defined in SCRIPT_A)
1088
- - NAME_3: CLASS_3
1089
- - NAME_4: CLASS_4 (defined in SCRIPT_B)"
1090
- `);
1091
- expect(std.warn).toMatchInlineSnapshot(`
1092
- "▲ [WARNING] Processing wrangler.toml configuration:
1093
-
1094
- - In wrangler.toml, you have configured [durable_objects] exported by this Worker (CLASS_1,
1095
- CLASS_3), but no [migrations] for them. This may not work as expected until you add a [migrations]
1096
- section to your wrangler.toml. Add this configuration to your wrangler.toml:
1097
-
1098
- \`\`\`
1099
- [[migrations]]
1100
- tag = \\"v1\\" # Should be unique for each entry
1101
- new_classes = [\\"CLASS_1\\", \\"CLASS_3\\"]
1102
- \`\`\`
1103
-
1104
- Refer to
1105
- https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml
1106
- for more details.
1107
-
1108
-
1109
- ▲ [WARNING] WARNING: You have Durable Object bindings that are not defined locally in the worker being developed.
1110
-
1111
- Be aware that changes to the data stored in these Durable Objects will be permanent and affect the
1112
- live instances.
1113
- Remote Durable Objects that are affected:
1114
- - {\\"name\\":\\"NAME_2\\",\\"class_name\\":\\"CLASS_2\\",\\"script_name\\":\\"SCRIPT_A\\"}
1115
- - {\\"name\\":\\"NAME_4\\",\\"class_name\\":\\"CLASS_4\\",\\"script_name\\":\\"SCRIPT_B\\"}
1116
-
1117
- "
1118
- `);
1119
- expect(std.err).toMatchInlineSnapshot(`""`);
1120
- });
1121
- });
1122
-
1123
- describe(".dev.vars", () => {
1124
- it("should override `vars` bindings from `wrangler.toml` with values in `.dev.vars`", async () => {
1125
- fs.writeFileSync("index.js", `export default {};`);
1126
-
1127
- const localVarsEnvContent = dedent`
1128
- # Preceding comment
1129
- VAR_1="var #1 value" # End of line comment
1130
- VAR_3="var #3 value"
1131
- VAR_MULTI_LINE_1="A: line 1
1132
- line 2"
1133
- VAR_MULTI_LINE_2="B: line 1\\nline 2"
1134
- EMPTY=
1135
- UNQUOTED= unquoted value
1136
- `;
1137
- fs.writeFileSync(".dev.vars", localVarsEnvContent, "utf8");
1138
-
1139
- writeWranglerToml({
1140
- main: "index.js",
1141
- vars: {
1142
- VAR_1: "original value 1",
1143
- VAR_2: "original value 2", // should not get overridden
1144
- VAR_3: "original value 3",
1145
- VAR_MULTI_LINE_1: "original multi-line 1",
1146
- VAR_MULTI_LINE_2: "original multi-line 2",
1147
- EMPTY: "original empty",
1148
- UNQUOTED: "original unquoted",
1149
- },
1150
- });
1151
- await runWrangler("dev");
1152
- const varBindings: Record<string, unknown> = (Dev as jest.Mock).mock
1153
- .calls[0][0].bindings.vars;
1154
-
1155
- expect(varBindings).toEqual({
1156
- VAR_1: "var #1 value",
1157
- VAR_2: "original value 2",
1158
- VAR_3: "var #3 value",
1159
- VAR_MULTI_LINE_1: "A: line 1\nline 2",
1160
- VAR_MULTI_LINE_2: "B: line 1\nline 2",
1161
- EMPTY: "",
1162
- UNQUOTED: "unquoted value", // Note that whitespace is trimmed
1163
- });
1164
- expect(std.out).toMatchInlineSnapshot(`
1165
- "Using vars defined in .dev.vars
1166
- Your worker has access to the following bindings:
1167
- - Vars:
1168
- - VAR_1: \\"(hidden)\\"
1169
- - VAR_2: \\"original value 2\\"
1170
- - VAR_3: \\"(hidden)\\"
1171
- - VAR_MULTI_LINE_1: \\"(hidden)\\"
1172
- - VAR_MULTI_LINE_2: \\"(hidden)\\"
1173
- - EMPTY: \\"(hidden)\\"
1174
- - UNQUOTED: \\"(hidden)\\""
1175
- `);
1176
- expect(std.warn).toMatchInlineSnapshot(`""`);
1177
- expect(std.err).toMatchInlineSnapshot(`""`);
1178
- });
1179
-
1180
- it("should prefer `.dev.vars.<environment>` if `--env <environment> set`", async () => {
1181
- fs.writeFileSync("index.js", `export default {};`);
1182
- fs.writeFileSync(".dev.vars", "DEFAULT_VAR=default");
1183
- fs.writeFileSync(".dev.vars.custom", "CUSTOM_VAR=custom");
1184
-
1185
- writeWranglerToml({ main: "index.js", env: { custom: {} } });
1186
- await runWrangler("dev --env custom");
1187
- const varBindings: Record<string, unknown> = (Dev as jest.Mock).mock
1188
- .calls[0][0].bindings.vars;
1189
-
1190
- expect(varBindings).toEqual({ CUSTOM_VAR: "custom" });
1191
- expect(std.out).toMatchInlineSnapshot(`
1192
- "Using vars defined in .dev.vars.custom
1193
- Your worker has access to the following bindings:
1194
- - Vars:
1195
- - CUSTOM_VAR: \\"(hidden)\\""
1196
- `);
1197
- expect(std.warn).toMatchInlineSnapshot(`""`);
1198
- expect(std.err).toMatchInlineSnapshot(`""`);
1199
- });
1200
- });
1201
-
1202
- describe("serve static assets", () => {
1203
- it("should error if --site is used with no value", async () => {
1204
- await expect(
1205
- runWrangler("dev --site")
1206
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1207
- `"Not enough arguments following: site"`
1208
- );
1209
-
1210
- expect(std).toMatchInlineSnapshot(`
1211
- Object {
1212
- "debug": "",
1213
- "err": "X [ERROR] Not enough arguments following: site
1214
-
1215
- ",
1216
- "info": "",
1217
- "out": "
1218
- wrangler dev [script]
1219
-
1220
- 👂 Start a local server for developing your worker
1221
-
1222
- Positionals:
1223
- script The path to an entry point for your worker [string]
1224
-
1225
- Flags:
1226
- -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
1227
- -c, --config Path to .toml configuration file [string]
1228
- -e, --env Environment to use for operations and .env files [string]
1229
- -h, --help Show help [boolean]
1230
- -v, --version Show version number [boolean]
1231
-
1232
- Options:
1233
- --name Name of the worker [string]
1234
- --no-bundle Skip internal build steps and directly publish script [boolean] [default: false]
1235
- --compatibility-date Date to use for compatibility checks [string]
1236
- --compatibility-flags, --compatibility-flag Flags to use for compatibility checks [array]
1237
- --latest Use the latest version of the worker runtime [boolean] [default: true]
1238
- --ip IP address to listen on [string]
1239
- --port Port to listen on [number]
1240
- --inspector-port Port for devtools to connect to [number]
1241
- --routes, --route Routes to upload [array]
1242
- --host Host to forward requests to, defaults to the zone of project [string]
1243
- --local-protocol Protocol to listen to requests on, defaults to http. [choices: \\"http\\", \\"https\\"]
1244
- --local-upstream Host to act as origin in local mode, defaults to dev.host or route [string]
1245
- --assets Static assets to be served [string]
1246
- --site Root folder of static assets for Workers Sites [string]
1247
- --site-include Array of .gitignore-style patterns that match file or directory names from the sites directory. Only matched items will be uploaded. [array]
1248
- --site-exclude Array of .gitignore-style patterns that match file or directory names from the sites directory. Matched items will not be uploaded. [array]
1249
- --upstream-protocol Protocol to forward requests to host on, defaults to https. [choices: \\"http\\", \\"https\\"]
1250
- --var A key-value pair to be injected into the script as a variable [array]
1251
- --define A key-value pair to be substituted in the script [array]
1252
- --jsx-factory The function that is called for each JSX element [string]
1253
- --jsx-fragment The function that is called for each JSX fragment [string]
1254
- --tsconfig Path to a custom tsconfig.json file [string]
1255
- -l, --local Run on my machine [boolean] [default: false]
1256
- --experimental-local Run on my machine using the Cloudflare Workers runtime [boolean] [default: false]
1257
- --experimental-local-remote-kv Read/write KV data from/to real namespaces on the Cloudflare network [boolean] [default: false]
1258
- --minify Minify the script [boolean]
1259
- --node-compat Enable Node.js compatibility [boolean]
1260
- --persist Enable persistence for local mode, using default path: .wrangler/state [boolean]
1261
- --persist-to Specify directory to use for local persistence (implies --persist) [string]
1262
- --live-reload Auto reload HTML pages when change is detected in local mode [boolean]
1263
- --test-scheduled Test scheduled events by visiting /__scheduled in browser [boolean] [default: false]
1264
- --log-level Specify logging level [choices: \\"debug\\", \\"info\\", \\"log\\", \\"warn\\", \\"error\\", \\"none\\"] [default: \\"log\\"]",
1265
- "warn": "",
1266
- }
1267
- `);
1268
- });
1269
-
1270
- it("should error if --assets and --site are used together", async () => {
1271
- writeWranglerToml({
1272
- main: "./index.js",
1273
- });
1274
- fs.writeFileSync("index.js", `export default {};`);
1275
- await expect(
1276
- runWrangler("dev --assets abc --site xyz")
1277
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1278
- `"Cannot use Assets and Workers Sites in the same Worker."`
1279
- );
1280
- });
1281
-
1282
- it("should error if --assets and config.site are used together", async () => {
1283
- writeWranglerToml({
1284
- main: "./index.js",
1285
- site: {
1286
- bucket: "xyz",
1287
- },
1288
- });
1289
- fs.writeFileSync("index.js", `export default {};`);
1290
- await expect(
1291
- runWrangler("dev --assets abc")
1292
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1293
- `"Cannot use Assets and Workers Sites in the same Worker."`
1294
- );
1295
- });
1296
-
1297
- it("should error if config.assets and --site are used together", async () => {
1298
- writeWranglerToml({
1299
- main: "./index.js",
1300
- // @ts-expect-error we allow string inputs here
1301
- assets: "abc",
1302
- });
1303
- fs.writeFileSync("index.js", `export default {};`);
1304
- await expect(
1305
- runWrangler("dev --site xyz")
1306
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1307
- `"Cannot use Assets and Workers Sites in the same Worker."`
1308
- );
1309
- });
1310
-
1311
- it("should error if config.assets and config.site are used together", async () => {
1312
- writeWranglerToml({
1313
- main: "./index.js",
1314
- // @ts-expect-error we allow string inputs here
1315
- assets: "abc",
1316
- site: {
1317
- bucket: "xyz",
1318
- },
1319
- });
1320
- fs.writeFileSync("index.js", `export default {};`);
1321
- await expect(
1322
- runWrangler("dev --assets abc")
1323
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1324
- `"Cannot use Assets and Workers Sites in the same Worker."`
1325
- );
1326
- });
1327
-
1328
- it("should indicate whether Sites is being used", async () => {
1329
- writeWranglerToml({
1330
- main: "index.js",
1331
- });
1332
- fs.writeFileSync("index.js", `export default {};`);
1333
-
1334
- await runWrangler("dev");
1335
- expect((Dev as jest.Mock).mock.calls[0][0].isWorkersSite).toEqual(false);
1336
-
1337
- await runWrangler("dev --site abc");
1338
- expect((Dev as jest.Mock).mock.calls[1][0].isWorkersSite).toEqual(true);
1339
-
1340
- await runWrangler("dev --assets abc");
1341
- expect((Dev as jest.Mock).mock.calls[2][0].isWorkersSite).toEqual(false);
1342
- });
1343
- it("should warn if --assets is used", async () => {
1344
- writeWranglerToml({
1345
- main: "./index.js",
1346
- });
1347
- fs.writeFileSync("index.js", `export default {};`);
1348
-
1349
- await runWrangler('dev --assets "./assets"');
1350
- expect(std).toMatchInlineSnapshot(`
1351
- Object {
1352
- "debug": "",
1353
- "err": "",
1354
- "info": "",
1355
- "out": "",
1356
- "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1357
-
1358
- ",
1359
- }
1360
- `);
1361
- });
1362
-
1363
- it("should warn if config.assets is used", async () => {
1364
- writeWranglerToml({
1365
- main: "./index.js",
1366
- // @ts-expect-error we allow string inputs here
1367
- assets: "./assets",
1368
- });
1369
- fs.writeFileSync("index.js", `export default {};`);
1370
-
1371
- await runWrangler("dev");
1372
- expect(std).toMatchInlineSnapshot(`
1373
- Object {
1374
- "debug": "",
1375
- "err": "",
1376
- "info": "",
1377
- "out": "",
1378
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1379
-
1380
- - \\"assets\\" fields are experimental and may change or break at any time.
1381
-
1382
- ",
1383
- }
1384
- `);
1385
- });
1386
- });
1387
-
1388
- describe("--inspect", () => {
1389
- it("should warn if --inspect is used", async () => {
1390
- fs.writeFileSync("index.js", `export default {};`);
1391
- await runWrangler("dev index.js --inspect");
1392
- expect(std).toMatchInlineSnapshot(`
1393
- Object {
1394
- "debug": "",
1395
- "err": "",
1396
- "info": "",
1397
- "out": "",
1398
- "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1399
-
1400
- ",
1401
- }
1402
- `);
1403
- });
1404
-
1405
- it("should default to true, without a warning", async () => {
1406
- fs.writeFileSync("index.js", `export default {};`);
1407
- await runWrangler("dev index.js");
1408
- expect((Dev as jest.Mock).mock.calls[0][0].inspect).toEqual(true);
1409
- expect(std).toMatchInlineSnapshot(`
1410
- Object {
1411
- "debug": "",
1412
- "err": "",
1413
- "info": "",
1414
- "out": "",
1415
- "warn": "",
1416
- }
1417
- `);
1418
- });
1419
-
1420
- it("should pass true, with a warning", async () => {
1421
- fs.writeFileSync("index.js", `export default {};`);
1422
- await runWrangler("dev index.js --inspect");
1423
- expect((Dev as jest.Mock).mock.calls[0][0].inspect).toEqual(true);
1424
- expect(std).toMatchInlineSnapshot(`
1425
- Object {
1426
- "debug": "",
1427
- "err": "",
1428
- "info": "",
1429
- "out": "",
1430
- "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1431
-
1432
- ",
1433
- }
1434
- `);
1435
- });
1436
-
1437
- it("should pass false, without a warning", async () => {
1438
- fs.writeFileSync("index.js", `export default {};`);
1439
- await runWrangler("dev index.js --inspect false");
1440
- expect((Dev as jest.Mock).mock.calls[0][0].inspect).toEqual(false);
1441
- expect(std).toMatchInlineSnapshot(`
1442
- Object {
1443
- "debug": "",
1444
- "err": "",
1445
- "info": "",
1446
- "out": "",
1447
- "warn": "",
1448
- }
1449
- `);
1450
- });
1451
- });
1452
-
1453
- describe("--log-level", () => {
1454
- it("should not output warnings with log-level 'none'", async () => {
1455
- fs.writeFileSync("index.js", `export default {};`);
1456
- await runWrangler("dev index.js --inspect --log-level none");
1457
- expect(std).toMatchInlineSnapshot(`
1458
- Object {
1459
- "debug": "",
1460
- "err": "",
1461
- "info": "",
1462
- "out": "",
1463
- "warn": "",
1464
- }
1465
- `);
1466
- });
1467
-
1468
- it("should output warnings with log-level 'warn'", async () => {
1469
- fs.writeFileSync("index.js", `export default {};`);
1470
- await runWrangler("dev index.js --inspect --log-level warn");
1471
- expect(std).toMatchInlineSnapshot(`
1472
- Object {
1473
- "debug": "",
1474
- "err": "",
1475
- "info": "",
1476
- "out": "",
1477
- "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1478
-
1479
- ",
1480
- }
1481
- `);
1482
- });
1483
-
1484
- it("should not output Errors with log-level error", async () => {
1485
- fs.writeFileSync("index.js", `export default {};`);
1486
- await runWrangler("dev index.js --inspect --log-level debug");
1487
- expect(std.debug.length > 1).toBe(true);
1488
- });
1489
- });
1490
-
1491
- describe("service bindings", () => {
1492
- it("should warn when using service bindings", async () => {
1493
- writeWranglerToml({
1494
- services: [
1495
- { binding: "WorkerA", service: "A" },
1496
- { binding: "WorkerB", service: "B", environment: "staging" },
1497
- ],
1498
- });
1499
- fs.writeFileSync("index.js", `export default {};`);
1500
- await runWrangler("dev index.js");
1501
- expect(std.out).toMatchInlineSnapshot(`
1502
- "Your worker has access to the following bindings:
1503
- - Services:
1504
- - WorkerA: A
1505
- - WorkerB: B - staging"
1506
- `);
1507
- expect(std.warn).toMatchInlineSnapshot(`
1508
- "▲ [WARNING] Processing wrangler.toml configuration:
1509
-
1510
- - \\"services\\" fields are experimental and may change or break at any time.
1511
-
1512
-
1513
- ▲ [WARNING] This worker is bound to live services: WorkerA (A), WorkerB (B@staging)
1514
-
1515
- "
1516
- `);
1517
- expect(std.err).toMatchInlineSnapshot(`""`);
1518
- });
1519
- });
1520
-
1521
- describe("print bindings", () => {
1522
- it("should print bindings", async () => {
1523
- writeWranglerToml({
1524
- services: [
1525
- { binding: "WorkerA", service: "A" },
1526
- { binding: "WorkerB", service: "B", environment: "staging" },
1527
- ],
1528
- });
1529
- fs.writeFileSync("index.js", `export default {};`);
1530
- await runWrangler("dev index.js");
1531
- expect(std).toMatchInlineSnapshot(`
1532
- Object {
1533
- "debug": "",
1534
- "err": "",
1535
- "info": "",
1536
- "out": "Your worker has access to the following bindings:
1537
- - Services:
1538
- - WorkerA: A
1539
- - WorkerB: B - staging",
1540
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1541
-
1542
- - \\"services\\" fields are experimental and may change or break at any time.
1543
-
1544
-
1545
- ▲ [WARNING] This worker is bound to live services: WorkerA (A), WorkerB (B@staging)
1546
-
1547
- ",
1548
- }
1549
- `);
1550
- });
1551
-
1552
- it("should mask vars that were overriden in .dev.vars", async () => {
1553
- writeWranglerToml({
1554
- vars: {
1555
- variable: 123,
1556
- overriden: "original values",
1557
- },
1558
- });
1559
- fs.writeFileSync(
1560
- ".dev.vars",
1561
- `
1562
- SECRET = "A secret"
1563
- overriden = "overriden value"
1564
- `
1565
- );
1566
- fs.writeFileSync("index.js", `export default {};`);
1567
- await runWrangler("dev index.js");
1568
- expect(std).toMatchInlineSnapshot(`
1569
- Object {
1570
- "debug": "",
1571
- "err": "",
1572
- "info": "",
1573
- "out": "Using vars defined in .dev.vars
1574
- Your worker has access to the following bindings:
1575
- - Vars:
1576
- - variable: 123
1577
- - overriden: \\"(hidden)\\"
1578
- - SECRET: \\"(hidden)\\"",
1579
- "warn": "",
1580
- }
1581
- `);
1582
- });
1583
- });
1584
-
1585
- describe("`nodejs_compat` compatibility flag", () => {
1586
- it("should conflict with the --node-compat option", async () => {
1587
- writeWranglerToml();
1588
- fs.writeFileSync("index.js", `export default {};`);
1589
-
1590
- await expect(
1591
- runWrangler(
1592
- "dev index.js --compatibility-flag=nodejs_compat --node-compat"
1593
- )
1594
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1595
- `"The \`nodejs_compat\` compatibility flag cannot be used in conjunction with the legacy \`--node-compat\` flag. If you want to use the Workers runtime Node.js compatibility features, please remove the \`--node-compat\` argument from your CLI command or \`node_compat = true\` from your config file."`
1596
- );
1597
- });
1598
- });
1599
- });
1600
-
1601
- function mockGetZones(domain: string, zones: { id: string }[] = []) {
1602
- msw.use(
1603
- rest.get("*/zones", (req, res, ctx) => {
1604
- expect([...req.url.searchParams.entries()]).toEqual([["name", domain]]);
1605
-
1606
- return res(
1607
- ctx.status(200),
1608
- ctx.json({
1609
- success: true,
1610
- errors: [],
1611
- messages: [],
1612
- result: zones,
1613
- })
1614
- );
1615
- })
1616
- );
1617
- }