wrangler 0.0.0-e2b7352 → 0.0.0-e2e6912bc

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 (172) hide show
  1. package/README.md +50 -15
  2. package/bin/wrangler.js +90 -36
  3. package/config-schema.json +3143 -0
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +142 -100
  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 +170 -0
  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-mock-analytics-engine.d.ts +3 -0
  21. package/templates/middleware/middleware-mock-analytics-engine.ts +30 -0
  22. package/templates/middleware/middleware-pretty-error.ts +40 -0
  23. package/templates/middleware/middleware-scheduled.ts +29 -0
  24. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  25. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  26. package/templates/modules-watch-stub.js +4 -0
  27. package/templates/new-worker-scheduled.js +17 -0
  28. package/templates/new-worker-scheduled.ts +32 -0
  29. package/templates/new-worker.js +3 -3
  30. package/templates/new-worker.ts +22 -4
  31. package/templates/no-op-worker.js +10 -0
  32. package/templates/pages-dev-pipeline.ts +32 -0
  33. package/templates/pages-dev-util.ts +55 -0
  34. package/templates/pages-shim.ts +9 -0
  35. package/templates/pages-template-plugin.ts +190 -0
  36. package/templates/pages-template-worker.ts +198 -0
  37. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  38. package/templates/startDevWorker/ProxyWorker.ts +336 -0
  39. package/templates/tsconfig-sanity.ts +11 -0
  40. package/templates/tsconfig.init.json +22 -0
  41. package/templates/tsconfig.json +6 -103
  42. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  43. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  44. package/wrangler-dist/ProxyWorker.js +241 -0
  45. package/wrangler-dist/ProxyWorker.js.map +6 -0
  46. package/wrangler-dist/cli.d.ts +26528 -0
  47. package/wrangler-dist/cli.js +169555 -135021
  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 -79
  53. package/miniflare-dist/index.mjs.map +0 -7
  54. package/pages/functions/buildWorker.ts +0 -62
  55. package/pages/functions/filepath-routing.test.ts +0 -223
  56. package/pages/functions/filepath-routing.ts +0 -181
  57. package/pages/functions/identifiers.ts +0 -78
  58. package/pages/functions/routes.ts +0 -151
  59. package/pages/functions/template-worker.ts +0 -130
  60. package/src/__tests__/configuration.test.ts +0 -2820
  61. package/src/__tests__/dev.test.tsx +0 -541
  62. package/src/__tests__/guess-worker-format.test.ts +0 -68
  63. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  64. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  65. package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
  66. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  67. package/src/__tests__/helpers/mock-bin.ts +0 -36
  68. package/src/__tests__/helpers/mock-cfetch.ts +0 -207
  69. package/src/__tests__/helpers/mock-console.ts +0 -70
  70. package/src/__tests__/helpers/mock-dialogs.ts +0 -65
  71. package/src/__tests__/helpers/mock-kv.ts +0 -33
  72. package/src/__tests__/helpers/mock-stdin.ts +0 -103
  73. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  74. package/src/__tests__/helpers/run-in-tmp.ts +0 -32
  75. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  76. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  77. package/src/__tests__/https-options.test.ts +0 -127
  78. package/src/__tests__/index.test.ts +0 -983
  79. package/src/__tests__/jest.setup.ts +0 -69
  80. package/src/__tests__/kv.test.ts +0 -1380
  81. package/src/__tests__/logout.test.ts +0 -52
  82. package/src/__tests__/package-manager.test.ts +0 -206
  83. package/src/__tests__/pages.test.ts +0 -82
  84. package/src/__tests__/parse.test.ts +0 -322
  85. package/src/__tests__/publish.test.ts +0 -3509
  86. package/src/__tests__/r2.test.ts +0 -198
  87. package/src/__tests__/route.test.ts +0 -45
  88. package/src/__tests__/secret.test.ts +0 -425
  89. package/src/__tests__/sentry.test.ts +0 -146
  90. package/src/__tests__/tail.test.ts +0 -638
  91. package/src/__tests__/whoami.test.tsx +0 -100
  92. package/src/bundle.ts +0 -155
  93. package/src/cfetch/index.ts +0 -104
  94. package/src/cfetch/internal.ts +0 -139
  95. package/src/cli.ts +0 -19
  96. package/src/config/README.md +0 -107
  97. package/src/config/config.ts +0 -218
  98. package/src/config/diagnostics.ts +0 -80
  99. package/src/config/environment.ts +0 -371
  100. package/src/config/index.ts +0 -62
  101. package/src/config/validation-helpers.ts +0 -554
  102. package/src/config/validation.ts +0 -1232
  103. package/src/create-worker-preview.ts +0 -166
  104. package/src/create-worker-upload-form.ts +0 -217
  105. package/src/dev/dev.tsx +0 -392
  106. package/src/dev/local.tsx +0 -232
  107. package/src/dev/remote.tsx +0 -203
  108. package/src/dev/use-esbuild.ts +0 -104
  109. package/src/dialogs.tsx +0 -77
  110. package/src/entry.ts +0 -240
  111. package/src/environment-variables.ts +0 -33
  112. package/src/https-options.ts +0 -122
  113. package/src/index.tsx +0 -2389
  114. package/src/inspect.ts +0 -617
  115. package/src/intl-polyfill.d.ts +0 -139
  116. package/src/kv.ts +0 -319
  117. package/src/miniflare-cli/README.md +0 -30
  118. package/src/miniflare-cli/enum-keys.ts +0 -17
  119. package/src/miniflare-cli/index.ts +0 -37
  120. package/src/module-collection.ts +0 -258
  121. package/src/open-in-browser.ts +0 -25
  122. package/src/package-manager.ts +0 -126
  123. package/src/pages.tsx +0 -1061
  124. package/src/parse.ts +0 -183
  125. package/src/paths.ts +0 -26
  126. package/src/proxy.ts +0 -440
  127. package/src/publish.ts +0 -350
  128. package/src/r2.ts +0 -50
  129. package/src/reporting.ts +0 -131
  130. package/src/selfsigned.d.ts +0 -29
  131. package/src/sites.tsx +0 -280
  132. package/src/tail/filters.ts +0 -279
  133. package/src/tail/index.ts +0 -299
  134. package/src/tail/printing.ts +0 -62
  135. package/src/user.tsx +0 -1127
  136. package/src/whoami.tsx +0 -69
  137. package/src/worker.ts +0 -163
  138. package/templates/static-asset-facade.js +0 -47
  139. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  140. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  141. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  142. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  143. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  144. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  145. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  146. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  147. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  148. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  149. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  150. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  151. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  152. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  153. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  154. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  155. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  156. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  157. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  158. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  159. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  160. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  161. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  162. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  163. package/vendor/wrangler-mime/LICENSE +0 -21
  164. package/vendor/wrangler-mime/Mime.js +0 -97
  165. package/vendor/wrangler-mime/README.md +0 -187
  166. package/vendor/wrangler-mime/cli.js +0 -46
  167. package/vendor/wrangler-mime/index.js +0 -4
  168. package/vendor/wrangler-mime/lite.js +0 -4
  169. package/vendor/wrangler-mime/package.json +0 -52
  170. package/vendor/wrangler-mime/types/other.js +0 -1
  171. package/vendor/wrangler-mime/types/standard.js +0 -1
  172. package/wrangler-dist/cli.js.map +0 -7
