wrangler 0.0.0-e6e1daba → 0.0.0-e739b7fe

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. package/README.md +10 -12
  2. package/bin/wrangler.js +14 -75
  3. package/package.json +226 -194
  4. package/templates/__tests__/tsconfig.json +1 -1
  5. package/templates/checked-fetch.js +10 -3
  6. package/templates/facade.d.ts +4 -1
  7. package/templates/gitignore +0 -4
  8. package/templates/init-tests/test-vitest-new-worker.js +1 -1
  9. package/templates/init-tests/test-vitest-new-worker.ts +1 -1
  10. package/templates/middleware/common.ts +9 -4
  11. package/templates/middleware/loader-modules.ts +67 -15
  12. package/templates/middleware/loader-sw.ts +6 -10
  13. package/templates/middleware/middleware-d1-beta.d.ts +3 -0
  14. package/templates/middleware/middleware-ensure-req-body-drained.ts +19 -0
  15. package/templates/middleware/middleware-miniflare3-json-error.ts +18 -5
  16. package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
  17. package/templates/middleware/middleware-multiworker-dev.ts +68 -0
  18. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  19. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  20. package/templates/modules-watch-stub.js +4 -0
  21. package/templates/new-worker-scheduled.ts +1 -1
  22. package/templates/new-worker.ts +1 -1
  23. package/templates/pages-dev-pipeline.ts +2 -1
  24. package/templates/pages-dev-util.ts +4 -1
  25. package/templates/pages-shim.ts +0 -3
  26. package/templates/pages-template-plugin.ts +12 -2
  27. package/templates/pages-template-worker.ts +11 -2
  28. package/templates/startDevWorker/InspectorProxyWorker.ts +661 -0
  29. package/templates/startDevWorker/ProxyWorker.ts +326 -0
  30. package/templates/tsconfig.init.json +1 -2
  31. package/templates/tsconfig.json +1 -1
  32. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  33. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  34. package/wrangler-dist/ProxyWorker.js +237 -0
  35. package/wrangler-dist/ProxyWorker.js.map +6 -0
  36. package/wrangler-dist/cli.d.ts +22647 -337
  37. package/wrangler-dist/cli.js +137196 -118219
  38. package/wrangler-dist/wasm-sync.wasm +0 -0
  39. package/import_meta_url.js +0 -3
  40. package/miniflare-config-stubs/.env.empty +0 -0
  41. package/miniflare-config-stubs/package.empty.json +0 -1
  42. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  43. package/miniflare-dist/index.mjs +0 -6368
  44. package/src/__tests__/access.test.ts +0 -25
  45. package/src/__tests__/api-dev.test.ts +0 -238
  46. package/src/__tests__/api-devregistry.test.js +0 -64
  47. package/src/__tests__/api.test.ts +0 -80
  48. package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
  49. package/src/__tests__/config-cache.test.ts +0 -42
  50. package/src/__tests__/configuration.test.ts +0 -4233
  51. package/src/__tests__/d1/d1.test.ts +0 -82
  52. package/src/__tests__/d1/execute.test.ts +0 -64
  53. package/src/__tests__/d1/migrate.test.ts +0 -155
  54. package/src/__tests__/d1/splitter.test.ts +0 -255
  55. package/src/__tests__/delete.test.ts +0 -266
  56. package/src/__tests__/deployments.test.ts +0 -129
  57. package/src/__tests__/dev.test.tsx +0 -1587
  58. package/src/__tests__/generate.test.ts +0 -238
  59. package/src/__tests__/get-host-from-url.test.ts +0 -16
  60. package/src/__tests__/guess-worker-format.test.ts +0 -120
  61. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  62. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  63. package/src/__tests__/helpers/end-event-loop.ts +0 -6
  64. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  65. package/src/__tests__/helpers/mock-auth-domain.ts +0 -20
  66. package/src/__tests__/helpers/mock-bin.ts +0 -36
  67. package/src/__tests__/helpers/mock-console.ts +0 -106
  68. package/src/__tests__/helpers/mock-dialogs.ts +0 -139
  69. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +0 -25
  70. package/src/__tests__/helpers/mock-get-zone-from-host.ts +0 -11
  71. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  72. package/src/__tests__/helpers/mock-istty.ts +0 -74
  73. package/src/__tests__/helpers/mock-known-routes.ts +0 -12
  74. package/src/__tests__/helpers/mock-kv.ts +0 -46
  75. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -263
  76. package/src/__tests__/helpers/mock-process.ts +0 -34
  77. package/src/__tests__/helpers/mock-set-timeout.ts +0 -16
  78. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  79. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  80. package/src/__tests__/helpers/msw/blob-worker.cjs +0 -19
  81. package/src/__tests__/helpers/msw/handlers/access.ts +0 -13
  82. package/src/__tests__/helpers/msw/handlers/deployments.ts +0 -93
  83. package/src/__tests__/helpers/msw/handlers/namespaces.ts +0 -81
  84. package/src/__tests__/helpers/msw/handlers/oauth.ts +0 -31
  85. package/src/__tests__/helpers/msw/handlers/r2.ts +0 -60
  86. package/src/__tests__/helpers/msw/handlers/script.ts +0 -56
  87. package/src/__tests__/helpers/msw/handlers/user.ts +0 -52
  88. package/src/__tests__/helpers/msw/handlers/zones.ts +0 -20
  89. package/src/__tests__/helpers/msw/index.ts +0 -50
  90. package/src/__tests__/helpers/msw/read-file-sync.js +0 -61
  91. package/src/__tests__/helpers/run-in-tmp.ts +0 -38
  92. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  93. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +0 -28
  94. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +0 -1
  95. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +0 -5
  96. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +0 -1
  97. package/src/__tests__/helpers/worker-scripts/parent-worker.js +0 -8
  98. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +0 -5
  99. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  100. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  101. package/src/__tests__/https-options.test.ts +0 -163
  102. package/src/__tests__/index.test.ts +0 -274
  103. package/src/__tests__/init.test.ts +0 -3164
  104. package/src/__tests__/jest.setup.ts +0 -175
  105. package/src/__tests__/kv.test.ts +0 -1799
  106. package/src/__tests__/logger.test.ts +0 -141
  107. package/src/__tests__/logout.test.ts +0 -47
  108. package/src/__tests__/metrics.test.ts +0 -493
  109. package/src/__tests__/middleware.scheduled.test.ts +0 -145
  110. package/src/__tests__/middleware.test.ts +0 -815
  111. package/src/__tests__/mtls-certificates.test.ts +0 -585
  112. package/src/__tests__/package-manager.test.ts +0 -353
  113. package/src/__tests__/pages/deployment-list.test.ts +0 -78
  114. package/src/__tests__/pages/functions-build.test.ts +0 -402
  115. package/src/__tests__/pages/pages.test.ts +0 -81
  116. package/src/__tests__/pages/project-create.test.ts +0 -63
  117. package/src/__tests__/pages/project-list.test.ts +0 -108
  118. package/src/__tests__/pages/project-upload.test.ts +0 -481
  119. package/src/__tests__/pages/publish.test.ts +0 -2745
  120. package/src/__tests__/pages-deployment-tail.test.ts +0 -955
  121. package/src/__tests__/parse.test.ts +0 -436
  122. package/src/__tests__/paths.test.ts +0 -39
  123. package/src/__tests__/publish.test.ts +0 -8167
  124. package/src/__tests__/pubsub.test.ts +0 -493
  125. package/src/__tests__/queues.test.ts +0 -529
  126. package/src/__tests__/r2.test.ts +0 -374
  127. package/src/__tests__/route.test.ts +0 -45
  128. package/src/__tests__/secret.test.ts +0 -693
  129. package/src/__tests__/tail.test.ts +0 -958
  130. package/src/__tests__/test-old-node-version.js +0 -31
  131. package/src/__tests__/tsconfig-sanity.ts +0 -12
  132. package/src/__tests__/tsconfig.json +0 -8
  133. package/src/__tests__/tsconfig.tsbuildinfo +0 -1
  134. package/src/__tests__/type-generation.test.ts +0 -233
  135. package/src/__tests__/user.test.ts +0 -118
  136. package/src/__tests__/utils-collectKeyValues.test.ts +0 -47
  137. package/src/__tests__/validate-dev-props.test.ts +0 -56
  138. package/src/__tests__/version.test.ts +0 -35
  139. package/src/__tests__/whoami.test.tsx +0 -172
  140. package/src/__tests__/worker-namespace.test.ts +0 -339
  141. package/src/abort.d.ts +0 -3
  142. package/src/api/dev.ts +0 -328
  143. package/src/api/index.ts +0 -11
  144. package/src/api/mtls-certificate.ts +0 -148
  145. package/src/api/pages/create-worker-bundle-contents.ts +0 -75
  146. package/src/api/pages/index.ts +0 -5
  147. package/src/api/pages/publish.tsx +0 -368
  148. package/src/bundle-reporter.ts +0 -68
  149. package/src/bundle.ts +0 -877
  150. package/src/cfetch/index.ts +0 -158
  151. package/src/cfetch/internal.ts +0 -258
  152. package/src/cli.ts +0 -28
  153. package/src/config/README.md +0 -107
  154. package/src/config/config.ts +0 -282
  155. package/src/config/diagnostics.ts +0 -80
  156. package/src/config/environment.ts +0 -586
  157. package/src/config/index.ts +0 -375
  158. package/src/config/validation-helpers.ts +0 -597
  159. package/src/config/validation.ts +0 -2198
  160. package/src/config-cache.ts +0 -85
  161. package/src/create-worker-preview.ts +0 -293
  162. package/src/create-worker-upload-form.ts +0 -334
  163. package/src/d1/backups.tsx +0 -215
  164. package/src/d1/constants.ts +0 -2
  165. package/src/d1/create.tsx +0 -64
  166. package/src/d1/delete.ts +0 -53
  167. package/src/d1/execute.tsx +0 -354
  168. package/src/d1/formatTimeAgo.ts +0 -14
  169. package/src/d1/index.ts +0 -100
  170. package/src/d1/list.tsx +0 -60
  171. package/src/d1/migrations/apply.tsx +0 -206
  172. package/src/d1/migrations/create.tsx +0 -76
  173. package/src/d1/migrations/helpers.ts +0 -172
  174. package/src/d1/migrations/index.ts +0 -3
  175. package/src/d1/migrations/list.tsx +0 -92
  176. package/src/d1/migrations/options.ts +0 -23
  177. package/src/d1/options.ts +0 -22
  178. package/src/d1/splitter.ts +0 -161
  179. package/src/d1/types.ts +0 -25
  180. package/src/d1/utils.ts +0 -49
  181. package/src/delete.ts +0 -100
  182. package/src/deployments.ts +0 -116
  183. package/src/deprecated/index.ts +0 -144
  184. package/src/dev/dev-vars.ts +0 -39
  185. package/src/dev/dev.tsx +0 -600
  186. package/src/dev/get-local-persistence-path.ts +0 -31
  187. package/src/dev/local.tsx +0 -922
  188. package/src/dev/remote.tsx +0 -632
  189. package/src/dev/start-server.ts +0 -538
  190. package/src/dev/use-esbuild.ts +0 -205
  191. package/src/dev/validate-dev-props.ts +0 -31
  192. package/src/dev-registry.ts +0 -201
  193. package/src/dev.tsx +0 -914
  194. package/src/dialogs.ts +0 -136
  195. package/src/dispatch-namespace.ts +0 -211
  196. package/src/docs/index.ts +0 -97
  197. package/src/durable.ts +0 -102
  198. package/src/entry.ts +0 -327
  199. package/src/environment-variables/factory.ts +0 -88
  200. package/src/environment-variables/misc-variables.ts +0 -30
  201. package/src/errors.ts +0 -11
  202. package/src/generate/index.ts +0 -298
  203. package/src/git-client.ts +0 -135
  204. package/src/global-wrangler-config-path.ts +0 -26
  205. package/src/https-options.ts +0 -127
  206. package/src/index.ts +0 -705
  207. package/src/init.ts +0 -1022
  208. package/src/inspect.ts +0 -782
  209. package/src/intl-polyfill.d.ts +0 -139
  210. package/src/is-ci.ts +0 -14
  211. package/src/is-interactive.ts +0 -16
  212. package/src/jest.d.ts +0 -4
  213. package/src/kv/helpers.ts +0 -430
  214. package/src/kv/index.ts +0 -594
  215. package/src/logger.ts +0 -104
  216. package/src/metrics/index.ts +0 -5
  217. package/src/metrics/metrics-config.ts +0 -239
  218. package/src/metrics/metrics-dispatcher.ts +0 -96
  219. package/src/metrics/metrics-usage-headers.ts +0 -24
  220. package/src/metrics/send-event.ts +0 -98
  221. package/src/miniflare-cli/README.md +0 -30
  222. package/src/miniflare-cli/assets.ts +0 -251
  223. package/src/miniflare-cli/index.ts +0 -210
  224. package/src/miniflare-cli/request-context.ts +0 -40
  225. package/src/miniflare-cli/tsconfig.json +0 -9
  226. package/src/miniflare-cli/tsconfig.tsbuildinfo +0 -1
  227. package/src/miniflare-cli/types.ts +0 -11
  228. package/src/module-collection.ts +0 -267
  229. package/src/mtls-certificate/cli.ts +0 -155
  230. package/src/open-in-browser.ts +0 -17
  231. package/src/package-manager.ts +0 -219
  232. package/src/pages/build.ts +0 -232
  233. package/src/pages/buildFunctions.ts +0 -130
  234. package/src/pages/constants.ts +0 -18
  235. package/src/pages/deployment-tails.ts +0 -281
  236. package/src/pages/deployments.tsx +0 -86
  237. package/src/pages/dev.ts +0 -716
  238. package/src/pages/errors.ts +0 -66
  239. package/src/pages/functions/buildPlugin.ts +0 -90
  240. package/src/pages/functions/buildWorker.ts +0 -288
  241. package/src/pages/functions/filepath-routing.test.ts +0 -234
  242. package/src/pages/functions/filepath-routing.ts +0 -189
  243. package/src/pages/functions/identifiers.ts +0 -78
  244. package/src/pages/functions/routes-consolidation.test.ts +0 -250
  245. package/src/pages/functions/routes-consolidation.ts +0 -73
  246. package/src/pages/functions/routes-transformation.test.ts +0 -282
  247. package/src/pages/functions/routes-transformation.ts +0 -115
  248. package/src/pages/functions/routes-validation.test.ts +0 -403
  249. package/src/pages/functions/routes-validation.ts +0 -202
  250. package/src/pages/functions/routes.ts +0 -151
  251. package/src/pages/functions/tsconfig.json +0 -8
  252. package/src/pages/functions/tsconfig.tsbuildinfo +0 -1
  253. package/src/pages/functions.ts +0 -86
  254. package/src/pages/hash.ts +0 -13
  255. package/src/pages/index.ts +0 -102
  256. package/src/pages/projects.tsx +0 -162
  257. package/src/pages/prompt-select-project.tsx +0 -31
  258. package/src/pages/publish.tsx +0 -276
  259. package/src/pages/types.ts +0 -46
  260. package/src/pages/upload.tsx +0 -449
  261. package/src/pages/utils.ts +0 -23
  262. package/src/parse.ts +0 -308
  263. package/src/paths.ts +0 -71
  264. package/src/proxy.ts +0 -694
  265. package/src/publish/index.ts +0 -274
  266. package/src/publish/publish.ts +0 -1065
  267. package/src/pubsub/index.ts +0 -286
  268. package/src/pubsub/pubsub-commands.ts +0 -623
  269. package/src/queues/cli/commands/consumer/add.ts +0 -65
  270. package/src/queues/cli/commands/consumer/index.ts +0 -19
  271. package/src/queues/cli/commands/consumer/remove.ts +0 -31
  272. package/src/queues/cli/commands/create.ts +0 -25
  273. package/src/queues/cli/commands/delete.ts +0 -26
  274. package/src/queues/cli/commands/index.ts +0 -35
  275. package/src/queues/cli/commands/list.ts +0 -25
  276. package/src/queues/client.ts +0 -135
  277. package/src/queues/utils.ts +0 -18
  278. package/src/r2/constants.ts +0 -4
  279. package/src/r2/helpers.ts +0 -132
  280. package/src/r2/index.ts +0 -289
  281. package/src/routes.ts +0 -140
  282. package/src/secret/index.ts +0 -375
  283. package/src/selfsigned.d.ts +0 -29
  284. package/src/sites.ts +0 -372
  285. package/src/tail/createTail.ts +0 -406
  286. package/src/tail/filters.ts +0 -277
  287. package/src/tail/index.ts +0 -211
  288. package/src/tail/printing.ts +0 -122
  289. package/src/tsconfig-sanity.ts +0 -16
  290. package/src/type-generation.ts +0 -181
  291. package/src/update-check.ts +0 -19
  292. package/src/user/access.ts +0 -68
  293. package/src/user/auth-variables.ts +0 -113
  294. package/src/user/choose-account.tsx +0 -39
  295. package/src/user/generate-auth-url.ts +0 -33
  296. package/src/user/generate-random-state.ts +0 -16
  297. package/src/user/index.ts +0 -2
  298. package/src/user/user.ts +0 -1233
  299. package/src/utils/collectKeyValues.ts +0 -14
  300. package/src/whoami.ts +0 -135
  301. package/src/worker.ts +0 -257
  302. package/src/yargs-types.ts +0 -37
  303. package/src/zones.ts +0 -191
  304. package/templates/__tests__/tsconfig.tsbuildinfo +0 -1
  305. package/templates/d1-beta-facade.js +0 -241
  306. package/templates/first-party-worker-module-facade.ts +0 -19
  307. package/templates/format-dev-errors.ts +0 -34
  308. package/templates/serve-static-assets.ts +0 -66
  309. package/templates/service-bindings-module-facade.js +0 -55
  310. package/templates/service-bindings-sw-facade.js +0 -42
  311. package/templates/tsconfig.tsbuildinfo +0 -1
