wrangler 0.0.0-e7a0cd5b → 0.0.0-e7c7235fd

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 (268) hide show
  1. package/README.md +31 -45
  2. package/bin/wrangler.js +24 -93
  3. package/config-schema.json +3324 -0
  4. package/package.json +183 -191
  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 +48 -32
  16. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  17. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  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-patch-console-prefix.d.ts +3 -0
  21. package/templates/middleware/middleware-patch-console-prefix.ts +21 -0
  22. package/templates/middleware/middleware-scheduled.ts +15 -1
  23. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  24. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  25. package/templates/modules-watch-stub.js +4 -0
  26. package/templates/new-worker-scheduled.ts +1 -1
  27. package/templates/new-worker.ts +4 -1
  28. package/templates/pages-dev-pipeline.ts +6 -2
  29. package/templates/pages-dev-util.ts +4 -1
  30. package/templates/pages-shim.ts +1 -1
  31. package/templates/pages-template-plugin.ts +33 -14
  32. package/templates/pages-template-worker.ts +12 -3
  33. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  34. package/templates/startDevWorker/ProxyWorker.ts +336 -0
  35. package/templates/tsconfig-sanity.ts +11 -0
  36. package/templates/tsconfig.init.json +22 -0
  37. package/templates/tsconfig.json +5 -103
  38. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  39. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  40. package/wrangler-dist/ProxyWorker.js +241 -0
  41. package/wrangler-dist/ProxyWorker.js.map +6 -0
  42. package/wrangler-dist/cli.d.ts +26345 -529
  43. package/wrangler-dist/cli.js +159104 -150579
  44. package/Cloudflare_CA.pem +0 -18
  45. package/import_meta_url.js +0 -3
  46. package/miniflare-config-stubs/.env.empty +0 -0
  47. package/miniflare-config-stubs/package.empty.json +0 -1
  48. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  49. package/miniflare-dist/index.mjs +0 -6316
  50. package/src/__tests__/access.test.ts +0 -25
  51. package/src/__tests__/api-dev.test.ts +0 -209
  52. package/src/__tests__/api-devregistry.test.js +0 -57
  53. package/src/__tests__/api.test.ts +0 -80
  54. package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
  55. package/src/__tests__/config-cache.test.ts +0 -42
  56. package/src/__tests__/configuration.test.ts +0 -4028
  57. package/src/__tests__/d1.test.ts +0 -72
  58. package/src/__tests__/delete.test.ts +0 -230
  59. package/src/__tests__/deployments.test.ts +0 -95
  60. package/src/__tests__/dev.test.tsx +0 -1509
  61. package/src/__tests__/dialogs.test.tsx +0 -40
  62. package/src/__tests__/generate.test.ts +0 -235
  63. package/src/__tests__/get-host-from-url.test.ts +0 -16
  64. package/src/__tests__/guess-worker-format.test.ts +0 -85
  65. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  66. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  67. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  68. package/src/__tests__/helpers/mock-bin.ts +0 -36
  69. package/src/__tests__/helpers/mock-cfetch.ts +0 -333
  70. package/src/__tests__/helpers/mock-console.ts +0 -106
  71. package/src/__tests__/helpers/mock-dialogs.ts +0 -153
  72. package/src/__tests__/helpers/mock-get-zone-from-host.ts +0 -8
  73. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  74. package/src/__tests__/helpers/mock-istty.ts +0 -74
  75. package/src/__tests__/helpers/mock-known-routes.ts +0 -7
  76. package/src/__tests__/helpers/mock-kv.ts +0 -33
  77. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -252
  78. package/src/__tests__/helpers/mock-process.ts +0 -39
  79. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  80. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  81. package/src/__tests__/helpers/msw/handlers/access.ts +0 -13
  82. package/src/__tests__/helpers/msw/handlers/deployments.ts +0 -59
  83. package/src/__tests__/helpers/msw/handlers/namespaces.ts +0 -104
  84. package/src/__tests__/helpers/msw/handlers/oauth.ts +0 -36
  85. package/src/__tests__/helpers/msw/handlers/r2.ts +0 -80
  86. package/src/__tests__/helpers/msw/handlers/script.ts +0 -75
  87. package/src/__tests__/helpers/msw/handlers/user.ts +0 -63
  88. package/src/__tests__/helpers/msw/handlers/zones.ts +0 -22
  89. package/src/__tests__/helpers/msw/index.ts +0 -21
  90. package/src/__tests__/helpers/run-in-tmp.ts +0 -38
  91. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  92. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +0 -1
  93. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +0 -5
  94. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +0 -1
  95. package/src/__tests__/helpers/worker-scripts/parent-worker.js +0 -8
  96. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +0 -5
  97. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  98. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  99. package/src/__tests__/https-options.test.ts +0 -163
  100. package/src/__tests__/index.test.ts +0 -262
  101. package/src/__tests__/init.test.ts +0 -2900
  102. package/src/__tests__/jest.setup.ts +0 -202
  103. package/src/__tests__/kv.test.ts +0 -1675
  104. package/src/__tests__/logger.test.ts +0 -141
  105. package/src/__tests__/metrics.test.ts +0 -450
  106. package/src/__tests__/middleware.scheduled.test.ts +0 -135
  107. package/src/__tests__/middleware.test.ts +0 -726
  108. package/src/__tests__/package-manager.test.ts +0 -353
  109. package/src/__tests__/pages.test.ts +0 -2223
  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 -7660
  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 -376
  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 -217
  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 -208
  129. package/src/api/index.ts +0 -2
  130. package/src/bundle-reporter.tsx +0 -68
  131. package/src/bundle.ts +0 -785
  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 -563
  139. package/src/config/index.ts +0 -342
  140. package/src/config/validation-helpers.ts +0 -597
  141. package/src/config/validation.ts +0 -2113
  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 -321
  145. package/src/d1/backups.tsx +0 -218
  146. package/src/d1/create.tsx +0 -54
  147. package/src/d1/delete.tsx +0 -56
  148. package/src/d1/execute.tsx +0 -299
  149. package/src/d1/formatTimeAgo.ts +0 -14
  150. package/src/d1/index.ts +0 -76
  151. package/src/d1/list.tsx +0 -48
  152. package/src/d1/options.ts +0 -12
  153. package/src/d1/types.tsx +0 -14
  154. package/src/d1/utils.ts +0 -39
  155. package/src/delete.ts +0 -108
  156. package/src/deployments.ts +0 -74
  157. package/src/deprecated/index.ts +0 -438
  158. package/src/dev/dev-vars.ts +0 -39
  159. package/src/dev/dev.tsx +0 -587
  160. package/src/dev/get-local-persistence-path.tsx +0 -31
  161. package/src/dev/local.tsx +0 -717
  162. package/src/dev/remote.tsx +0 -603
  163. package/src/dev/start-server.ts +0 -513
  164. package/src/dev/use-esbuild.ts +0 -204
  165. package/src/dev/validate-dev-props.ts +0 -31
  166. package/src/dev-registry.tsx +0 -201
  167. package/src/dev.tsx +0 -869
  168. package/src/dialogs.tsx +0 -163
  169. package/src/dispatch-namespace.ts +0 -207
  170. package/src/durable.ts +0 -102
  171. package/src/entry.ts +0 -329
  172. package/src/environment-variables.ts +0 -50
  173. package/src/errors.ts +0 -11
  174. package/src/git-client.ts +0 -124
  175. package/src/global-wrangler-config-path.ts +0 -26
  176. package/src/https-options.ts +0 -127
  177. package/src/index.tsx +0 -684
  178. package/src/init.ts +0 -970
  179. package/src/inspect.ts +0 -767
  180. package/src/intl-polyfill.d.ts +0 -139
  181. package/src/is-ci.ts +0 -14
  182. package/src/is-interactive.ts +0 -16
  183. package/src/kv/helpers.ts +0 -430
  184. package/src/kv/index.ts +0 -596
  185. package/src/logger.ts +0 -92
  186. package/src/metrics/index.ts +0 -5
  187. package/src/metrics/metrics-config.ts +0 -239
  188. package/src/metrics/metrics-dispatcher.ts +0 -96
  189. package/src/metrics/metrics-usage-headers.ts +0 -24
  190. package/src/metrics/send-event.ts +0 -94
  191. package/src/miniflare-cli/README.md +0 -30
  192. package/src/miniflare-cli/assets.ts +0 -215
  193. package/src/miniflare-cli/index.ts +0 -213
  194. package/src/miniflare-cli/request-context.ts +0 -40
  195. package/src/module-collection.ts +0 -267
  196. package/src/open-in-browser.ts +0 -17
  197. package/src/package-manager.ts +0 -219
  198. package/src/pages/build.tsx +0 -238
  199. package/src/pages/constants.ts +0 -18
  200. package/src/pages/deployments.tsx +0 -106
  201. package/src/pages/dev.tsx +0 -693
  202. package/src/pages/errors.ts +0 -66
  203. package/src/pages/functions/buildPlugin.ts +0 -110
  204. package/src/pages/functions/buildWorker.ts +0 -156
  205. package/src/pages/functions/filepath-routing.test.ts +0 -234
  206. package/src/pages/functions/filepath-routing.ts +0 -189
  207. package/src/pages/functions/identifiers.ts +0 -78
  208. package/src/pages/functions/routes-consolidation.test.ts +0 -250
  209. package/src/pages/functions/routes-consolidation.ts +0 -73
  210. package/src/pages/functions/routes-transformation.test.ts +0 -282
  211. package/src/pages/functions/routes-transformation.ts +0 -115
  212. package/src/pages/functions/routes-validation.test.ts +0 -403
  213. package/src/pages/functions/routes-validation.ts +0 -202
  214. package/src/pages/functions/routes.ts +0 -151
  215. package/src/pages/functions.tsx +0 -82
  216. package/src/pages/hash.tsx +0 -13
  217. package/src/pages/index.tsx +0 -94
  218. package/src/pages/projects.tsx +0 -169
  219. package/src/pages/publish.tsx +0 -436
  220. package/src/pages/types.ts +0 -49
  221. package/src/pages/upload.tsx +0 -425
  222. package/src/pages/utils.ts +0 -12
  223. package/src/parse.ts +0 -286
  224. package/src/paths.ts +0 -71
  225. package/src/proxy.ts +0 -689
  226. package/src/publish/index.ts +0 -270
  227. package/src/publish/publish.ts +0 -1035
  228. package/src/pubsub/index.ts +0 -286
  229. package/src/pubsub/pubsub-commands.tsx +0 -624
  230. package/src/queues/cli/commands/consumer/add.ts +0 -71
  231. package/src/queues/cli/commands/consumer/index.ts +0 -22
  232. package/src/queues/cli/commands/consumer/remove.ts +0 -38
  233. package/src/queues/cli/commands/create.ts +0 -25
  234. package/src/queues/cli/commands/delete.ts +0 -26
  235. package/src/queues/cli/commands/index.ts +0 -33
  236. package/src/queues/cli/commands/list.ts +0 -25
  237. package/src/queues/client.ts +0 -135
  238. package/src/r2/helpers.ts +0 -131
  239. package/src/r2/index.ts +0 -277
  240. package/src/routes.ts +0 -140
  241. package/src/secret/index.ts +0 -379
  242. package/src/selfsigned.d.ts +0 -29
  243. package/src/sites.tsx +0 -372
  244. package/src/tail/createTail.ts +0 -315
  245. package/src/tail/filters.ts +0 -277
  246. package/src/tail/index.ts +0 -214
  247. package/src/tail/printing.ts +0 -107
  248. package/src/type-generation.ts +0 -159
  249. package/src/update-check.ts +0 -19
  250. package/src/user/access.ts +0 -69
  251. package/src/user/choose-account.tsx +0 -69
  252. package/src/user/env-vars.ts +0 -46
  253. package/src/user/generate-auth-url.ts +0 -33
  254. package/src/user/generate-random-state.ts +0 -16
  255. package/src/user/index.ts +0 -3
  256. package/src/user/user.tsx +0 -1192
  257. package/src/utils/collectKeyValues.ts +0 -14
  258. package/src/whoami.tsx +0 -169
  259. package/src/worker.ts +0 -242
  260. package/src/yargs-types.ts +0 -20
  261. package/src/zones.ts +0 -191
  262. package/templates/d1-beta-facade.js +0 -174
  263. package/templates/experimental-local-cache-stubs.js +0 -27
  264. package/templates/first-party-worker-module-facade.ts +0 -18
  265. package/templates/format-dev-errors.ts +0 -32
  266. package/templates/serve-static-assets.ts +0 -63
  267. package/templates/service-bindings-module-facade.js +0 -54
  268. package/templates/service-bindings-sw-facade.js +0 -42
