wrangler 0.0.0-e41c7e41 → 0.0.0-e44f496a8

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