@@ -1,1587 +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 "console.log('custom build'); 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 \"console.log('custom build'); 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 \\"console.log('custom build'); 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 "custom build" && 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 \\"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 "console.log('custom build');"`,
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 \\"console.log('custom build');\\".
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 \\"console.log('custom build');\\"
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 \\"console.log('custom build');\\".
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
- "out": "",
898
- "warn": "",
899
- }
900
- `);
901
- });
902
-
903
- it("should use 9229 as the default port", async () => {
904
- writeWranglerToml({
905
- main: "index.js",
906
- });
907
- fs.writeFileSync("index.js", `export default {};`);
908
- await runWrangler("dev");
909
- expect((Dev as jest.Mock).mock.calls[0][0].inspectorPort).toEqual(9229);
910
- expect(std).toMatchInlineSnapshot(`
911
- Object {
912
- "debug": "",
913
- "err": "",
914
- "out": "",
915
- "warn": "",
916
- }
917
- `);
918
- });
919
-
920
- it("should read --inspector-port", async () => {
921
- writeWranglerToml({
922
- main: "index.js",
923
- });
924
- fs.writeFileSync("index.js", `export default {};`);
925
- await runWrangler("dev --inspector-port=9999");
926
- expect((Dev as jest.Mock).mock.calls[0][0].inspectorPort).toEqual(9999);
927
- expect(std).toMatchInlineSnapshot(`
928
- Object {
929
- "debug": "",
930
- "err": "",
931
- "out": "",
932
- "warn": "",
933
- }
934
- `);
935
- });
936
-
937
- it("should read dev.inspector_port from wrangler.toml", async () => {
938
- writeWranglerToml({
939
- main: "index.js",
940
- dev: {
941
- inspector_port: 9999,
942
- },
943
- });
944
- fs.writeFileSync("index.js", `export default {};`);
945
- await runWrangler("dev");
946
- expect((Dev as jest.Mock).mock.calls[0][0].inspectorPort).toEqual(9999);
947
- expect(std).toMatchInlineSnapshot(`
948
- Object {
949
- "debug": "",
950
- "err": "",
951
- "out": "",
952
- "warn": "",
953
- }
954
- `);
955
- });
956
-
957
- it("should error if a bad dev.inspector_port config is provided", async () => {
958
- writeWranglerToml({
959
- main: "index.js",
960
- dev: {
961
- // @ts-expect-error intentionally bad port
962
- inspector_port: "some string",
963
- },
964
- });
965
- fs.writeFileSync("index.js", `export default {};`);
966
- await expect(runWrangler("dev")).rejects
967
- .toThrowErrorMatchingInlineSnapshot(`
968
- "Processing wrangler.toml configuration:
969
- - Expected \\"dev.inspector_port\\" to be of type number but got \\"some string\\"."
970
- `);
971
- });
972
- });
973
-
974
- describe("port", () => {
975
- it("should default port to 8787 if it is not in use", async () => {
976
- writeWranglerToml({
977
- main: "index.js",
978
- });
979
- fs.writeFileSync("index.js", `export default {};`);
980
- await runWrangler("dev");
981
- expect((Dev as jest.Mock).mock.calls[0][0].initialPort).toEqual(8787);
982
- expect(std.out).toMatchInlineSnapshot(`""`);
983
- expect(std.warn).toMatchInlineSnapshot(`""`);
984
- expect(std.err).toMatchInlineSnapshot(`""`);
985
- });
986
-
987
- it("should use `port` from `wrangler.toml`, if available", async () => {
988
- writeWranglerToml({
989
- main: "index.js",
990
- dev: {
991
- port: 8888,
992
- },
993
- });
994
- fs.writeFileSync("index.js", `export default {};`);
995
- // Mock `getPort()` to resolve to a completely different port.
996
- (getPort as jest.Mock).mockResolvedValue(98765);
997
-
998
- await runWrangler("dev");
999
- expect((Dev as jest.Mock).mock.calls[0][0].initialPort).toEqual(8888);
1000
- expect(std.out).toMatchInlineSnapshot(`""`);
1001
- expect(std.warn).toMatchInlineSnapshot(`""`);
1002
- expect(std.err).toMatchInlineSnapshot(`""`);
1003
- });
1004
-
1005
- it("should error if a bad dev.port config is provided", async () => {
1006
- writeWranglerToml({
1007
- main: "index.js",
1008
- dev: {
1009
- // @ts-expect-error intentionally bad port
1010
- port: "some string",
1011
- },
1012
- });
1013
- fs.writeFileSync("index.js", `export default {};`);
1014
- await expect(runWrangler("dev")).rejects
1015
- .toThrowErrorMatchingInlineSnapshot(`
1016
- "Processing wrangler.toml configuration:
1017
- - Expected \\"dev.port\\" to be of type number but got \\"some string\\"."
1018
- `);
1019
- });
1020
-
1021
- it("should use --port command line arg, if provided", async () => {
1022
- writeWranglerToml({
1023
- main: "index.js",
1024
- dev: {
1025
- port: 8888,
1026
- },
1027
- });
1028
- fs.writeFileSync("index.js", `export default {};`);
1029
- // Mock `getPort()` to resolve to a completely different port.
1030
- (getPort as jest.Mock).mockResolvedValue(98765);
1031
-
1032
- await runWrangler("dev --port=9999");
1033
- expect((Dev as jest.Mock).mock.calls[0][0].initialPort).toEqual(9999);
1034
- expect(std.out).toMatchInlineSnapshot(`""`);
1035
- expect(std.warn).toMatchInlineSnapshot(`""`);
1036
- expect(std.err).toMatchInlineSnapshot(`""`);
1037
- });
1038
-
1039
- it("should use a different port to the default if it is in use", async () => {
1040
- writeWranglerToml({
1041
- main: "index.js",
1042
- });
1043
- fs.writeFileSync("index.js", `export default {};`);
1044
- // Mock `getPort()` to resolve to a completely different port.
1045
- (getPort as jest.Mock).mockResolvedValue(98765);
1046
-
1047
- await runWrangler("dev");
1048
- expect((Dev as jest.Mock).mock.calls[0][0].initialPort).toEqual(98765);
1049
- expect(std.out).toMatchInlineSnapshot(`""`);
1050
- expect(std.warn).toMatchInlineSnapshot(`""`);
1051
- expect(std.err).toMatchInlineSnapshot(`""`);
1052
- });
1053
- });
1054
-
1055
- describe("durable_objects", () => {
1056
- it("should warn if there are remote Durable Objects, or missing migrations for local Durable Objects", async () => {
1057
- writeWranglerToml({
1058
- main: "index.js",
1059
- durable_objects: {
1060
- bindings: [
1061
- { name: "NAME_1", class_name: "CLASS_1" },
1062
- {
1063
- name: "NAME_2",
1064
- class_name: "CLASS_2",
1065
- script_name: "SCRIPT_A",
1066
- },
1067
- { name: "NAME_3", class_name: "CLASS_3" },
1068
- {
1069
- name: "NAME_4",
1070
- class_name: "CLASS_4",
1071
- script_name: "SCRIPT_B",
1072
- },
1073
- ],
1074
- },
1075
- });
1076
- fs.writeFileSync("index.js", `export default {};`);
1077
- await runWrangler("dev");
1078
- expect((Dev as jest.Mock).mock.calls[0][0].initialIp).toEqual("0.0.0.0");
1079
- expect(std.out).toMatchInlineSnapshot(`
1080
- "Your worker has access to the following bindings:
1081
- - Durable Objects:
1082
- - NAME_1: CLASS_1
1083
- - NAME_2: CLASS_2 (defined in SCRIPT_A)
1084
- - NAME_3: CLASS_3
1085
- - NAME_4: CLASS_4 (defined in SCRIPT_B)"
1086
- `);
1087
- expect(std.warn).toMatchInlineSnapshot(`
1088
- "▲ [WARNING] Processing wrangler.toml configuration:
1089
-
1090
- - In wrangler.toml, you have configured [durable_objects] exported by this Worker (CLASS_1,
1091
- CLASS_3), but no [migrations] for them. This may not work as expected until you add a [migrations]
1092
- section to your wrangler.toml. Add this configuration to your wrangler.toml:
1093
-
1094
- \`\`\`
1095
- [[migrations]]
1096
- tag = \\"v1\\" # Should be unique for each entry
1097
- new_classes = [\\"CLASS_1\\", \\"CLASS_3\\"]
1098
- \`\`\`
1099
-
1100
- Refer to
1101
- https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml
1102
- for more details.
1103
-
1104
-
1105
- ▲ [WARNING] WARNING: You have Durable Object bindings that are not defined locally in the worker being developed.
1106
-
1107
- Be aware that changes to the data stored in these Durable Objects will be permanent and affect the
1108
- live instances.
1109
- Remote Durable Objects that are affected:
1110
- - {\\"name\\":\\"NAME_2\\",\\"class_name\\":\\"CLASS_2\\",\\"script_name\\":\\"SCRIPT_A\\"}
1111
- - {\\"name\\":\\"NAME_4\\",\\"class_name\\":\\"CLASS_4\\",\\"script_name\\":\\"SCRIPT_B\\"}
1112
-
1113
- "
1114
- `);
1115
- expect(std.err).toMatchInlineSnapshot(`""`);
1116
- });
1117
- });
1118
-
1119
- describe(".dev.vars", () => {
1120
- it("should override `vars` bindings from `wrangler.toml` with values in `.dev.vars`", async () => {
1121
- fs.writeFileSync("index.js", `export default {};`);
1122
-
1123
- const localVarsEnvContent = dedent`
1124
- # Preceding comment
1125
- VAR_1="var #1 value" # End of line comment
1126
- VAR_3="var #3 value"
1127
- VAR_MULTI_LINE_1="A: line 1
1128
- line 2"
1129
- VAR_MULTI_LINE_2="B: line 1\\nline 2"
1130
- EMPTY=
1131
- UNQUOTED= unquoted value
1132
- `;
1133
- fs.writeFileSync(".dev.vars", localVarsEnvContent, "utf8");
1134
-
1135
- writeWranglerToml({
1136
- main: "index.js",
1137
- vars: {
1138
- VAR_1: "original value 1",
1139
- VAR_2: "original value 2", // should not get overridden
1140
- VAR_3: "original value 3",
1141
- VAR_MULTI_LINE_1: "original multi-line 1",
1142
- VAR_MULTI_LINE_2: "original multi-line 2",
1143
- EMPTY: "original empty",
1144
- UNQUOTED: "original unquoted",
1145
- },
1146
- });
1147
- await runWrangler("dev");
1148
- const varBindings: Record<string, unknown> = (Dev as jest.Mock).mock
1149
- .calls[0][0].bindings.vars;
1150
-
1151
- expect(varBindings).toEqual({
1152
- VAR_1: "var #1 value",
1153
- VAR_2: "original value 2",
1154
- VAR_3: "var #3 value",
1155
- VAR_MULTI_LINE_1: "A: line 1\nline 2",
1156
- VAR_MULTI_LINE_2: "B: line 1\nline 2",
1157
- EMPTY: "",
1158
- UNQUOTED: "unquoted value", // Note that whitespace is trimmed
1159
- });
1160
- expect(std.out).toMatchInlineSnapshot(`
1161
- "Using vars defined in .dev.vars
1162
- Your worker has access to the following bindings:
1163
- - Vars:
1164
- - VAR_1: \\"(hidden)\\"
1165
- - VAR_2: \\"original value 2\\"
1166
- - VAR_3: \\"(hidden)\\"
1167
- - VAR_MULTI_LINE_1: \\"(hidden)\\"
1168
- - VAR_MULTI_LINE_2: \\"(hidden)\\"
1169
- - EMPTY: \\"(hidden)\\"
1170
- - UNQUOTED: \\"(hidden)\\""
1171
- `);
1172
- expect(std.warn).toMatchInlineSnapshot(`""`);
1173
- expect(std.err).toMatchInlineSnapshot(`""`);
1174
- });
1175
-
1176
- it("should prefer `.dev.vars.<environment>` if `--env <environment> set`", async () => {
1177
- fs.writeFileSync("index.js", `export default {};`);
1178
- fs.writeFileSync(".dev.vars", "DEFAULT_VAR=default");
1179
- fs.writeFileSync(".dev.vars.custom", "CUSTOM_VAR=custom");
1180
-
1181
- writeWranglerToml({ main: "index.js", env: { custom: {} } });
1182
- await runWrangler("dev --env custom");
1183
- const varBindings: Record<string, unknown> = (Dev as jest.Mock).mock
1184
- .calls[0][0].bindings.vars;
1185
-
1186
- expect(varBindings).toEqual({ CUSTOM_VAR: "custom" });
1187
- expect(std.out).toMatchInlineSnapshot(`
1188
- "Using vars defined in .dev.vars.custom
1189
- Your worker has access to the following bindings:
1190
- - Vars:
1191
- - CUSTOM_VAR: \\"(hidden)\\""
1192
- `);
1193
- expect(std.warn).toMatchInlineSnapshot(`""`);
1194
- expect(std.err).toMatchInlineSnapshot(`""`);
1195
- });
1196
- });
1197
-
1198
- describe("serve static assets", () => {
1199
- it("should error if --site is used with no value", async () => {
1200
- await expect(
1201
- runWrangler("dev --site")
1202
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1203
- `"Not enough arguments following: site"`
1204
- );
1205
-
1206
- expect(std).toMatchInlineSnapshot(`
1207
- Object {
1208
- "debug": "",
1209
- "err": "X [ERROR] Not enough arguments following: site
1210
-
1211
- ",
1212
- "out": "
1213
- wrangler dev [script]
1214
-
1215
- 👂 Start a local server for developing your worker
1216
-
1217
- Positionals:
1218
- script The path to an entry point for your worker [string]
1219
-
1220
- Flags:
1221
- -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
1222
- -c, --config Path to .toml configuration file [string]
1223
- -e, --env Environment to use for operations and .env files [string]
1224
- -h, --help Show help [boolean]
1225
- -v, --version Show version number [boolean]
1226
-
1227
- Options:
1228
- --name Name of the worker [string]
1229
- --no-bundle Skip internal build steps and directly publish script [boolean] [default: false]
1230
- --compatibility-date Date to use for compatibility checks [string]
1231
- --compatibility-flags, --compatibility-flag Flags to use for compatibility checks [array]
1232
- --latest Use the latest version of the worker runtime [boolean] [default: true]
1233
- --ip IP address to listen on [string]
1234
- --port Port to listen on [number]
1235
- --inspector-port Port for devtools to connect to [number]
1236
- --routes, --route Routes to upload [array]
1237
- --host Host to forward requests to, defaults to the zone of project [string]
1238
- --local-protocol Protocol to listen to requests on, defaults to http. [choices: \\"http\\", \\"https\\"]
1239
- --local-upstream Host to act as origin in local mode, defaults to dev.host or route [string]
1240
- --assets Static assets to be served [string]
1241
- --site Root folder of static assets for Workers Sites [string]
1242
- --site-include Array of .gitignore-style patterns that match file or directory names from the sites directory. Only matched items will be uploaded. [array]
1243
- --site-exclude Array of .gitignore-style patterns that match file or directory names from the sites directory. Matched items will not be uploaded. [array]
1244
- --upstream-protocol Protocol to forward requests to host on, defaults to https. [choices: \\"http\\", \\"https\\"]
1245
- --var A key-value pair to be injected into the script as a variable [array]
1246
- --define A key-value pair to be substituted in the script [array]
1247
- --jsx-factory The function that is called for each JSX element [string]
1248
- --jsx-fragment The function that is called for each JSX fragment [string]
1249
- --tsconfig Path to a custom tsconfig.json file [string]
1250
- -l, --local Run on my machine [boolean] [default: false]
1251
- --experimental-local Run on my machine using the Cloudflare Workers runtime [boolean] [default: false]
1252
- --experimental-local-remote-kv Read/write KV data from/to real namespaces on the Cloudflare network [boolean] [default: false]
1253
- --minify Minify the script [boolean]
1254
- --node-compat Enable node.js compatibility [boolean]
1255
- --persist Enable persistence for local mode, using default path: .wrangler/state [boolean]
1256
- --persist-to Specify directory to use for local persistence (implies --persist) [string]
1257
- --live-reload Auto reload HTML pages when change is detected in local mode [boolean]
1258
- --test-scheduled Test scheduled events by visiting /__scheduled in browser [boolean] [default: false]
1259
- --log-level Specify logging level [choices: \\"debug\\", \\"info\\", \\"log\\", \\"warn\\", \\"error\\", \\"none\\"] [default: \\"log\\"]",
1260
- "warn": "",
1261
- }
1262
- `);
1263
- });
1264
-
1265
- it("should error if --assets and --site are used together", async () => {
1266
- writeWranglerToml({
1267
- main: "./index.js",
1268
- });
1269
- fs.writeFileSync("index.js", `export default {};`);
1270
- await expect(
1271
- runWrangler("dev --assets abc --site xyz")
1272
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1273
- `"Cannot use Assets and Workers Sites in the same Worker."`
1274
- );
1275
- });
1276
-
1277
- it("should error if --assets and config.site are used together", async () => {
1278
- writeWranglerToml({
1279
- main: "./index.js",
1280
- site: {
1281
- bucket: "xyz",
1282
- },
1283
- });
1284
- fs.writeFileSync("index.js", `export default {};`);
1285
- await expect(
1286
- runWrangler("dev --assets abc")
1287
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1288
- `"Cannot use Assets and Workers Sites in the same Worker."`
1289
- );
1290
- });
1291
-
1292
- it("should error if config.assets and --site are used together", async () => {
1293
- writeWranglerToml({
1294
- main: "./index.js",
1295
- // @ts-expect-error we allow string inputs here
1296
- assets: "abc",
1297
- });
1298
- fs.writeFileSync("index.js", `export default {};`);
1299
- await expect(
1300
- runWrangler("dev --site xyz")
1301
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1302
- `"Cannot use Assets and Workers Sites in the same Worker."`
1303
- );
1304
- });
1305
-
1306
- it("should error if config.assets and config.site are used together", async () => {
1307
- writeWranglerToml({
1308
- main: "./index.js",
1309
- // @ts-expect-error we allow string inputs here
1310
- assets: "abc",
1311
- site: {
1312
- bucket: "xyz",
1313
- },
1314
- });
1315
- fs.writeFileSync("index.js", `export default {};`);
1316
- await expect(
1317
- runWrangler("dev --assets abc")
1318
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1319
- `"Cannot use Assets and Workers Sites in the same Worker."`
1320
- );
1321
- });
1322
-
1323
- it("should indicate whether Sites is being used", async () => {
1324
- writeWranglerToml({
1325
- main: "index.js",
1326
- });
1327
- fs.writeFileSync("index.js", `export default {};`);
1328
-
1329
- await runWrangler("dev");
1330
- expect((Dev as jest.Mock).mock.calls[0][0].isWorkersSite).toEqual(false);
1331
-
1332
- await runWrangler("dev --site abc");
1333
- expect((Dev as jest.Mock).mock.calls[1][0].isWorkersSite).toEqual(true);
1334
-
1335
- await runWrangler("dev --assets abc");
1336
- expect((Dev as jest.Mock).mock.calls[2][0].isWorkersSite).toEqual(false);
1337
- });
1338
- it("should warn if --assets is used", async () => {
1339
- writeWranglerToml({
1340
- main: "./index.js",
1341
- });
1342
- fs.writeFileSync("index.js", `export default {};`);
1343
-
1344
- await runWrangler('dev --assets "./assets"');
1345
- expect(std).toMatchInlineSnapshot(`
1346
- Object {
1347
- "debug": "",
1348
- "err": "",
1349
- "out": "",
1350
- "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1351
-
1352
- ",
1353
- }
1354
- `);
1355
- });
1356
-
1357
- it("should warn if config.assets is used", async () => {
1358
- writeWranglerToml({
1359
- main: "./index.js",
1360
- // @ts-expect-error we allow string inputs here
1361
- assets: "./assets",
1362
- });
1363
- fs.writeFileSync("index.js", `export default {};`);
1364
-
1365
- await runWrangler("dev");
1366
- expect(std).toMatchInlineSnapshot(`
1367
- Object {
1368
- "debug": "",
1369
- "err": "",
1370
- "out": "",
1371
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1372
-
1373
- - \\"assets\\" fields are experimental and may change or break at any time.
1374
-
1375
- ",
1376
- }
1377
- `);
1378
- });
1379
- });
1380
-
1381
- describe("--inspect", () => {
1382
- it("should warn if --inspect is used", async () => {
1383
- fs.writeFileSync("index.js", `export default {};`);
1384
- await runWrangler("dev index.js --inspect");
1385
- expect(std).toMatchInlineSnapshot(`
1386
- Object {
1387
- "debug": "",
1388
- "err": "",
1389
- "out": "",
1390
- "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1391
-
1392
- ",
1393
- }
1394
- `);
1395
- });
1396
-
1397
- it("should default to true, without a warning", async () => {
1398
- fs.writeFileSync("index.js", `export default {};`);
1399
- await runWrangler("dev index.js");
1400
- expect((Dev as jest.Mock).mock.calls[0][0].inspect).toEqual(true);
1401
- expect(std).toMatchInlineSnapshot(`
1402
- Object {
1403
- "debug": "",
1404
- "err": "",
1405
- "out": "",
1406
- "warn": "",
1407
- }
1408
- `);
1409
- });
1410
-
1411
- it("should pass true, with a warning", async () => {
1412
- fs.writeFileSync("index.js", `export default {};`);
1413
- await runWrangler("dev index.js --inspect");
1414
- expect((Dev as jest.Mock).mock.calls[0][0].inspect).toEqual(true);
1415
- expect(std).toMatchInlineSnapshot(`
1416
- Object {
1417
- "debug": "",
1418
- "err": "",
1419
- "out": "",
1420
- "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1421
-
1422
- ",
1423
- }
1424
- `);
1425
- });
1426
-
1427
- it("should pass false, without a warning", async () => {
1428
- fs.writeFileSync("index.js", `export default {};`);
1429
- await runWrangler("dev index.js --inspect false");
1430
- expect((Dev as jest.Mock).mock.calls[0][0].inspect).toEqual(false);
1431
- expect(std).toMatchInlineSnapshot(`
1432
- Object {
1433
- "debug": "",
1434
- "err": "",
1435
- "out": "",
1436
- "warn": "",
1437
- }
1438
- `);
1439
- });
1440
- });
1441
-
1442
- describe("--log-level", () => {
1443
- it("should not output warnings with log-level 'none'", async () => {
1444
- fs.writeFileSync("index.js", `export default {};`);
1445
- await runWrangler("dev index.js --inspect --log-level none");
1446
- expect(std).toMatchInlineSnapshot(`
1447
- Object {
1448
- "debug": "",
1449
- "err": "",
1450
- "out": "",
1451
- "warn": "",
1452
- }
1453
- `);
1454
- });
1455
-
1456
- it("should output warnings with log-level 'warn'", async () => {
1457
- fs.writeFileSync("index.js", `export default {};`);
1458
- await runWrangler("dev index.js --inspect --log-level warn");
1459
- expect(std).toMatchInlineSnapshot(`
1460
- Object {
1461
- "debug": "",
1462
- "err": "",
1463
- "out": "",
1464
- "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1465
-
1466
- ",
1467
- }
1468
- `);
1469
- });
1470
-
1471
- it("should not output Errors with log-level error", async () => {
1472
- fs.writeFileSync("index.js", `export default {};`);
1473
- await runWrangler("dev index.js --inspect --log-level debug");
1474
- expect(std.debug.length > 1).toBe(true);
1475
- });
1476
- });
1477
-
1478
- describe("service bindings", () => {
1479
- it("should warn when using service bindings", async () => {
1480
- writeWranglerToml({
1481
- services: [
1482
- { binding: "WorkerA", service: "A" },
1483
- { binding: "WorkerB", service: "B", environment: "staging" },
1484
- ],
1485
- });
1486
- fs.writeFileSync("index.js", `export default {};`);
1487
- await runWrangler("dev index.js");
1488
- expect(std.out).toMatchInlineSnapshot(`
1489
- "Your worker has access to the following bindings:
1490
- - Services:
1491
- - WorkerA: A
1492
- - WorkerB: B - staging"
1493
- `);
1494
- expect(std.warn).toMatchInlineSnapshot(`
1495
- "▲ [WARNING] Processing wrangler.toml configuration:
1496
-
1497
- - \\"services\\" fields are experimental and may change or break at any time.
1498
-
1499
-
1500
- ▲ [WARNING] This worker is bound to live services: WorkerA (A), WorkerB (B@staging)
1501
-
1502
- "
1503
- `);
1504
- expect(std.err).toMatchInlineSnapshot(`""`);
1505
- });
1506
- });
1507
-
1508
- describe("print bindings", () => {
1509
- it("should print bindings", async () => {
1510
- writeWranglerToml({
1511
- services: [
1512
- { binding: "WorkerA", service: "A" },
1513
- { binding: "WorkerB", service: "B", environment: "staging" },
1514
- ],
1515
- });
1516
- fs.writeFileSync("index.js", `export default {};`);
1517
- await runWrangler("dev index.js");
1518
- expect(std).toMatchInlineSnapshot(`
1519
- Object {
1520
- "debug": "",
1521
- "err": "",
1522
- "out": "Your worker has access to the following bindings:
1523
- - Services:
1524
- - WorkerA: A
1525
- - WorkerB: B - staging",
1526
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1527
-
1528
- - \\"services\\" fields are experimental and may change or break at any time.
1529
-
1530
-
1531
- ▲ [WARNING] This worker is bound to live services: WorkerA (A), WorkerB (B@staging)
1532
-
1533
- ",
1534
- }
1535
- `);
1536
- });
1537
-
1538
- it("should mask vars that were overriden in .dev.vars", async () => {
1539
- writeWranglerToml({
1540
- vars: {
1541
- variable: 123,
1542
- overriden: "original values",
1543
- },
1544
- });
1545
- fs.writeFileSync(
1546
- ".dev.vars",
1547
- `
1548
- SECRET = "A secret"
1549
- overriden = "overriden value"
1550
- `
1551
- );
1552
- fs.writeFileSync("index.js", `export default {};`);
1553
- await runWrangler("dev index.js");
1554
- expect(std).toMatchInlineSnapshot(`
1555
- Object {
1556
- "debug": "",
1557
- "err": "",
1558
- "out": "Using vars defined in .dev.vars
1559
- Your worker has access to the following bindings:
1560
- - Vars:
1561
- - variable: 123
1562
- - overriden: \\"(hidden)\\"
1563
- - SECRET: \\"(hidden)\\"",
1564
- "warn": "",
1565
- }
1566
- `);
1567
- });
1568
- });
1569
- });
1570
-
1571
- function mockGetZones(domain: string, zones: { id: string }[] = []) {
1572
- msw.use(
1573
- rest.get("*/zones", (req, res, ctx) => {
1574
- expect([...req.url.searchParams.entries()]).toEqual([["name", domain]]);
1575
-
1576
- return res(
1577
- ctx.status(200),
1578
- ctx.json({
1579
- success: true,
1580
- errors: [],
1581
- messages: [],
1582
- result: zones,
1583
- })
1584
- );
1585
- })
1586
- );
1587
- }