@@ -1,541 +0,0 @@
1
- import * as fs from "node:fs";
2
- import { readFileSync } from "node:fs";
3
- import patchConsole from "patch-console";
4
- import Dev from "../dev/dev";
5
- import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
6
- import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
7
- import { mockConsoleMethods } from "./helpers/mock-console";
8
- import { runInTempDir } from "./helpers/run-in-tmp";
9
- import { runWrangler } from "./helpers/run-wrangler";
10
- import writeWranglerToml from "./helpers/write-wrangler-toml";
11
-
12
- describe("wrangler dev", () => {
13
- mockAccountId();
14
- mockApiToken();
15
- runInTempDir();
16
- const std = mockConsoleMethods();
17
- afterEach(() => {
18
- (Dev as jest.Mock).mockClear();
19
- patchConsole(() => {});
20
- unsetAllMocks();
21
- });
22
-
23
- describe("entry-points", () => {
24
- it("should error if there is no entry-point specified", async () => {
25
- writeWranglerToml();
26
-
27
- await expect(
28
- runWrangler("dev")
29
- ).rejects.toThrowErrorMatchingInlineSnapshot(
30
- `"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."`
31
- );
32
-
33
- expect(std.out).toMatchInlineSnapshot(`""`);
34
- expect(std.err).toMatchInlineSnapshot(`
35
- "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.
36
-
37
- %s If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
38
- `);
39
- });
40
-
41
- it("should use `main` from the top-level environment", async () => {
42
- writeWranglerToml({
43
- main: "index.js",
44
- });
45
- fs.writeFileSync("index.js", `export default {};`);
46
- await runWrangler("dev");
47
- expect((Dev as jest.Mock).mock.calls[0][0].entry.file).toMatch(
48
- /index\.js$/
49
- );
50
- expect(std.out).toMatchInlineSnapshot(`""`);
51
- expect(std.warn).toMatchInlineSnapshot(`""`);
52
- expect(std.err).toMatchInlineSnapshot(`""`);
53
- });
54
-
55
- it("should use `main` from a named environment", async () => {
56
- writeWranglerToml({
57
- env: {
58
- ENV1: {
59
- main: "index.js",
60
- },
61
- },
62
- });
63
- fs.writeFileSync("index.js", `export default {};`);
64
- await runWrangler("dev --env=ENV1");
65
- expect((Dev as jest.Mock).mock.calls[0][0].entry.file).toMatch(
66
- /index\.js$/
67
- );
68
- expect(std.out).toMatchInlineSnapshot(`""`);
69
- expect(std.warn).toMatchInlineSnapshot(`""`);
70
- expect(std.err).toMatchInlineSnapshot(`""`);
71
- });
72
-
73
- it("should use `main` from a named environment, rather than the top-level", async () => {
74
- writeWranglerToml({
75
- main: "other.js",
76
- env: {
77
- ENV1: {
78
- main: "index.js",
79
- },
80
- },
81
- });
82
- fs.writeFileSync("index.js", `export default {};`);
83
- await runWrangler("dev --env=ENV1");
84
- expect((Dev as jest.Mock).mock.calls[0][0].entry.file).toMatch(
85
- /index\.js$/
86
- );
87
- expect(std.out).toMatchInlineSnapshot(`""`);
88
- expect(std.warn).toMatchInlineSnapshot(`""`);
89
- expect(std.err).toMatchInlineSnapshot(`""`);
90
- });
91
- });
92
-
93
- describe("host", () => {
94
- it("should resolve a host to its zone", async () => {
95
- writeWranglerToml({
96
- main: "index.js",
97
- });
98
- fs.writeFileSync("index.js", `export default {};`);
99
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
100
- await runWrangler("dev --host some-host.com");
101
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
102
- host: "some-host.com",
103
- id: "some-zone-id",
104
- });
105
- });
106
-
107
- it("should read wrangler.toml's dev.host", async () => {
108
- writeWranglerToml({
109
- main: "index.js",
110
- dev: {
111
- host: "some-host.com",
112
- },
113
- });
114
- fs.writeFileSync("index.js", `export default {};`);
115
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
116
- await runWrangler("dev");
117
- expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
118
- "some-host.com"
119
- );
120
- });
121
-
122
- it("should read --route", async () => {
123
- writeWranglerToml({
124
- main: "index.js",
125
- });
126
- fs.writeFileSync("index.js", `export default {};`);
127
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
128
- await runWrangler("dev --route http://some-host.com/some/path/*");
129
- expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
130
- "some-host.com"
131
- );
132
- });
133
-
134
- it("should read wrangler.toml's routes", async () => {
135
- writeWranglerToml({
136
- main: "index.js",
137
- routes: [
138
- "http://some-host.com/some/path/*",
139
- "http://some-other-host.com/path/*",
140
- ],
141
- });
142
- fs.writeFileSync("index.js", `export default {};`);
143
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
144
- await runWrangler("dev");
145
- expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
146
- "some-host.com"
147
- );
148
- });
149
-
150
- it("should read wrangler.toml's environment specific routes", async () => {
151
- writeWranglerToml({
152
- main: "index.js",
153
- routes: [
154
- "http://a-host.com/some/path/*",
155
- "http://another-host.com/path/*",
156
- ],
157
- env: {
158
- staging: {
159
- routes: [
160
- "http://some-host.com/some/path/*",
161
- "http://some-other-host.com/path/*",
162
- ],
163
- },
164
- },
165
- });
166
- fs.writeFileSync("index.js", `export default {};`);
167
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
168
- await runWrangler("dev --env staging");
169
- expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
170
- "some-host.com"
171
- );
172
- });
173
-
174
- it("given a long host, it should use the longest subdomain that resolves to a zone", async () => {
175
- writeWranglerToml({
176
- main: "index.js",
177
- });
178
- fs.writeFileSync("index.js", `export default {};`);
179
- mockGetZones("111.222.333.some-host.com", []);
180
- mockGetZones("222.333.some-host.com", []);
181
- mockGetZones("333.some-host.com", [{ id: "some-zone-id" }]);
182
- await runWrangler("dev --host 111.222.333.some-host.com");
183
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
184
- host: "111.222.333.some-host.com",
185
- id: "some-zone-id",
186
- });
187
- });
188
-
189
- it("should, in order, use args.host/config.dev.host/args.routes/(config.route|config.routes)", async () => {
190
- // This test might seem like it's testing implementation details, but let's be specific and consider it a spec
191
-
192
- fs.writeFileSync("index.js", `export default {};`);
193
-
194
- // config.routes
195
- mockGetZones("5.some-host.com", [{ id: "some-zone-id-5" }]);
196
- writeWranglerToml({
197
- main: "index.js",
198
- routes: ["http://5.some-host.com/some/path/*"],
199
- });
200
- await runWrangler("dev");
201
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
202
- host: "5.some-host.com",
203
- id: "some-zone-id-5",
204
- });
205
- (Dev as jest.Mock).mockClear();
206
-
207
- // config.route
208
- mockGetZones("4.some-host.com", [{ id: "some-zone-id-4" }]);
209
- writeWranglerToml({
210
- main: "index.js",
211
- route: "https://4.some-host.com/some/path/*",
212
- });
213
- await runWrangler("dev");
214
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
215
- host: "4.some-host.com",
216
- id: "some-zone-id-4",
217
- });
218
- (Dev as jest.Mock).mockClear();
219
-
220
- // --routes
221
- mockGetZones("3.some-host.com", [{ id: "some-zone-id-3" }]);
222
- writeWranglerToml({
223
- main: "index.js",
224
- route: "https://4.some-host.com/some/path/*",
225
- });
226
- await runWrangler("dev --routes http://3.some-host.com/some/path/*");
227
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
228
- host: "3.some-host.com",
229
- id: "some-zone-id-3",
230
- });
231
- (Dev as jest.Mock).mockClear();
232
-
233
- // config.dev.host
234
- mockGetZones("2.some-host.com", [{ id: "some-zone-id-2" }]);
235
- writeWranglerToml({
236
- main: "index.js",
237
- dev: {
238
- host: `2.some-host.com`,
239
- },
240
- route: "4.some-host.com/some/path/*",
241
- });
242
- await runWrangler("dev --routes http://3.some-host.com/some/path/*");
243
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
244
- host: "2.some-host.com",
245
- id: "some-zone-id-2",
246
- });
247
- (Dev as jest.Mock).mockClear();
248
-
249
- // --host
250
- mockGetZones("1.some-host.com", [{ id: "some-zone-id-1" }]);
251
- writeWranglerToml({
252
- main: "index.js",
253
- dev: {
254
- host: `2.some-host.com`,
255
- },
256
- route: "4.some-host.com/some/path/*",
257
- });
258
- await runWrangler(
259
- "dev --routes http://3.some-host.com/some/path/* --host 1.some-host.com"
260
- );
261
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
262
- host: "1.some-host.com",
263
- id: "some-zone-id-1",
264
- });
265
- (Dev as jest.Mock).mockClear();
266
- });
267
-
268
- it("should error if a host can't resolve to a zone", async () => {
269
- writeWranglerToml({
270
- main: "index.js",
271
- });
272
- fs.writeFileSync("index.js", `export default {};`);
273
- mockGetZones("some-host.com", []);
274
- await expect(
275
- runWrangler("dev --host some-host.com")
276
- ).rejects.toThrowErrorMatchingInlineSnapshot(
277
- `"Could not find zone for some-host.com"`
278
- );
279
- });
280
-
281
- it("should not try to resolve a zone when starting in local mode", async () => {
282
- writeWranglerToml({
283
- main: "index.js",
284
- });
285
- fs.writeFileSync("index.js", `export default {};`);
286
- await runWrangler("dev --host some-host.com --local");
287
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual(undefined);
288
- });
289
- });
290
-
291
- describe("custom builds", () => {
292
- it("should run a custom build before starting `dev`", async () => {
293
- writeWranglerToml({
294
- build: {
295
- command: `node -e "console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')"`,
296
- },
297
- });
298
-
299
- await runWrangler("dev index.js");
300
-
301
- expect(readFileSync("index.js", "utf-8")).toMatchInlineSnapshot(
302
- `"export default { fetch(){ return new Response(123) } }"`
303
- );
304
-
305
- // and the command would pass through
306
- expect((Dev as jest.Mock).mock.calls[0][0].build).toEqual({
307
- command:
308
- "node -e \"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\"",
309
- cwd: undefined,
310
- watch_dir: "src",
311
- });
312
- expect(std.out).toMatchInlineSnapshot(
313
- `"running: node -e \\"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\""`
314
- );
315
- expect(std.err).toMatchInlineSnapshot(`""`);
316
- expect(std.warn).toMatchInlineSnapshot(`""`);
317
- });
318
-
319
- if (process.platform !== "win32") {
320
- it("should run a custom build of multiple steps combined by && before starting `dev`", async () => {
321
- writeWranglerToml({
322
- build: {
323
- command: `echo "custom build" && echo "export default { fetch(){ return new Response(123) } }" > index.js`,
324
- },
325
- });
326
-
327
- await runWrangler("dev index.js");
328
-
329
- expect(readFileSync("index.js", "utf-8")).toMatchInlineSnapshot(`
330
- "export default { fetch(){ return new Response(123) } }
331
- "
332
- `);
333
-
334
- expect(std.out).toMatchInlineSnapshot(
335
- `"running: echo \\"custom build\\" && echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js"`
336
- );
337
- expect(std.err).toMatchInlineSnapshot(`""`);
338
- expect(std.warn).toMatchInlineSnapshot(`""`);
339
- });
340
- }
341
-
342
- it("should throw an error if the entry doesn't exist after the build finishes", async () => {
343
- writeWranglerToml({
344
- main: "index.js",
345
- build: {
346
- command: `node -e "console.log('custom build');"`,
347
- },
348
- });
349
-
350
- await expect(
351
- runWrangler("dev")
352
- ).rejects.toThrowErrorMatchingInlineSnapshot(
353
- `"Could not resolve \\"index.js\\" after running custom build: node -e \\"console.log('custom build');\\""`
354
- );
355
- expect(std.out).toMatchInlineSnapshot(
356
- `"running: node -e \\"console.log('custom build');\\""`
357
- );
358
- expect(std.err).toMatchInlineSnapshot(`
359
- "Could not resolve \\"index.js\\" after running custom build: node -e \\"console.log('custom build');\\"
360
-
361
- %s If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
362
- `);
363
- expect(std.warn).toMatchInlineSnapshot(`""`);
364
- });
365
- });
366
-
367
- describe("upstream-protocol", () => {
368
- it("should default upstream-protocol to `https`", async () => {
369
- writeWranglerToml({
370
- main: "index.js",
371
- });
372
- fs.writeFileSync("index.js", `export default {};`);
373
- await runWrangler("dev");
374
- expect((Dev as jest.Mock).mock.calls[0][0].upstreamProtocol).toEqual(
375
- "https"
376
- );
377
- expect(std.out).toMatchInlineSnapshot(`""`);
378
- expect(std.warn).toMatchInlineSnapshot(`""`);
379
- expect(std.err).toMatchInlineSnapshot(`""`);
380
- });
381
-
382
- it("should warn if `--upstream-protocol=http` is used", async () => {
383
- writeWranglerToml({
384
- main: "index.js",
385
- });
386
- fs.writeFileSync("index.js", `export default {};`);
387
- await runWrangler("dev --upstream-protocol=http");
388
- expect((Dev as jest.Mock).mock.calls[0][0].upstreamProtocol).toEqual(
389
- "http"
390
- );
391
- expect(std.out).toMatchInlineSnapshot(`""`);
392
- expect(std.warn).toMatchInlineSnapshot(`
393
- "Setting upstream-protocol to http is not currently implemented.
394
- If this is required in your project, please add your use case to the following issue:
395
- https://github.com/cloudflare/wrangler2/issues/583."
396
- `);
397
- expect(std.err).toMatchInlineSnapshot(`""`);
398
- });
399
- });
400
-
401
- describe("local-protocol", () => {
402
- it("should default local-protocol to `http`", async () => {
403
- writeWranglerToml({
404
- main: "index.js",
405
- });
406
- fs.writeFileSync("index.js", `export default {};`);
407
- await runWrangler("dev");
408
- expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual("http");
409
- expect(std.out).toMatchInlineSnapshot(`""`);
410
- expect(std.warn).toMatchInlineSnapshot(`""`);
411
- expect(std.err).toMatchInlineSnapshot(`""`);
412
- });
413
-
414
- it("should use `local_protocol` from `wrangler.toml`, if available", async () => {
415
- writeWranglerToml({
416
- main: "index.js",
417
- dev: {
418
- local_protocol: "https",
419
- },
420
- });
421
- fs.writeFileSync("index.js", `export default {};`);
422
- await runWrangler("dev");
423
- expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual(
424
- "https"
425
- );
426
- expect(std.out).toMatchInlineSnapshot(`""`);
427
- expect(std.warn).toMatchInlineSnapshot(`""`);
428
- expect(std.err).toMatchInlineSnapshot(`""`);
429
- });
430
-
431
- it("should use --local-protocol command line arg, if provided", async () => {
432
- // Here we show that the command line overrides the wrangler.toml by
433
- // setting the config to https, and then setting it back to http on the command line.
434
- writeWranglerToml({
435
- main: "index.js",
436
- dev: {
437
- local_protocol: "https",
438
- },
439
- });
440
- fs.writeFileSync("index.js", `export default {};`);
441
- await runWrangler("dev --local-protocol=http");
442
- expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual("http");
443
- expect(std.out).toMatchInlineSnapshot(`""`);
444
- expect(std.warn).toMatchInlineSnapshot(`""`);
445
- expect(std.err).toMatchInlineSnapshot(`""`);
446
- });
447
- });
448
-
449
- describe("ip", () => {
450
- it("should default ip to localhost", async () => {
451
- writeWranglerToml({
452
- main: "index.js",
453
- });
454
- fs.writeFileSync("index.js", `export default {};`);
455
- await runWrangler("dev");
456
- expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("localhost");
457
- expect(std.out).toMatchInlineSnapshot(`""`);
458
- expect(std.warn).toMatchInlineSnapshot(`""`);
459
- expect(std.err).toMatchInlineSnapshot(`""`);
460
- });
461
-
462
- it("should use to `ip` from `wrangler.toml`, if available", async () => {
463
- writeWranglerToml({
464
- main: "index.js",
465
- dev: {
466
- ip: "0.0.0.0",
467
- },
468
- });
469
- fs.writeFileSync("index.js", `export default {};`);
470
- await runWrangler("dev");
471
- expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("0.0.0.0");
472
- expect(std.out).toMatchInlineSnapshot(`""`);
473
- expect(std.warn).toMatchInlineSnapshot(`""`);
474
- expect(std.err).toMatchInlineSnapshot(`""`);
475
- });
476
-
477
- it("should use --ip command line arg, if provided", async () => {
478
- writeWranglerToml({
479
- main: "index.js",
480
- dev: {
481
- ip: "1.1.1.1",
482
- },
483
- });
484
- fs.writeFileSync("index.js", `export default {};`);
485
- await runWrangler("dev --ip=0.0.0.0");
486
- expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("0.0.0.0");
487
- expect(std.out).toMatchInlineSnapshot(`""`);
488
- expect(std.warn).toMatchInlineSnapshot(`""`);
489
- expect(std.err).toMatchInlineSnapshot(`""`);
490
- });
491
- });
492
-
493
- describe("durable_objects", () => {
494
- it("should warn if there is one or more remote Durable Object", async () => {
495
- writeWranglerToml({
496
- main: "index.js",
497
- durable_objects: {
498
- bindings: [
499
- { name: "NAME_1", class_name: "CLASS_1" },
500
- {
501
- name: "NAME_2",
502
- class_name: "CLASS_2",
503
- script_name: "SCRIPT_A",
504
- },
505
- { name: "NAME_3", class_name: "CLASS_3" },
506
- {
507
- name: "NAME_4",
508
- class_name: "CLASS_4",
509
- script_name: "SCRIPT_B",
510
- },
511
- ],
512
- },
513
- });
514
- fs.writeFileSync("index.js", `export default {};`);
515
- await runWrangler("dev");
516
- expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("localhost");
517
- expect(std.out).toMatchInlineSnapshot(`""`);
518
- expect(std.warn).toMatchInlineSnapshot(`
519
- "WARNING: You have Durable Object bindings, which are not defined locally in the worker being developed.
520
- Be aware that changes to the data stored in these Durable Objects will be permanent and affect the live instances.
521
- Remote Durable Objects that are affected:
522
- - {\\"name\\":\\"NAME_2\\",\\"class_name\\":\\"CLASS_2\\",\\"script_name\\":\\"SCRIPT_A\\"}
523
- - {\\"name\\":\\"NAME_4\\",\\"class_name\\":\\"CLASS_4\\",\\"script_name\\":\\"SCRIPT_B\\"}"
524
- `);
525
- expect(std.err).toMatchInlineSnapshot(`""`);
526
- });
527
- });
528
- });
529
-
530
- function mockGetZones(domain: string, zones: { id: string }[] = []) {
531
- const removeMock = setMockResponse(
532
- "/zones",
533
- "GET",
534
- (_urlPieces, _init, queryParams) => {
535
- expect([...queryParams.entries()]).toEqual([["name", domain]]);
536
- // 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.
537
- removeMock();
538
- return zones;
539
- }
540
- );
541
- }
@@ -1,68 +0,0 @@
1
- import { writeFile } from "fs/promises";
2
- import path from "path";
3
- import guessWorkerFormat from "../entry";
4
- import { runInTempDir } from "./helpers/run-in-tmp";
5
-
6
- describe("guess worker format", () => {
7
- runInTempDir();
8
- it('should detect a "modules" worker', async () => {
9
- await writeFile("./index.ts", "export default {};");
10
- // Note that this isn't actually a valid worker, because it's missing
11
- // a fetch handler. Regardless, our heuristic is simply to check for exports.
12
- const guess = await guessWorkerFormat(
13
- path.join(process.cwd(), "./index.ts"),
14
- process.cwd(),
15
- undefined
16
- );
17
- expect(guess).toBe("modules");
18
- });
19
-
20
- it('should detect a "service-worker" worker', async () => {
21
- await writeFile("./index.ts", "");
22
- // Note that this isn't actually a valid worker, because it's missing
23
- // a fetch listener. Regardless, our heuristic is simply to check for
24
- // the lack of exports.
25
- const guess = await guessWorkerFormat(
26
- path.join(process.cwd(), "./index.ts"),
27
- process.cwd(),
28
- undefined
29
- );
30
- expect(guess).toBe("service-worker");
31
- });
32
-
33
- it("should throw an error when the hint doesn't match the guess (modules - service-worker)", async () => {
34
- await writeFile("./index.ts", "export default {};");
35
- await expect(
36
- guessWorkerFormat(
37
- path.join(process.cwd(), "./index.ts"),
38
- process.cwd(),
39
- "service-worker"
40
- )
41
- ).rejects.toThrow(
42
- "You configured this worker to be a 'service-worker', but the file you are trying to build appears to have ES module exports. Please pass `--format modules`, or simply remove the configuration."
43
- );
44
- });
45
-
46
- it("should throw an error when the hint doesn't match the guess (service-worker - modules)", async () => {
47
- await writeFile("./index.ts", "");
48
- await expect(
49
- guessWorkerFormat(
50
- path.join(process.cwd(), "./index.ts"),
51
- process.cwd(),
52
- "modules"
53
- )
54
- ).rejects.toThrow(
55
- "You configured this worker to be 'modules', but the file you are trying to build doesn't export a handler. Please pass `--format service-worker`, or simply remove the configuration."
56
- );
57
- });
58
-
59
- it("should not error if a .js entry point has jsx", async () => {
60
- await writeFile("./index.js", "console.log(<div/>)");
61
- const guess = await guessWorkerFormat(
62
- path.join(process.cwd(), "./index.js"),
63
- process.cwd(),
64
- undefined
65
- );
66
- expect(guess).toBe("service-worker");
67
- });
68
- });
@@ -1,4 +0,0 @@
1
- // We use this mock during tests because we're having trouble
2
- // properly compiling clipboardy for jest
3
- // We can revisit this if and when we write tests that test
4
- // the copying part of `dev`
@@ -1,11 +0,0 @@
1
- /**
2
- * The typings file available at `@types/cmd-shim` are out of date.
3
- */
4
- module "cmd-shim" {
5
- /**
6
- *
7
- * Create a cmd shim at `to` for the command line program at `from`.
8
- *
9
- */
10
- export default function cmdShim(from: string, to: string): Promise<void>;
11
- }
@@ -1,6 +0,0 @@
1
- module "faye-websocket" {
2
- /**
3
- * Standards-compliant WebSocket client and server.
4
- */
5
- export default WebSocket;
6
- }
@@ -1,48 +0,0 @@
1
- import { reinitialiseAuthTokens } from "../../user";
2
-
3
- const ORIGINAL_CLOUDFLARE_API_TOKEN = process.env.CLOUDFLARE_API_TOKEN;
4
- const ORIGINAL_CLOUDFLARE_ACCOUNT_ID = process.env.CLOUDFLARE_ACCOUNT_ID;
5
-
6
- /**
7
- * Mock the API token so that we don't need to read it from user configuration files.
8
- *
9
- * Note that you can remove any API token from the environment by setting the value to `null`.
10
- * This is useful if a higher `describe()` block has already called `mockApiToken()`.
11
- */
12
- export function mockApiToken({
13
- apiToken = "some-api-token",
14
- }: { apiToken?: string | null } = {}) {
15
- beforeEach(() => {
16
- if (apiToken === null) {
17
- delete process.env.CLOUDFLARE_API_TOKEN;
18
- } else {
19
- process.env.CLOUDFLARE_API_TOKEN = apiToken;
20
- }
21
- // Now we have updated the environment, we must reinitialize the user auth state.
22
- reinitialiseAuthTokens();
23
- });
24
- afterEach(() => {
25
- process.env.CLOUDFLARE_API_TOKEN = ORIGINAL_CLOUDFLARE_API_TOKEN;
26
- });
27
- }
28
-
29
- /**
30
- * Mock the current account ID so that we don't need to read it from configuration files.
31
- *
32
- * Note that you can remove any account ID from the environment by setting the value to `null`.
33
- * This is useful if a higher `describe()` block has already called `mockAccountId()`.
34
- */
35
- export function mockAccountId({
36
- accountId = "some-account-id",
37
- }: { accountId?: string | null } = {}) {
38
- beforeEach(() => {
39
- if (accountId === null) {
40
- delete process.env.CLOUDFLARE_ACCOUNT_ID;
41
- } else {
42
- process.env.CLOUDFLARE_ACCOUNT_ID = accountId;
43
- }
44
- });
45
- afterEach(() => {
46
- process.env.CLOUDFLARE_ACCOUNT_ID = ORIGINAL_CLOUDFLARE_ACCOUNT_ID;
47
- });
48
- }