@@ -1,1509 +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 use 9229 as the default port", async () => {
834
- writeWranglerToml({
835
- main: "index.js",
836
- });
837
- fs.writeFileSync("index.js", `export default {};`);
838
- await runWrangler("dev");
839
- expect((Dev as jest.Mock).mock.calls[0][0].inspectorPort).toEqual(9229);
840
- expect(std).toMatchInlineSnapshot(`
841
- Object {
842
- "debug": "",
843
- "err": "",
844
- "out": "",
845
- "warn": "",
846
- }
847
- `);
848
- });
849
-
850
- it("should read --inspector-port", async () => {
851
- writeWranglerToml({
852
- main: "index.js",
853
- });
854
- fs.writeFileSync("index.js", `export default {};`);
855
- await runWrangler("dev --inspector-port=9999");
856
- expect((Dev as jest.Mock).mock.calls[0][0].inspectorPort).toEqual(9999);
857
- expect(std).toMatchInlineSnapshot(`
858
- Object {
859
- "debug": "",
860
- "err": "",
861
- "out": "",
862
- "warn": "",
863
- }
864
- `);
865
- });
866
-
867
- it("should read dev.inspector_port from wrangler.toml", async () => {
868
- writeWranglerToml({
869
- main: "index.js",
870
- dev: {
871
- inspector_port: 9999,
872
- },
873
- });
874
- fs.writeFileSync("index.js", `export default {};`);
875
- await runWrangler("dev");
876
- expect((Dev as jest.Mock).mock.calls[0][0].inspectorPort).toEqual(9999);
877
- expect(std).toMatchInlineSnapshot(`
878
- Object {
879
- "debug": "",
880
- "err": "",
881
- "out": "",
882
- "warn": "",
883
- }
884
- `);
885
- });
886
-
887
- it("should error if a bad dev.inspector_port config is provided", async () => {
888
- writeWranglerToml({
889
- main: "index.js",
890
- dev: {
891
- // @ts-expect-error intentionally bad port
892
- inspector_port: "some string",
893
- },
894
- });
895
- fs.writeFileSync("index.js", `export default {};`);
896
- await expect(runWrangler("dev")).rejects
897
- .toThrowErrorMatchingInlineSnapshot(`
898
- "Processing wrangler.toml configuration:
899
- - Expected \\"dev.inspector_port\\" to be of type number but got \\"some string\\"."
900
- `);
901
- });
902
- });
903
-
904
- describe("port", () => {
905
- it("should default port to 8787 if it is not in use", async () => {
906
- writeWranglerToml({
907
- main: "index.js",
908
- });
909
- fs.writeFileSync("index.js", `export default {};`);
910
- await runWrangler("dev");
911
- expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(8787);
912
- expect(std.out).toMatchInlineSnapshot(`""`);
913
- expect(std.warn).toMatchInlineSnapshot(`""`);
914
- expect(std.err).toMatchInlineSnapshot(`""`);
915
- });
916
-
917
- it("should use `port` from `wrangler.toml`, if available", async () => {
918
- writeWranglerToml({
919
- main: "index.js",
920
- dev: {
921
- port: 8888,
922
- },
923
- });
924
- fs.writeFileSync("index.js", `export default {};`);
925
- // Mock `getPort()` to resolve to a completely different port.
926
- (getPort as jest.Mock).mockResolvedValue(98765);
927
-
928
- await runWrangler("dev");
929
- expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(8888);
930
- expect(std.out).toMatchInlineSnapshot(`""`);
931
- expect(std.warn).toMatchInlineSnapshot(`""`);
932
- expect(std.err).toMatchInlineSnapshot(`""`);
933
- });
934
-
935
- it("should error if a bad dev.port config is provided", async () => {
936
- writeWranglerToml({
937
- main: "index.js",
938
- dev: {
939
- // @ts-expect-error intentionally bad port
940
- port: "some string",
941
- },
942
- });
943
- fs.writeFileSync("index.js", `export default {};`);
944
- await expect(runWrangler("dev")).rejects
945
- .toThrowErrorMatchingInlineSnapshot(`
946
- "Processing wrangler.toml configuration:
947
- - Expected \\"dev.port\\" to be of type number but got \\"some string\\"."
948
- `);
949
- });
950
-
951
- it("should use --port command line arg, if provided", async () => {
952
- writeWranglerToml({
953
- main: "index.js",
954
- dev: {
955
- port: 8888,
956
- },
957
- });
958
- fs.writeFileSync("index.js", `export default {};`);
959
- // Mock `getPort()` to resolve to a completely different port.
960
- (getPort as jest.Mock).mockResolvedValue(98765);
961
-
962
- await runWrangler("dev --port=9999");
963
- expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(9999);
964
- expect(std.out).toMatchInlineSnapshot(`""`);
965
- expect(std.warn).toMatchInlineSnapshot(`""`);
966
- expect(std.err).toMatchInlineSnapshot(`""`);
967
- });
968
-
969
- it("should use a different port to the default if it is in use", async () => {
970
- writeWranglerToml({
971
- main: "index.js",
972
- });
973
- fs.writeFileSync("index.js", `export default {};`);
974
- // Mock `getPort()` to resolve to a completely different port.
975
- (getPort as jest.Mock).mockResolvedValue(98765);
976
-
977
- await runWrangler("dev");
978
- expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(98765);
979
- expect(std.out).toMatchInlineSnapshot(`""`);
980
- expect(std.warn).toMatchInlineSnapshot(`""`);
981
- expect(std.err).toMatchInlineSnapshot(`""`);
982
- });
983
- });
984
-
985
- describe("durable_objects", () => {
986
- it("should warn if there are remote Durable Objects, or missing migrations for local Durable Objects", async () => {
987
- writeWranglerToml({
988
- main: "index.js",
989
- durable_objects: {
990
- bindings: [
991
- { name: "NAME_1", class_name: "CLASS_1" },
992
- {
993
- name: "NAME_2",
994
- class_name: "CLASS_2",
995
- script_name: "SCRIPT_A",
996
- },
997
- { name: "NAME_3", class_name: "CLASS_3" },
998
- {
999
- name: "NAME_4",
1000
- class_name: "CLASS_4",
1001
- script_name: "SCRIPT_B",
1002
- },
1003
- ],
1004
- },
1005
- });
1006
- fs.writeFileSync("index.js", `export default {};`);
1007
- await runWrangler("dev");
1008
- expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("0.0.0.0");
1009
- expect(std.out).toMatchInlineSnapshot(`
1010
- "Your worker has access to the following bindings:
1011
- - Durable Objects:
1012
- - NAME_1: CLASS_1
1013
- - NAME_2: CLASS_2 (defined in SCRIPT_A)
1014
- - NAME_3: CLASS_3
1015
- - NAME_4: CLASS_4 (defined in SCRIPT_B)"
1016
- `);
1017
- expect(std.warn).toMatchInlineSnapshot(`
1018
- "▲ [WARNING] Processing wrangler.toml configuration:
1019
-
1020
- - In wrangler.toml, you have configured [durable_objects] exported by this Worker (CLASS_1,
1021
- CLASS_3), but no [migrations] for them. This may not work as expected until you add a [migrations]
1022
- section to your wrangler.toml. Add this configuration to your wrangler.toml:
1023
-
1024
- \`\`\`
1025
- [[migrations]]
1026
- tag = \\"v1\\" # Should be unique for each entry
1027
- new_classes = [\\"CLASS_1\\", \\"CLASS_3\\"]
1028
- \`\`\`
1029
-
1030
- Refer to
1031
- https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml
1032
- for more details.
1033
-
1034
-
1035
- ▲ [WARNING] WARNING: You have Durable Object bindings that are not defined locally in the worker being developed.
1036
-
1037
- Be aware that changes to the data stored in these Durable Objects will be permanent and affect the
1038
- live instances.
1039
- Remote Durable Objects that are affected:
1040
- - {\\"name\\":\\"NAME_2\\",\\"class_name\\":\\"CLASS_2\\",\\"script_name\\":\\"SCRIPT_A\\"}
1041
- - {\\"name\\":\\"NAME_4\\",\\"class_name\\":\\"CLASS_4\\",\\"script_name\\":\\"SCRIPT_B\\"}
1042
-
1043
- "
1044
- `);
1045
- expect(std.err).toMatchInlineSnapshot(`""`);
1046
- });
1047
- });
1048
-
1049
- describe(".dev.vars", () => {
1050
- it("should override `vars` bindings from `wrangler.toml` with values in `.dev.vars`", async () => {
1051
- fs.writeFileSync("index.js", `export default {};`);
1052
-
1053
- const localVarsEnvContent = dedent`
1054
- # Preceding comment
1055
- VAR_1="var #1 value" # End of line comment
1056
- VAR_3="var #3 value"
1057
- VAR_MULTI_LINE_1="A: line 1
1058
- line 2"
1059
- VAR_MULTI_LINE_2="B: line 1\\nline 2"
1060
- EMPTY=
1061
- UNQUOTED= unquoted value
1062
- `;
1063
- fs.writeFileSync(".dev.vars", localVarsEnvContent, "utf8");
1064
-
1065
- writeWranglerToml({
1066
- main: "index.js",
1067
- vars: {
1068
- VAR_1: "original value 1",
1069
- VAR_2: "original value 2", // should not get overridden
1070
- VAR_3: "original value 3",
1071
- VAR_MULTI_LINE_1: "original multi-line 1",
1072
- VAR_MULTI_LINE_2: "original multi-line 2",
1073
- EMPTY: "original empty",
1074
- UNQUOTED: "original unquoted",
1075
- },
1076
- });
1077
- await runWrangler("dev");
1078
- const varBindings: Record<string, unknown> = (Dev as jest.Mock).mock
1079
- .calls[0][0].bindings.vars;
1080
-
1081
- expect(varBindings).toEqual({
1082
- VAR_1: "var #1 value",
1083
- VAR_2: "original value 2",
1084
- VAR_3: "var #3 value",
1085
- VAR_MULTI_LINE_1: "A: line 1\nline 2",
1086
- VAR_MULTI_LINE_2: "B: line 1\nline 2",
1087
- EMPTY: "",
1088
- UNQUOTED: "unquoted value", // Note that whitespace is trimmed
1089
- });
1090
- expect(std.out).toMatchInlineSnapshot(`
1091
- "Using vars defined in .dev.vars
1092
- Your worker has access to the following bindings:
1093
- - Vars:
1094
- - VAR_1: \\"(hidden)\\"
1095
- - VAR_2: \\"original value 2\\"
1096
- - VAR_3: \\"(hidden)\\"
1097
- - VAR_MULTI_LINE_1: \\"(hidden)\\"
1098
- - VAR_MULTI_LINE_2: \\"(hidden)\\"
1099
- - EMPTY: \\"(hidden)\\"
1100
- - UNQUOTED: \\"(hidden)\\""
1101
- `);
1102
- expect(std.warn).toMatchInlineSnapshot(`""`);
1103
- expect(std.err).toMatchInlineSnapshot(`""`);
1104
- });
1105
-
1106
- it("should prefer `.dev.vars.<environment>` if `--env <environment> set`", async () => {
1107
- fs.writeFileSync("index.js", `export default {};`);
1108
- fs.writeFileSync(".dev.vars", "DEFAULT_VAR=default");
1109
- fs.writeFileSync(".dev.vars.custom", "CUSTOM_VAR=custom");
1110
-
1111
- writeWranglerToml({ main: "index.js", env: { custom: {} } });
1112
- await runWrangler("dev --env custom");
1113
- const varBindings: Record<string, unknown> = (Dev as jest.Mock).mock
1114
- .calls[0][0].bindings.vars;
1115
-
1116
- expect(varBindings).toEqual({ CUSTOM_VAR: "custom" });
1117
- expect(std.out).toMatchInlineSnapshot(`
1118
- "Using vars defined in .dev.vars.custom
1119
- Your worker has access to the following bindings:
1120
- - Vars:
1121
- - CUSTOM_VAR: \\"(hidden)\\""
1122
- `);
1123
- expect(std.warn).toMatchInlineSnapshot(`""`);
1124
- expect(std.err).toMatchInlineSnapshot(`""`);
1125
- });
1126
- });
1127
-
1128
- describe("serve static assets", () => {
1129
- it("should error if --site is used with no value", async () => {
1130
- await expect(
1131
- runWrangler("dev --site")
1132
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1133
- `"Not enough arguments following: site"`
1134
- );
1135
-
1136
- expect(std).toMatchInlineSnapshot(`
1137
- Object {
1138
- "debug": "",
1139
- "err": "X [ERROR] Not enough arguments following: site
1140
-
1141
- ",
1142
- "out": "
1143
- wrangler dev [script]
1144
-
1145
- 👂 Start a local server for developing your worker
1146
-
1147
- Positionals:
1148
- script The path to an entry point for your worker [string]
1149
-
1150
- Flags:
1151
- -c, --config Path to .toml configuration file [string]
1152
- -e, --env Environment to use for operations and .env files [string]
1153
- -h, --help Show help [boolean]
1154
- -v, --version Show version number [boolean]
1155
-
1156
- Options:
1157
- --name Name of the worker [string]
1158
- --no-bundle Skip internal build steps and directly publish script [boolean] [default: false]
1159
- --compatibility-date Date to use for compatibility checks [string]
1160
- --compatibility-flags, --compatibility-flag Flags to use for compatibility checks [array]
1161
- --latest Use the latest version of the worker runtime [boolean] [default: true]
1162
- --ip IP address to listen on [string]
1163
- --port Port to listen on [number]
1164
- --inspector-port Port for devtools to connect to [number]
1165
- --routes, --route Routes to upload [array]
1166
- --host Host to forward requests to, defaults to the zone of project [string]
1167
- --local-protocol Protocol to listen to requests on, defaults to http. [choices: \\"http\\", \\"https\\"]
1168
- --local-upstream Host to act as origin in local mode, defaults to dev.host or route [string]
1169
- --assets Static assets to be served [string]
1170
- --site Root folder of static assets for Workers Sites [string]
1171
- --site-include Array of .gitignore-style patterns that match file or directory names from the sites directory. Only matched items will be uploaded. [array]
1172
- --site-exclude Array of .gitignore-style patterns that match file or directory names from the sites directory. Matched items will not be uploaded. [array]
1173
- --upstream-protocol Protocol to forward requests to host on, defaults to https. [choices: \\"http\\", \\"https\\"]
1174
- --var A key-value pair to be injected into the script as a variable [array]
1175
- --define A key-value pair to be substituted in the script [array]
1176
- --jsx-factory The function that is called for each JSX element [string]
1177
- --jsx-fragment The function that is called for each JSX fragment [string]
1178
- --tsconfig Path to a custom tsconfig.json file [string]
1179
- -l, --local Run on my machine [boolean] [default: false]
1180
- --experimental-local Run on my machine using the Cloudflare Workers runtime [boolean] [default: false]
1181
- --minify Minify the script [boolean]
1182
- --node-compat Enable node.js compatibility [boolean]
1183
- --persist Enable persistence for local mode, using default path: .wrangler/state [boolean]
1184
- --persist-to Specify directory to use for local persistence (implies --persist) [string]
1185
- --test-scheduled Test scheduled events by visiting /__scheduled in browser [boolean] [default: false]
1186
- --log-level Specify logging level [choices: \\"debug\\", \\"info\\", \\"log\\", \\"warn\\", \\"error\\", \\"none\\"] [default: \\"log\\"]",
1187
- "warn": "",
1188
- }
1189
- `);
1190
- });
1191
-
1192
- it("should error if --assets and --site are used together", async () => {
1193
- writeWranglerToml({
1194
- main: "./index.js",
1195
- });
1196
- fs.writeFileSync("index.js", `export default {};`);
1197
- await expect(
1198
- runWrangler("dev --assets abc --site xyz")
1199
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1200
- `"Cannot use Assets and Workers Sites in the same Worker."`
1201
- );
1202
- });
1203
-
1204
- it("should error if --assets and config.site are used together", async () => {
1205
- writeWranglerToml({
1206
- main: "./index.js",
1207
- site: {
1208
- bucket: "xyz",
1209
- },
1210
- });
1211
- fs.writeFileSync("index.js", `export default {};`);
1212
- await expect(
1213
- runWrangler("dev --assets abc")
1214
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1215
- `"Cannot use Assets and Workers Sites in the same Worker."`
1216
- );
1217
- });
1218
-
1219
- it("should error if config.assets and --site are used together", async () => {
1220
- writeWranglerToml({
1221
- main: "./index.js",
1222
- // @ts-expect-error we allow string inputs here
1223
- assets: "abc",
1224
- });
1225
- fs.writeFileSync("index.js", `export default {};`);
1226
- await expect(
1227
- runWrangler("dev --site xyz")
1228
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1229
- `"Cannot use Assets and Workers Sites in the same Worker."`
1230
- );
1231
- });
1232
-
1233
- it("should error if config.assets and config.site are used together", async () => {
1234
- writeWranglerToml({
1235
- main: "./index.js",
1236
- // @ts-expect-error we allow string inputs here
1237
- assets: "abc",
1238
- site: {
1239
- bucket: "xyz",
1240
- },
1241
- });
1242
- fs.writeFileSync("index.js", `export default {};`);
1243
- await expect(
1244
- runWrangler("dev --assets abc")
1245
- ).rejects.toThrowErrorMatchingInlineSnapshot(
1246
- `"Cannot use Assets and Workers Sites in the same Worker."`
1247
- );
1248
- });
1249
-
1250
- it("should indicate whether Sites is being used", async () => {
1251
- writeWranglerToml({
1252
- main: "index.js",
1253
- });
1254
- fs.writeFileSync("index.js", `export default {};`);
1255
-
1256
- await runWrangler("dev");
1257
- expect((Dev as jest.Mock).mock.calls[0][0].isWorkersSite).toEqual(false);
1258
-
1259
- await runWrangler("dev --site abc");
1260
- expect((Dev as jest.Mock).mock.calls[1][0].isWorkersSite).toEqual(true);
1261
-
1262
- await runWrangler("dev --assets abc");
1263
- expect((Dev as jest.Mock).mock.calls[2][0].isWorkersSite).toEqual(false);
1264
- });
1265
- it("should warn if --assets is used", async () => {
1266
- writeWranglerToml({
1267
- main: "./index.js",
1268
- });
1269
- fs.writeFileSync("index.js", `export default {};`);
1270
-
1271
- await runWrangler('dev --assets "./assets"');
1272
- expect(std).toMatchInlineSnapshot(`
1273
- Object {
1274
- "debug": "",
1275
- "err": "",
1276
- "out": "",
1277
- "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1278
-
1279
- ",
1280
- }
1281
- `);
1282
- });
1283
-
1284
- it("should warn if config.assets is used", async () => {
1285
- writeWranglerToml({
1286
- main: "./index.js",
1287
- // @ts-expect-error we allow string inputs here
1288
- assets: "./assets",
1289
- });
1290
- fs.writeFileSync("index.js", `export default {};`);
1291
-
1292
- await runWrangler("dev");
1293
- expect(std).toMatchInlineSnapshot(`
1294
- Object {
1295
- "debug": "",
1296
- "err": "",
1297
- "out": "",
1298
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1299
-
1300
- - \\"assets\\" fields are experimental and may change or break at any time.
1301
-
1302
- ",
1303
- }
1304
- `);
1305
- });
1306
- });
1307
-
1308
- describe("--inspect", () => {
1309
- it("should warn if --inspect is used", async () => {
1310
- fs.writeFileSync("index.js", `export default {};`);
1311
- await runWrangler("dev index.js --inspect");
1312
- expect(std).toMatchInlineSnapshot(`
1313
- Object {
1314
- "debug": "",
1315
- "err": "",
1316
- "out": "",
1317
- "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1318
-
1319
- ",
1320
- }
1321
- `);
1322
- });
1323
-
1324
- it("should default to true, without a warning", async () => {
1325
- fs.writeFileSync("index.js", `export default {};`);
1326
- await runWrangler("dev index.js");
1327
- expect((Dev as jest.Mock).mock.calls[0][0].inspect).toEqual(true);
1328
- expect(std).toMatchInlineSnapshot(`
1329
- Object {
1330
- "debug": "",
1331
- "err": "",
1332
- "out": "",
1333
- "warn": "",
1334
- }
1335
- `);
1336
- });
1337
-
1338
- it("should pass true, with a warning", async () => {
1339
- fs.writeFileSync("index.js", `export default {};`);
1340
- await runWrangler("dev index.js --inspect");
1341
- expect((Dev as jest.Mock).mock.calls[0][0].inspect).toEqual(true);
1342
- expect(std).toMatchInlineSnapshot(`
1343
- Object {
1344
- "debug": "",
1345
- "err": "",
1346
- "out": "",
1347
- "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1348
-
1349
- ",
1350
- }
1351
- `);
1352
- });
1353
-
1354
- it("should pass false, without a warning", async () => {
1355
- fs.writeFileSync("index.js", `export default {};`);
1356
- await runWrangler("dev index.js --inspect false");
1357
- expect((Dev as jest.Mock).mock.calls[0][0].inspect).toEqual(false);
1358
- expect(std).toMatchInlineSnapshot(`
1359
- Object {
1360
- "debug": "",
1361
- "err": "",
1362
- "out": "",
1363
- "warn": "",
1364
- }
1365
- `);
1366
- });
1367
- });
1368
-
1369
- describe("--log-level", () => {
1370
- it("should not output warnings with log-level 'none'", async () => {
1371
- fs.writeFileSync("index.js", `export default {};`);
1372
- await runWrangler("dev index.js --inspect --log-level none");
1373
- expect(std).toMatchInlineSnapshot(`
1374
- Object {
1375
- "debug": "",
1376
- "err": "",
1377
- "out": "",
1378
- "warn": "",
1379
- }
1380
- `);
1381
- });
1382
-
1383
- it("should output warnings with log-level 'warn'", async () => {
1384
- fs.writeFileSync("index.js", `export default {};`);
1385
- await runWrangler("dev index.js --inspect --log-level warn");
1386
- expect(std).toMatchInlineSnapshot(`
1387
- Object {
1388
- "debug": "",
1389
- "err": "",
1390
- "out": "",
1391
- "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1392
-
1393
- ",
1394
- }
1395
- `);
1396
- });
1397
-
1398
- it("should not output Errors with log-level error", async () => {
1399
- fs.writeFileSync("index.js", `export default {};`);
1400
- await runWrangler("dev index.js --inspect --log-level debug");
1401
- expect(std.debug.length > 1).toBe(true);
1402
- });
1403
- });
1404
-
1405
- describe("service bindings", () => {
1406
- it("should warn when using service bindings", async () => {
1407
- writeWranglerToml({
1408
- services: [
1409
- { binding: "WorkerA", service: "A" },
1410
- { binding: "WorkerB", service: "B", environment: "staging" },
1411
- ],
1412
- });
1413
- fs.writeFileSync("index.js", `export default {};`);
1414
- await runWrangler("dev index.js");
1415
- expect(std.out).toMatchInlineSnapshot(`
1416
- "Your worker has access to the following bindings:
1417
- - Services:
1418
- - WorkerA: A
1419
- - WorkerB: B - staging"
1420
- `);
1421
- expect(std.warn).toMatchInlineSnapshot(`
1422
- "▲ [WARNING] Processing wrangler.toml configuration:
1423
-
1424
- - \\"services\\" fields are experimental and may change or break at any time.
1425
-
1426
-
1427
- ▲ [WARNING] This worker is bound to live services: WorkerA (A), WorkerB (B@staging)
1428
-
1429
- "
1430
- `);
1431
- expect(std.err).toMatchInlineSnapshot(`""`);
1432
- });
1433
- });
1434
-
1435
- describe("print bindings", () => {
1436
- it("should print bindings", async () => {
1437
- writeWranglerToml({
1438
- services: [
1439
- { binding: "WorkerA", service: "A" },
1440
- { binding: "WorkerB", service: "B", environment: "staging" },
1441
- ],
1442
- });
1443
- fs.writeFileSync("index.js", `export default {};`);
1444
- await runWrangler("dev index.js");
1445
- expect(std).toMatchInlineSnapshot(`
1446
- Object {
1447
- "debug": "",
1448
- "err": "",
1449
- "out": "Your worker has access to the following bindings:
1450
- - Services:
1451
- - WorkerA: A
1452
- - WorkerB: B - staging",
1453
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1454
-
1455
- - \\"services\\" fields are experimental and may change or break at any time.
1456
-
1457
-
1458
- ▲ [WARNING] This worker is bound to live services: WorkerA (A), WorkerB (B@staging)
1459
-
1460
- ",
1461
- }
1462
- `);
1463
- });
1464
-
1465
- it("should mask vars that were overriden in .dev.vars", async () => {
1466
- writeWranglerToml({
1467
- vars: {
1468
- variable: 123,
1469
- overriden: "original values",
1470
- },
1471
- });
1472
- fs.writeFileSync(
1473
- ".dev.vars",
1474
- `
1475
- SECRET = "A secret"
1476
- overriden = "overriden value"
1477
- `
1478
- );
1479
- fs.writeFileSync("index.js", `export default {};`);
1480
- await runWrangler("dev index.js");
1481
- expect(std).toMatchInlineSnapshot(`
1482
- Object {
1483
- "debug": "",
1484
- "err": "",
1485
- "out": "Using vars defined in .dev.vars
1486
- Your worker has access to the following bindings:
1487
- - Vars:
1488
- - variable: 123
1489
- - overriden: \\"(hidden)\\"
1490
- - SECRET: \\"(hidden)\\"",
1491
- "warn": "",
1492
- }
1493
- `);
1494
- });
1495
- });
1496
- });
1497
-
1498
- function mockGetZones(domain: string, zones: { id: string }[] = []) {
1499
- const removeMock = setMockResponse(
1500
- "/zones",
1501
- "GET",
1502
- (_urlPieces, _init, queryParams) => {
1503
- expect([...queryParams.entries()]).toEqual([["name", domain]]);
1504
- // 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.
1505
- removeMock();
1506
- return zones;
1507
- }
1508
- );
1509
- }