wrangler 0.0.0-e64812e → 0.0.0-e6488257

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 (185) hide show
  1. package/README.md +29 -11
  2. package/bin/wrangler.js +86 -67
  3. package/config-schema.json +2947 -0
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +114 -77
  6. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  7. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  8. package/templates/__tests__/tsconfig.json +8 -0
  9. package/templates/checked-fetch.js +30 -0
  10. package/templates/facade.d.ts +19 -0
  11. package/templates/gitignore +0 -4
  12. package/templates/init-tests/test-jest-new-worker.js +23 -0
  13. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  14. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  15. package/templates/middleware/common.ts +67 -0
  16. package/templates/middleware/loader-modules.ts +134 -0
  17. package/templates/middleware/loader-sw.ts +229 -0
  18. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  19. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  20. package/templates/middleware/middleware-pretty-error.ts +40 -0
  21. package/templates/middleware/middleware-scheduled.ts +15 -0
  22. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  23. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  24. package/templates/modules-watch-stub.js +4 -0
  25. package/templates/new-worker-scheduled.js +3 -3
  26. package/templates/new-worker-scheduled.ts +16 -16
  27. package/templates/new-worker.js +3 -3
  28. package/templates/new-worker.ts +19 -16
  29. package/templates/no-op-worker.js +10 -0
  30. package/templates/pages-dev-pipeline.ts +32 -0
  31. package/templates/pages-dev-util.ts +55 -0
  32. package/templates/pages-shim.ts +9 -0
  33. package/templates/pages-template-plugin.ts +190 -0
  34. package/templates/pages-template-worker.ts +198 -0
  35. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  36. package/templates/startDevWorker/ProxyWorker.ts +334 -0
  37. package/templates/tsconfig-sanity.ts +11 -0
  38. package/templates/tsconfig.init.json +105 -0
  39. package/templates/tsconfig.json +6 -103
  40. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  41. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  42. package/wrangler-dist/ProxyWorker.js +240 -0
  43. package/wrangler-dist/ProxyWorker.js.map +6 -0
  44. package/wrangler-dist/cli.d.ts +24215 -0
  45. package/wrangler-dist/cli.js +188741 -107044
  46. package/wrangler-dist/wasm-sync.wasm +0 -0
  47. package/Cloudflare_CA.pem +0 -18
  48. package/import_meta_url.js +0 -3
  49. package/miniflare-config-stubs/.env.empty +0 -0
  50. package/miniflare-config-stubs/package.empty.json +0 -1
  51. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  52. package/miniflare-dist/index.mjs +0 -4886
  53. package/pages/functions/buildPlugin.ts +0 -105
  54. package/pages/functions/buildWorker.ts +0 -151
  55. package/pages/functions/filepath-routing.test.ts +0 -234
  56. package/pages/functions/filepath-routing.ts +0 -189
  57. package/pages/functions/identifiers.ts +0 -78
  58. package/pages/functions/routes.ts +0 -156
  59. package/pages/functions/template-plugin.ts +0 -147
  60. package/pages/functions/template-worker.ts +0 -143
  61. package/src/__tests__/config-cache.test.ts +0 -36
  62. package/src/__tests__/configuration.test.ts +0 -3374
  63. package/src/__tests__/dev.test.tsx +0 -980
  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/faye-websocket.d.ts +0 -6
  68. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  69. package/src/__tests__/helpers/mock-bin.ts +0 -36
  70. package/src/__tests__/helpers/mock-cfetch.ts +0 -211
  71. package/src/__tests__/helpers/mock-console.ts +0 -87
  72. package/src/__tests__/helpers/mock-dialogs.ts +0 -130
  73. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  74. package/src/__tests__/helpers/mock-istty.ts +0 -27
  75. package/src/__tests__/helpers/mock-kv.ts +0 -33
  76. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -255
  77. package/src/__tests__/helpers/mock-stdin.ts +0 -103
  78. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  79. package/src/__tests__/helpers/run-in-tmp.ts +0 -39
  80. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  81. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  82. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  83. package/src/__tests__/https-options.test.ts +0 -130
  84. package/src/__tests__/index.test.ts +0 -256
  85. package/src/__tests__/init.test.ts +0 -1634
  86. package/src/__tests__/jest.setup.ts +0 -77
  87. package/src/__tests__/kv.test.ts +0 -1481
  88. package/src/__tests__/logger.test.ts +0 -115
  89. package/src/__tests__/package-manager.test.ts +0 -353
  90. package/src/__tests__/pages.test.ts +0 -754
  91. package/src/__tests__/parse.test.ts +0 -330
  92. package/src/__tests__/publish.test.ts +0 -5468
  93. package/src/__tests__/r2.test.ts +0 -233
  94. package/src/__tests__/route.test.ts +0 -45
  95. package/src/__tests__/secret.test.ts +0 -481
  96. package/src/__tests__/tail.test.ts +0 -690
  97. package/src/__tests__/user.test.ts +0 -131
  98. package/src/__tests__/whoami.test.tsx +0 -105
  99. package/src/abort.d.ts +0 -3
  100. package/src/bundle.ts +0 -200
  101. package/src/cfetch/index.ts +0 -121
  102. package/src/cfetch/internal.ts +0 -145
  103. package/src/cli.ts +0 -13
  104. package/src/config/README.md +0 -107
  105. package/src/config/config.ts +0 -234
  106. package/src/config/diagnostics.ts +0 -80
  107. package/src/config/environment.ts +0 -420
  108. package/src/config/index.ts +0 -225
  109. package/src/config/validation-helpers.ts +0 -575
  110. package/src/config/validation.ts +0 -1539
  111. package/src/config-cache.ts +0 -45
  112. package/src/create-worker-preview.ts +0 -185
  113. package/src/create-worker-upload-form.ts +0 -254
  114. package/src/dev/dev-vars.ts +0 -36
  115. package/src/dev/dev.tsx +0 -419
  116. package/src/dev/local.tsx +0 -318
  117. package/src/dev/remote.tsx +0 -227
  118. package/src/dev/use-esbuild.ts +0 -118
  119. package/src/dialogs.tsx +0 -135
  120. package/src/durable.ts +0 -102
  121. package/src/entry.ts +0 -322
  122. package/src/environment-variables.ts +0 -35
  123. package/src/errors.ts +0 -11
  124. package/src/https-options.ts +0 -123
  125. package/src/index.tsx +0 -2864
  126. package/src/inspect.ts +0 -662
  127. package/src/intl-polyfill.d.ts +0 -139
  128. package/src/kv.ts +0 -408
  129. package/src/logger.ts +0 -66
  130. package/src/miniflare-cli/README.md +0 -30
  131. package/src/miniflare-cli/enum-keys.ts +0 -17
  132. package/src/miniflare-cli/index.ts +0 -41
  133. package/src/miniflare-cli/request-context.ts +0 -40
  134. package/src/module-collection.ts +0 -258
  135. package/src/open-in-browser.ts +0 -19
  136. package/src/package-manager.ts +0 -174
  137. package/src/pages.tsx +0 -2038
  138. package/src/parse.ts +0 -202
  139. package/src/paths.ts +0 -26
  140. package/src/proxy.ts +0 -465
  141. package/src/publish.ts +0 -583
  142. package/src/r2.ts +0 -50
  143. package/src/selfsigned.d.ts +0 -29
  144. package/src/sites.tsx +0 -295
  145. package/src/tail/filters.ts +0 -279
  146. package/src/tail/index.ts +0 -299
  147. package/src/tail/printing.ts +0 -67
  148. package/src/update-check.ts +0 -19
  149. package/src/user.tsx +0 -1203
  150. package/src/whoami.tsx +0 -70
  151. package/src/worker.ts +0 -180
  152. package/templates/static-asset-facade.js +0 -47
  153. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  154. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  155. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  156. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  157. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  158. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  159. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  160. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  161. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  162. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  163. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  164. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  165. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  166. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  167. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  168. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  169. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  170. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  171. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  172. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  173. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  174. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  175. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  176. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  177. package/vendor/wrangler-mime/LICENSE +0 -21
  178. package/vendor/wrangler-mime/Mime.js +0 -97
  179. package/vendor/wrangler-mime/README.md +0 -187
  180. package/vendor/wrangler-mime/cli.js +0 -46
  181. package/vendor/wrangler-mime/index.js +0 -4
  182. package/vendor/wrangler-mime/lite.js +0 -4
  183. package/vendor/wrangler-mime/package.json +0 -52
  184. package/vendor/wrangler-mime/types/other.js +0 -1
  185. package/vendor/wrangler-mime/types/standard.js +0 -1
@@ -1,980 +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 { runInTempDir } from "./helpers/run-in-tmp";
10
- import { runWrangler } from "./helpers/run-wrangler";
11
- import writeWranglerToml from "./helpers/write-wrangler-toml";
12
-
13
- describe("wrangler dev", () => {
14
- mockAccountId();
15
- mockApiToken();
16
- runInTempDir();
17
- const std = mockConsoleMethods();
18
- afterEach(() => {
19
- (Dev as jest.Mock).mockClear();
20
- patchConsole(() => {});
21
- unsetAllMocks();
22
- });
23
-
24
- describe("compatibility-date", () => {
25
- it("should not warn if there is no wrangler.toml and no compatibility-date specified", async () => {
26
- fs.writeFileSync("index.js", `export default {};`);
27
- await runWrangler("dev index.js");
28
- expect(std.out).toMatchInlineSnapshot(`""`);
29
- expect(std.warn).toMatchInlineSnapshot(`""`);
30
- expect(std.err).toMatchInlineSnapshot(`""`);
31
- });
32
-
33
- it("should warn if there is a wrangler.toml but no compatibility-date", async () => {
34
- writeWranglerToml({
35
- main: "index.js",
36
- compatibility_date: undefined,
37
- });
38
- fs.writeFileSync("index.js", `export default {};`);
39
- await runWrangler("dev");
40
- const currentDate = new Date().toISOString().substring(0, 10);
41
- expect(std.out).toMatchInlineSnapshot(`""`);
42
- expect(std.warn.replaceAll(currentDate, "<current-date>"))
43
- .toMatchInlineSnapshot(`
44
- "▲ [WARNING] No compatibility_date was specified. Using today's date: <current-date>.
45
-
46
- Add one to your wrangler.toml file:
47
- \`\`\`
48
- compatibility_date = \\"<current-date>\\"
49
- \`\`\`
50
- or pass it in your terminal:
51
- \`\`\`
52
- --compatibility-date=<current-date>
53
- \`\`\`
54
- See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information.
55
-
56
- "
57
- `);
58
- expect(std.err).toMatchInlineSnapshot(`""`);
59
- });
60
-
61
- it("should not warn if there is a wrangler.toml but compatibility-date is specified at the command line", async () => {
62
- writeWranglerToml({
63
- main: "index.js",
64
- compatibility_date: undefined,
65
- });
66
- fs.writeFileSync("index.js", `export default {};`);
67
- await runWrangler("dev --compatibility-date=2020-01-01");
68
- expect(std.out).toMatchInlineSnapshot(`""`);
69
- expect(std.warn).toMatchInlineSnapshot(`""`);
70
- expect(std.err).toMatchInlineSnapshot(`""`);
71
- });
72
- });
73
-
74
- describe("entry-points", () => {
75
- it("should error if there is no entry-point specified", async () => {
76
- writeWranglerToml();
77
-
78
- await expect(
79
- runWrangler("dev")
80
- ).rejects.toThrowErrorMatchingInlineSnapshot(
81
- `"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."`
82
- );
83
-
84
- expect(std.out).toMatchInlineSnapshot(`
85
- "
86
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
87
- `);
88
- expect(std.err).toMatchInlineSnapshot(`
89
- "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.
90
-
91
- "
92
- `);
93
- });
94
-
95
- it("should use `main` from the top-level environment", async () => {
96
- writeWranglerToml({
97
- main: "index.js",
98
- });
99
- fs.writeFileSync("index.js", `export default {};`);
100
- await runWrangler("dev");
101
- expect((Dev as jest.Mock).mock.calls[0][0].entry.file).toMatch(
102
- /index\.js$/
103
- );
104
- expect(std.out).toMatchInlineSnapshot(`""`);
105
- expect(std.warn).toMatchInlineSnapshot(`""`);
106
- expect(std.err).toMatchInlineSnapshot(`""`);
107
- });
108
-
109
- it("should use `main` from a named environment", async () => {
110
- writeWranglerToml({
111
- env: {
112
- ENV1: {
113
- main: "index.js",
114
- },
115
- },
116
- });
117
- fs.writeFileSync("index.js", `export default {};`);
118
- await runWrangler("dev --env=ENV1");
119
- expect((Dev as jest.Mock).mock.calls[0][0].entry.file).toMatch(
120
- /index\.js$/
121
- );
122
- expect(std.out).toMatchInlineSnapshot(`""`);
123
- expect(std.warn).toMatchInlineSnapshot(`""`);
124
- expect(std.err).toMatchInlineSnapshot(`""`);
125
- });
126
-
127
- it("should use `main` from a named environment, rather than the top-level", async () => {
128
- writeWranglerToml({
129
- main: "other.js",
130
- env: {
131
- ENV1: {
132
- main: "index.js",
133
- },
134
- },
135
- });
136
- fs.writeFileSync("index.js", `export default {};`);
137
- await runWrangler("dev --env=ENV1");
138
- expect((Dev as jest.Mock).mock.calls[0][0].entry.file).toMatch(
139
- /index\.js$/
140
- );
141
- expect(std.out).toMatchInlineSnapshot(`""`);
142
- expect(std.warn).toMatchInlineSnapshot(`""`);
143
- expect(std.err).toMatchInlineSnapshot(`""`);
144
- });
145
- });
146
-
147
- describe("host", () => {
148
- it("should resolve a host to its zone", async () => {
149
- writeWranglerToml({
150
- main: "index.js",
151
- });
152
- fs.writeFileSync("index.js", `export default {};`);
153
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
154
- await runWrangler("dev --host some-host.com");
155
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
156
- host: "some-host.com",
157
- id: "some-zone-id",
158
- });
159
- });
160
-
161
- it("should read wrangler.toml's dev.host", async () => {
162
- writeWranglerToml({
163
- main: "index.js",
164
- dev: {
165
- host: "some-host.com",
166
- },
167
- });
168
- fs.writeFileSync("index.js", `export default {};`);
169
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
170
- await runWrangler("dev");
171
- expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
172
- "some-host.com"
173
- );
174
- });
175
-
176
- it("should read --route", async () => {
177
- writeWranglerToml({
178
- main: "index.js",
179
- });
180
- fs.writeFileSync("index.js", `export default {};`);
181
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
182
- await runWrangler("dev --route http://some-host.com/some/path/*");
183
- expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
184
- "some-host.com"
185
- );
186
- });
187
-
188
- it("should read wrangler.toml's routes", async () => {
189
- writeWranglerToml({
190
- main: "index.js",
191
- routes: [
192
- "http://some-host.com/some/path/*",
193
- "http://some-other-host.com/path/*",
194
- ],
195
- });
196
- fs.writeFileSync("index.js", `export default {};`);
197
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
198
- await runWrangler("dev");
199
- expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
200
- "some-host.com"
201
- );
202
- });
203
-
204
- it("should read wrangler.toml's environment specific routes", async () => {
205
- writeWranglerToml({
206
- main: "index.js",
207
- routes: [
208
- "http://a-host.com/some/path/*",
209
- "http://another-host.com/path/*",
210
- ],
211
- env: {
212
- staging: {
213
- routes: [
214
- "http://some-host.com/some/path/*",
215
- "http://some-other-host.com/path/*",
216
- ],
217
- },
218
- },
219
- });
220
- fs.writeFileSync("index.js", `export default {};`);
221
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
222
- await runWrangler("dev --env staging");
223
- expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
224
- "some-host.com"
225
- );
226
- });
227
-
228
- it("should strip leading `*` from given host when deducing a zone id", async () => {
229
- writeWranglerToml({
230
- main: "index.js",
231
- route: "*some-host.com/some/path/*",
232
- });
233
- fs.writeFileSync("index.js", `export default {};`);
234
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
235
- await runWrangler("dev");
236
- expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
237
- "some-host.com"
238
- );
239
- });
240
-
241
- it("should strip leading `*.` from given host when deducing a zone id", async () => {
242
- writeWranglerToml({
243
- main: "index.js",
244
- route: "*.some-host.com/some/path/*",
245
- });
246
- fs.writeFileSync("index.js", `export default {};`);
247
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
248
- await runWrangler("dev");
249
- expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
250
- "some-host.com"
251
- );
252
- });
253
-
254
- it("should, when provided, use a configured zone_id", async () => {
255
- writeWranglerToml({
256
- main: "index.js",
257
- routes: [
258
- { pattern: "https://some-domain.com/*", zone_id: "some-zone-id" },
259
- ],
260
- });
261
- fs.writeFileSync("index.js", `export default {};`);
262
- await runWrangler("dev");
263
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
264
- host: "some-domain.com",
265
- id: "some-zone-id",
266
- });
267
- });
268
-
269
- it("should, when provided, use a zone_name to get a zone_id", async () => {
270
- writeWranglerToml({
271
- main: "index.js",
272
- routes: [
273
- { pattern: "https://some-domain.com/*", zone_name: "some-zone.com" },
274
- ],
275
- });
276
- fs.writeFileSync("index.js", `export default {};`);
277
- mockGetZones("some-zone.com", [{ id: "a-zone-id" }]);
278
- await runWrangler("dev");
279
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
280
- // note that it uses the provided zone_name as a host too
281
- host: "some-zone.com",
282
- id: "a-zone-id",
283
- });
284
- });
285
-
286
- it("given a long host, it should use the longest subdomain that resolves to a zone", async () => {
287
- writeWranglerToml({
288
- main: "index.js",
289
- });
290
- fs.writeFileSync("index.js", `export default {};`);
291
- mockGetZones("111.222.333.some-host.com", []);
292
- mockGetZones("222.333.some-host.com", []);
293
- mockGetZones("333.some-host.com", [{ id: "some-zone-id" }]);
294
- await runWrangler("dev --host 111.222.333.some-host.com");
295
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
296
- host: "111.222.333.some-host.com",
297
- id: "some-zone-id",
298
- });
299
- });
300
-
301
- it("should, in order, use args.host/config.dev.host/args.routes/(config.route|config.routes)", async () => {
302
- // This test might seem like it's testing implementation details, but let's be specific and consider it a spec
303
-
304
- fs.writeFileSync("index.js", `export default {};`);
305
-
306
- // config.routes
307
- mockGetZones("5.some-host.com", [{ id: "some-zone-id-5" }]);
308
- writeWranglerToml({
309
- main: "index.js",
310
- routes: ["http://5.some-host.com/some/path/*"],
311
- });
312
- await runWrangler("dev");
313
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
314
- host: "5.some-host.com",
315
- id: "some-zone-id-5",
316
- });
317
- (Dev as jest.Mock).mockClear();
318
-
319
- // config.route
320
- mockGetZones("4.some-host.com", [{ id: "some-zone-id-4" }]);
321
- writeWranglerToml({
322
- main: "index.js",
323
- route: "https://4.some-host.com/some/path/*",
324
- });
325
- await runWrangler("dev");
326
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
327
- host: "4.some-host.com",
328
- id: "some-zone-id-4",
329
- });
330
- (Dev as jest.Mock).mockClear();
331
-
332
- // --routes
333
- mockGetZones("3.some-host.com", [{ id: "some-zone-id-3" }]);
334
- writeWranglerToml({
335
- main: "index.js",
336
- route: "https://4.some-host.com/some/path/*",
337
- });
338
- await runWrangler("dev --routes http://3.some-host.com/some/path/*");
339
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
340
- host: "3.some-host.com",
341
- id: "some-zone-id-3",
342
- });
343
- (Dev as jest.Mock).mockClear();
344
-
345
- // config.dev.host
346
- mockGetZones("2.some-host.com", [{ id: "some-zone-id-2" }]);
347
- writeWranglerToml({
348
- main: "index.js",
349
- dev: {
350
- host: `2.some-host.com`,
351
- },
352
- route: "4.some-host.com/some/path/*",
353
- });
354
- await runWrangler("dev --routes http://3.some-host.com/some/path/*");
355
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
356
- host: "2.some-host.com",
357
- id: "some-zone-id-2",
358
- });
359
- (Dev as jest.Mock).mockClear();
360
-
361
- // --host
362
- mockGetZones("1.some-host.com", [{ id: "some-zone-id-1" }]);
363
- writeWranglerToml({
364
- main: "index.js",
365
- dev: {
366
- host: `2.some-host.com`,
367
- },
368
- route: "4.some-host.com/some/path/*",
369
- });
370
- await runWrangler(
371
- "dev --routes http://3.some-host.com/some/path/* --host 1.some-host.com"
372
- );
373
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
374
- host: "1.some-host.com",
375
- id: "some-zone-id-1",
376
- });
377
- (Dev as jest.Mock).mockClear();
378
- });
379
-
380
- it("should error if a host can't resolve to a zone", async () => {
381
- writeWranglerToml({
382
- main: "index.js",
383
- });
384
- fs.writeFileSync("index.js", `export default {};`);
385
- mockGetZones("some-host.com", []);
386
- await expect(
387
- runWrangler("dev --host some-host.com")
388
- ).rejects.toThrowErrorMatchingInlineSnapshot(
389
- `"Could not find zone for some-host.com"`
390
- );
391
- });
392
-
393
- it("should not try to resolve a zone when starting in local mode", async () => {
394
- writeWranglerToml({
395
- main: "index.js",
396
- });
397
- fs.writeFileSync("index.js", `export default {};`);
398
- await runWrangler("dev --host some-host.com --local");
399
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual(undefined);
400
- });
401
- });
402
-
403
- describe("custom builds", () => {
404
- it("should run a custom build before starting `dev`", async () => {
405
- writeWranglerToml({
406
- build: {
407
- command: `node -e "console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')"`,
408
- },
409
- });
410
-
411
- await runWrangler("dev index.js");
412
-
413
- expect(fs.readFileSync("index.js", "utf-8")).toMatchInlineSnapshot(
414
- `"export default { fetch(){ return new Response(123) } }"`
415
- );
416
-
417
- // and the command would pass through
418
- expect((Dev as jest.Mock).mock.calls[0][0].build).toEqual({
419
- command:
420
- "node -e \"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\"",
421
- cwd: undefined,
422
- watch_dir: "src",
423
- });
424
- expect(std.out).toMatchInlineSnapshot(
425
- `"Running custom build: node -e \\"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\""`
426
- );
427
- expect(std.err).toMatchInlineSnapshot(`""`);
428
- expect(std.warn).toMatchInlineSnapshot(`""`);
429
- });
430
-
431
- if (process.platform !== "win32") {
432
- it("should run a custom build of multiple steps combined by && before starting `dev`", async () => {
433
- writeWranglerToml({
434
- build: {
435
- command: `echo "custom build" && echo "export default { fetch(){ return new Response(123) } }" > index.js`,
436
- },
437
- });
438
-
439
- await runWrangler("dev index.js");
440
-
441
- expect(fs.readFileSync("index.js", "utf-8")).toMatchInlineSnapshot(`
442
- "export default { fetch(){ return new Response(123) } }
443
- "
444
- `);
445
-
446
- expect(std.out).toMatchInlineSnapshot(
447
- `"Running custom build: echo \\"custom build\\" && echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js"`
448
- );
449
- expect(std.err).toMatchInlineSnapshot(`""`);
450
- expect(std.warn).toMatchInlineSnapshot(`""`);
451
- });
452
- }
453
-
454
- it("should throw an error if the entry doesn't exist after the build finishes", async () => {
455
- writeWranglerToml({
456
- main: "index.js",
457
- build: {
458
- command: `node -e "console.log('custom build');"`,
459
- },
460
- });
461
-
462
- await expect(runWrangler("dev")).rejects
463
- .toThrowErrorMatchingInlineSnapshot(`
464
- "The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
465
- The \`main\` property in wrangler.toml should point to the file generated by the custom build."
466
- `);
467
- expect(std.out).toMatchInlineSnapshot(`
468
- "Running custom build: node -e \\"console.log('custom build');\\"
469
-
470
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
471
- `);
472
- expect(std.err).toMatchInlineSnapshot(`
473
- "X [ERROR] The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
474
-
475
- The \`main\` property in wrangler.toml should point to the file generated by the custom build.
476
-
477
- "
478
- `);
479
- expect(std.warn).toMatchInlineSnapshot(`""`);
480
- });
481
- });
482
-
483
- describe("upstream-protocol", () => {
484
- it("should default upstream-protocol to `https`", async () => {
485
- writeWranglerToml({
486
- main: "index.js",
487
- });
488
- fs.writeFileSync("index.js", `export default {};`);
489
- await runWrangler("dev");
490
- expect((Dev as jest.Mock).mock.calls[0][0].upstreamProtocol).toEqual(
491
- "https"
492
- );
493
- expect(std.out).toMatchInlineSnapshot(`""`);
494
- expect(std.warn).toMatchInlineSnapshot(`""`);
495
- expect(std.err).toMatchInlineSnapshot(`""`);
496
- });
497
-
498
- it("should warn if `--upstream-protocol=http` is used", async () => {
499
- writeWranglerToml({
500
- main: "index.js",
501
- });
502
- fs.writeFileSync("index.js", `export default {};`);
503
- await runWrangler("dev --upstream-protocol=http");
504
- expect((Dev as jest.Mock).mock.calls[0][0].upstreamProtocol).toEqual(
505
- "http"
506
- );
507
- expect(std.out).toMatchInlineSnapshot(`""`);
508
- expect(std.warn).toMatchInlineSnapshot(`
509
- "▲ [WARNING] Setting upstream-protocol to http is not currently implemented.
510
-
511
- If this is required in your project, please add your use case to the following issue:
512
- https://github.com/cloudflare/wrangler2/issues/583.
513
-
514
- "
515
- `);
516
- expect(std.err).toMatchInlineSnapshot(`""`);
517
- });
518
- });
519
-
520
- describe("local-protocol", () => {
521
- it("should default local-protocol to `http`", async () => {
522
- writeWranglerToml({
523
- main: "index.js",
524
- });
525
- fs.writeFileSync("index.js", `export default {};`);
526
- await runWrangler("dev");
527
- expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual("http");
528
- expect(std.out).toMatchInlineSnapshot(`""`);
529
- expect(std.warn).toMatchInlineSnapshot(`""`);
530
- expect(std.err).toMatchInlineSnapshot(`""`);
531
- });
532
-
533
- it("should use `local_protocol` from `wrangler.toml`, if available", async () => {
534
- writeWranglerToml({
535
- main: "index.js",
536
- dev: {
537
- local_protocol: "https",
538
- },
539
- });
540
- fs.writeFileSync("index.js", `export default {};`);
541
- await runWrangler("dev");
542
- expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual(
543
- "https"
544
- );
545
- expect(std.out).toMatchInlineSnapshot(`""`);
546
- expect(std.warn).toMatchInlineSnapshot(`""`);
547
- expect(std.err).toMatchInlineSnapshot(`""`);
548
- });
549
-
550
- it("should use --local-protocol command line arg, if provided", async () => {
551
- // Here we show that the command line overrides the wrangler.toml by
552
- // setting the config to https, and then setting it back to http on the command line.
553
- writeWranglerToml({
554
- main: "index.js",
555
- dev: {
556
- local_protocol: "https",
557
- },
558
- });
559
- fs.writeFileSync("index.js", `export default {};`);
560
- await runWrangler("dev --local-protocol=http");
561
- expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual("http");
562
- expect(std.out).toMatchInlineSnapshot(`""`);
563
- expect(std.warn).toMatchInlineSnapshot(`""`);
564
- expect(std.err).toMatchInlineSnapshot(`""`);
565
- });
566
- });
567
-
568
- describe("ip", () => {
569
- it("should default ip to localhost", async () => {
570
- writeWranglerToml({
571
- main: "index.js",
572
- });
573
- fs.writeFileSync("index.js", `export default {};`);
574
- await runWrangler("dev");
575
- expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("localhost");
576
- expect(std.out).toMatchInlineSnapshot(`""`);
577
- expect(std.warn).toMatchInlineSnapshot(`""`);
578
- expect(std.err).toMatchInlineSnapshot(`""`);
579
- });
580
-
581
- it("should use to `ip` from `wrangler.toml`, if available", async () => {
582
- writeWranglerToml({
583
- main: "index.js",
584
- dev: {
585
- ip: "0.0.0.0",
586
- },
587
- });
588
- fs.writeFileSync("index.js", `export default {};`);
589
- await runWrangler("dev");
590
- expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("0.0.0.0");
591
- expect(std.out).toMatchInlineSnapshot(`""`);
592
- expect(std.warn).toMatchInlineSnapshot(`""`);
593
- expect(std.err).toMatchInlineSnapshot(`""`);
594
- });
595
-
596
- it("should use --ip command line arg, if provided", async () => {
597
- writeWranglerToml({
598
- main: "index.js",
599
- dev: {
600
- ip: "1.1.1.1",
601
- },
602
- });
603
- fs.writeFileSync("index.js", `export default {};`);
604
- await runWrangler("dev --ip=0.0.0.0");
605
- expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("0.0.0.0");
606
- expect(std.out).toMatchInlineSnapshot(`""`);
607
- expect(std.warn).toMatchInlineSnapshot(`""`);
608
- expect(std.err).toMatchInlineSnapshot(`""`);
609
- });
610
- });
611
-
612
- describe("port", () => {
613
- it("should default port to 8787 if it is not in use", async () => {
614
- writeWranglerToml({
615
- main: "index.js",
616
- });
617
- fs.writeFileSync("index.js", `export default {};`);
618
- await runWrangler("dev");
619
- expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(8787);
620
- expect(std.out).toMatchInlineSnapshot(`""`);
621
- expect(std.warn).toMatchInlineSnapshot(`""`);
622
- expect(std.err).toMatchInlineSnapshot(`""`);
623
- });
624
-
625
- it("should use to `port` from `wrangler.toml`, if available", async () => {
626
- writeWranglerToml({
627
- main: "index.js",
628
- dev: {
629
- port: 8888,
630
- },
631
- });
632
- fs.writeFileSync("index.js", `export default {};`);
633
- // Mock `getPort()` to resolve to a completely different port.
634
- (getPort as jest.Mock).mockResolvedValue(98765);
635
-
636
- await runWrangler("dev");
637
- expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(8888);
638
- expect(std.out).toMatchInlineSnapshot(`""`);
639
- expect(std.warn).toMatchInlineSnapshot(`""`);
640
- expect(std.err).toMatchInlineSnapshot(`""`);
641
- });
642
-
643
- it("should use --port command line arg, if provided", async () => {
644
- writeWranglerToml({
645
- main: "index.js",
646
- dev: {
647
- port: 8888,
648
- },
649
- });
650
- fs.writeFileSync("index.js", `export default {};`);
651
- // Mock `getPort()` to resolve to a completely different port.
652
- (getPort as jest.Mock).mockResolvedValue(98765);
653
-
654
- await runWrangler("dev --port=9999");
655
- expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(9999);
656
- expect(std.out).toMatchInlineSnapshot(`""`);
657
- expect(std.warn).toMatchInlineSnapshot(`""`);
658
- expect(std.err).toMatchInlineSnapshot(`""`);
659
- });
660
-
661
- it("should use a different port to the default if it is in use", async () => {
662
- writeWranglerToml({
663
- main: "index.js",
664
- });
665
- fs.writeFileSync("index.js", `export default {};`);
666
- // Mock `getPort()` to resolve to a completely different port.
667
- (getPort as jest.Mock).mockResolvedValue(98765);
668
-
669
- await runWrangler("dev");
670
- expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(98765);
671
- expect(std.out).toMatchInlineSnapshot(`""`);
672
- expect(std.warn).toMatchInlineSnapshot(`""`);
673
- expect(std.err).toMatchInlineSnapshot(`""`);
674
- });
675
- });
676
-
677
- describe("durable_objects", () => {
678
- it("should warn if there are remote Durable Objects, or missing migrations for local Durable Objects", async () => {
679
- writeWranglerToml({
680
- main: "index.js",
681
- durable_objects: {
682
- bindings: [
683
- { name: "NAME_1", class_name: "CLASS_1" },
684
- {
685
- name: "NAME_2",
686
- class_name: "CLASS_2",
687
- script_name: "SCRIPT_A",
688
- },
689
- { name: "NAME_3", class_name: "CLASS_3" },
690
- {
691
- name: "NAME_4",
692
- class_name: "CLASS_4",
693
- script_name: "SCRIPT_B",
694
- },
695
- ],
696
- },
697
- });
698
- fs.writeFileSync("index.js", `export default {};`);
699
- await runWrangler("dev");
700
- expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("localhost");
701
- expect(std.out).toMatchInlineSnapshot(`
702
- "Your worker has access to the following bindings:
703
- - Durable Objects:
704
- - NAME_1: CLASS_1
705
- - NAME_2: CLASS_2 (defined in SCRIPT_A)
706
- - NAME_3: CLASS_3
707
- - NAME_4: CLASS_4 (defined in SCRIPT_B)"
708
- `);
709
- expect(std.warn).toMatchInlineSnapshot(`
710
- "▲ [WARNING] Processing wrangler.toml configuration:
711
-
712
- - In wrangler.toml, you have configured [durable_objects] exported by this Worker (CLASS_1,
713
- CLASS_3), but no [migrations] for them. This may not work as expected until you add a [migrations]
714
- section to your wrangler.toml. Add this configuration to your wrangler.toml:
715
-
716
- \`\`\`
717
- [[migrations]]
718
- tag = \\"v1\\" # Should be unique for each entry
719
- new_classes = [\\"CLASS_1\\", \\"CLASS_3\\"]
720
- \`\`\`
721
-
722
- Refer to
723
- https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml
724
- for more details.
725
-
726
-
727
- ▲ [WARNING] WARNING: You have Durable Object bindings that are not defined locally in the worker being developed.
728
-
729
- Be aware that changes to the data stored in these Durable Objects will be permanent and affect the
730
- live instances.
731
- Remote Durable Objects that are affected:
732
- - {\\"name\\":\\"NAME_2\\",\\"class_name\\":\\"CLASS_2\\",\\"script_name\\":\\"SCRIPT_A\\"}
733
- - {\\"name\\":\\"NAME_4\\",\\"class_name\\":\\"CLASS_4\\",\\"script_name\\":\\"SCRIPT_B\\"}
734
-
735
- "
736
- `);
737
- expect(std.err).toMatchInlineSnapshot(`""`);
738
- });
739
- });
740
-
741
- describe(".dev.vars", () => {
742
- it("should override `vars` bindings from `wrangler.toml` with values in `.dev.vars`", async () => {
743
- fs.writeFileSync("index.js", `export default {};`);
744
-
745
- const localVarsEnvContent = dedent`
746
- # Preceding comment
747
- VAR_1="var #1 value" # End of line comment
748
- VAR_3="var #3 value"
749
- VAR_MULTI_LINE_1="A: line 1
750
- line 2"
751
- VAR_MULTI_LINE_2="B: line 1\\nline 2"
752
- EMPTY=
753
- UNQUOTED= unquoted value
754
- `;
755
- fs.writeFileSync(".dev.vars", localVarsEnvContent, "utf8");
756
-
757
- writeWranglerToml({
758
- main: "index.js",
759
- vars: {
760
- VAR_1: "original value 1",
761
- VAR_2: "original value 2", // should not get overridden
762
- VAR_3: "original value 3",
763
- VAR_MULTI_LINE_1: "original multi-line 1",
764
- VAR_MULTI_LINE_2: "original multi-line 2",
765
- EMPTY: "original empty",
766
- UNQUOTED: "original unquoted",
767
- },
768
- });
769
- await runWrangler("dev");
770
- const varBindings: Record<string, unknown> = (Dev as jest.Mock).mock
771
- .calls[0][0].bindings.vars;
772
-
773
- expect(varBindings).toEqual({
774
- VAR_1: "var #1 value",
775
- VAR_2: "original value 2",
776
- VAR_3: "var #3 value",
777
- VAR_MULTI_LINE_1: "A: line 1\nline 2",
778
- VAR_MULTI_LINE_2: "B: line 1\nline 2",
779
- EMPTY: "",
780
- UNQUOTED: "unquoted value", // Note that whitespace is trimmed
781
- });
782
- expect(std.out).toMatchInlineSnapshot(`
783
- "Using vars defined in .dev.vars
784
- Your worker has access to the following bindings:
785
- - Vars:
786
- - VAR_1: \\"(hidden)\\"
787
- - VAR_2: \\"original value 2\\"
788
- - VAR_3: \\"(hidden)\\"
789
- - VAR_MULTI_LINE_1: \\"(hidden)\\"
790
- - VAR_MULTI_LINE_2: \\"(hidden)\\"
791
- - EMPTY: \\"(hidden)\\"
792
- - UNQUOTED: \\"(hidden)\\""
793
- `);
794
- expect(std.warn).toMatchInlineSnapshot(`""`);
795
- expect(std.err).toMatchInlineSnapshot(`""`);
796
- });
797
- });
798
-
799
- describe("site", () => {
800
- it("should error if --site is used with no value", async () => {
801
- await expect(
802
- runWrangler("dev --site")
803
- ).rejects.toThrowErrorMatchingInlineSnapshot(
804
- `"Not enough arguments following: site"`
805
- );
806
-
807
- expect(std).toMatchInlineSnapshot(`
808
- Object {
809
- "debug": "",
810
- "err": "X [ERROR] Not enough arguments following: site
811
-
812
- ",
813
- "out": "
814
- wrangler dev [script]
815
-
816
- 👂 Start a local server for developing your worker
817
-
818
- Positionals:
819
- script The path to an entry point for your worker [string]
820
-
821
- Flags:
822
- -c, --config Path to .toml configuration file [string]
823
- -h, --help Show help [boolean]
824
- -v, --version Show version number [boolean]
825
-
826
- Options:
827
- --name Name of the worker [string]
828
- --format Choose an entry type [deprecated] [choices: \\"modules\\", \\"service-worker\\"]
829
- -e, --env Perform on a specific environment [string]
830
- --compatibility-date Date to use for compatibility checks [string]
831
- --compatibility-flags, --compatibility-flag Flags to use for compatibility checks [array]
832
- --latest Use the latest version of the worker runtime [boolean] [default: true]
833
- --ip IP address to listen on, defaults to \`localhost\` [string]
834
- --port Port to listen on [number]
835
- --inspector-port Port for devtools to connect to [number]
836
- --routes, --route Routes to upload [array]
837
- --host Host to forward requests to, defaults to the zone of project [string]
838
- --local-protocol Protocol to listen to requests on, defaults to http. [choices: \\"http\\", \\"https\\"]
839
- --experimental-public Static assets to be served [string]
840
- --site Root folder of static assets for Workers Sites [string]
841
- --site-include Array of .gitignore-style patterns that match file or directory names from the sites directory. Only matched items will be uploaded. [array]
842
- --site-exclude Array of .gitignore-style patterns that match file or directory names from the sites directory. Matched items will not be uploaded. [array]
843
- --upstream-protocol Protocol to forward requests to host on, defaults to https. [choices: \\"http\\", \\"https\\"]
844
- --jsx-factory The function that is called for each JSX element [string]
845
- --jsx-fragment The function that is called for each JSX fragment [string]
846
- --tsconfig Path to a custom tsconfig.json file [string]
847
- -l, --local Run on my machine [boolean] [default: false]
848
- --minify Minify the script [boolean]
849
- --node-compat Enable node.js compatibility [boolean]
850
- --experimental-enable-local-persistence Enable persistence for this session (only for local mode) [boolean]
851
- --inspect Enable dev tools [deprecated] [boolean]",
852
- "warn": "",
853
- }
854
- `);
855
- });
856
- });
857
-
858
- describe("--inspect", () => {
859
- it("should warn if --inspect is used", async () => {
860
- fs.writeFileSync("index.js", `export default {};`);
861
- await runWrangler("dev index.js --inspect");
862
- expect(std).toMatchInlineSnapshot(`
863
- Object {
864
- "debug": "",
865
- "err": "",
866
- "out": "",
867
- "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
868
-
869
- ",
870
- }
871
- `);
872
- });
873
- });
874
-
875
- describe("service bindings", () => {
876
- it("should warn when using service bindings", async () => {
877
- writeWranglerToml({
878
- services: [
879
- { binding: "WorkerA", service: "A" },
880
- { binding: "WorkerB", service: "B", environment: "staging" },
881
- ],
882
- });
883
- fs.writeFileSync("index.js", `export default {};`);
884
- await runWrangler("dev index.js");
885
- expect(std).toMatchInlineSnapshot(`
886
- Object {
887
- "debug": "",
888
- "err": "",
889
- "out": "Your worker has access to the following bindings:
890
- - Services:
891
- - WorkerA: A
892
- - WorkerB: B - staging",
893
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
894
-
895
- - \\"services\\" fields are experimental and may change or break at any time.
896
-
897
-
898
- ▲ [WARNING] This worker is bound to live services: WorkerA (A), WorkerB (B@staging)
899
-
900
- ",
901
- }
902
- `);
903
- });
904
- });
905
-
906
- describe("print bindings", () => {
907
- it("should print bindings", async () => {
908
- writeWranglerToml({
909
- services: [
910
- { binding: "WorkerA", service: "A" },
911
- { binding: "WorkerB", service: "B", environment: "staging" },
912
- ],
913
- });
914
- fs.writeFileSync("index.js", `export default {};`);
915
- await runWrangler("dev index.js");
916
- expect(std).toMatchInlineSnapshot(`
917
- Object {
918
- "debug": "",
919
- "err": "",
920
- "out": "Your worker has access to the following bindings:
921
- - Services:
922
- - WorkerA: A
923
- - WorkerB: B - staging",
924
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
925
-
926
- - \\"services\\" fields are experimental and may change or break at any time.
927
-
928
-
929
- ▲ [WARNING] This worker is bound to live services: WorkerA (A), WorkerB (B@staging)
930
-
931
- ",
932
- }
933
- `);
934
- });
935
-
936
- it("should mask vars that were overriden in .dev.vars", async () => {
937
- writeWranglerToml({
938
- vars: {
939
- variable: 123,
940
- overriden: "original values",
941
- },
942
- });
943
- fs.writeFileSync(
944
- ".dev.vars",
945
- `
946
- SECRET = "A secret"
947
- overriden = "overriden value"
948
- `
949
- );
950
- fs.writeFileSync("index.js", `export default {};`);
951
- await runWrangler("dev index.js");
952
- expect(std).toMatchInlineSnapshot(`
953
- Object {
954
- "debug": "",
955
- "err": "",
956
- "out": "Using vars defined in .dev.vars
957
- Your worker has access to the following bindings:
958
- - Vars:
959
- - variable: \\"123\\"
960
- - overriden: \\"(hidden)\\"
961
- - SECRET: \\"(hidden)\\"",
962
- "warn": "",
963
- }
964
- `);
965
- });
966
- });
967
- });
968
-
969
- function mockGetZones(domain: string, zones: { id: string }[] = []) {
970
- const removeMock = setMockResponse(
971
- "/zones",
972
- "GET",
973
- (_urlPieces, _init, queryParams) => {
974
- expect([...queryParams.entries()]).toEqual([["name", domain]]);
975
- // 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.
976
- removeMock();
977
- return zones;
978
- }
979
- );
980
- }