wrangler 0.0.0-e3a458e → 0.0.0-e3a57616

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 (168) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +47 -16
  3. package/bin/wrangler.js +123 -32
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +160 -85
  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 +17 -0
  11. package/templates/gitignore +172 -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 +136 -0
  17. package/templates/middleware/loader-sw.ts +229 -0
  18. package/templates/middleware/middleware-d1-beta.d.ts +3 -0
  19. package/templates/middleware/middleware-miniflare3-json-error.ts +33 -0
  20. package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
  21. package/templates/middleware/middleware-multiworker-dev.ts +68 -0
  22. package/templates/middleware/middleware-pretty-error.ts +40 -0
  23. package/templates/middleware/middleware-scheduled.ts +15 -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 +654 -0
  38. package/templates/startDevWorker/ProxyWorker.ts +252 -0
  39. package/templates/tsconfig-sanity.ts +11 -0
  40. package/templates/tsconfig.init.json +105 -0
  41. package/templates/tsconfig.json +6 -103
  42. package/wrangler-dist/InspectorProxyWorker.js +460 -0
  43. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  44. package/wrangler-dist/ProxyWorker.js +186 -0
  45. package/wrangler-dist/ProxyWorker.js.map +6 -0
  46. package/wrangler-dist/cli.d.ts +23793 -0
  47. package/wrangler-dist/cli.js +160711 -133928
  48. package/wrangler-dist/wasm-sync.wasm +0 -0
  49. package/import_meta_url.js +0 -3
  50. package/miniflare-config-stubs/.env.empty +0 -0
  51. package/miniflare-config-stubs/package.empty.json +0 -1
  52. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  53. package/pages/functions/buildWorker.ts +0 -62
  54. package/pages/functions/filepath-routing.test.ts +0 -223
  55. package/pages/functions/filepath-routing.ts +0 -181
  56. package/pages/functions/identifiers.ts +0 -78
  57. package/pages/functions/routes.ts +0 -151
  58. package/pages/functions/template-worker.ts +0 -130
  59. package/src/__tests__/configuration.test.ts +0 -2598
  60. package/src/__tests__/dev.test.tsx +0 -445
  61. package/src/__tests__/dev2.test.tsx +0 -154
  62. package/src/__tests__/guess-worker-format.test.ts +0 -58
  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 -991
  79. package/src/__tests__/jest.setup.ts +0 -69
  80. package/src/__tests__/kv.test.ts +0 -1382
  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 -44
  84. package/src/__tests__/parse.test.ts +0 -322
  85. package/src/__tests__/publish.test.ts +0 -2611
  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 -564
  91. package/src/__tests__/whoami.test.tsx +0 -100
  92. package/src/bundle.ts +0 -142
  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 -279
  98. package/src/config/diagnostics.ts +0 -80
  99. package/src/config/environment.ts +0 -305
  100. package/src/config/index.ts +0 -52
  101. package/src/config/validation-helpers.ts +0 -468
  102. package/src/config/validation.ts +0 -1057
  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 -362
  106. package/src/dev/local.tsx +0 -247
  107. package/src/dev/remote.tsx +0 -203
  108. package/src/dev/use-esbuild.ts +0 -100
  109. package/src/dialogs.tsx +0 -77
  110. package/src/entry.ts +0 -159
  111. package/src/environment-variables.ts +0 -33
  112. package/src/https-options.ts +0 -122
  113. package/src/index.tsx +0 -2365
  114. package/src/inspect.ts +0 -617
  115. package/src/kv.ts +0 -339
  116. package/src/module-collection.ts +0 -253
  117. package/src/open-in-browser.ts +0 -25
  118. package/src/package-manager.ts +0 -126
  119. package/src/pages.tsx +0 -1045
  120. package/src/parse.ts +0 -183
  121. package/src/paths.ts +0 -26
  122. package/src/proxy.ts +0 -440
  123. package/src/publish.ts +0 -354
  124. package/src/r2.ts +0 -50
  125. package/src/reporting.ts +0 -131
  126. package/src/selfsigned.d.ts +0 -29
  127. package/src/sites.tsx +0 -273
  128. package/src/tail/filters.ts +0 -279
  129. package/src/tail/index.ts +0 -299
  130. package/src/tail/printing.ts +0 -62
  131. package/src/user.tsx +0 -1118
  132. package/src/whoami.tsx +0 -69
  133. package/src/worker.ts +0 -163
  134. package/templates/static-asset-facade.js +0 -47
  135. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  136. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  137. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  138. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  139. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  140. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  141. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  142. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  143. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  144. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  145. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  146. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  147. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  148. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  149. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  150. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  151. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  152. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  153. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  154. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  155. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  156. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  157. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  158. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  159. package/vendor/wrangler-mime/LICENSE +0 -21
  160. package/vendor/wrangler-mime/Mime.js +0 -97
  161. package/vendor/wrangler-mime/README.md +0 -187
  162. package/vendor/wrangler-mime/cli.js +0 -46
  163. package/vendor/wrangler-mime/index.js +0 -4
  164. package/vendor/wrangler-mime/lite.js +0 -4
  165. package/vendor/wrangler-mime/package.json +0 -52
  166. package/vendor/wrangler-mime/types/other.js +0 -1
  167. package/vendor/wrangler-mime/types/standard.js +0 -1
  168. package/wrangler-dist/cli.js.map +0 -7
@@ -1,445 +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("Dev component", () => {
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
-
42
- describe("host", () => {
43
- it("should resolve a host to its zone", async () => {
44
- writeWranglerToml({
45
- main: "index.js",
46
- });
47
- fs.writeFileSync("index.js", `export default {};`);
48
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
49
- await runWrangler("dev --host some-host.com");
50
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
51
- host: "some-host.com",
52
- id: "some-zone-id",
53
- });
54
- });
55
-
56
- it("should read wrangler.toml's dev.host", async () => {
57
- writeWranglerToml({
58
- main: "index.js",
59
- dev: {
60
- host: "some-host.com",
61
- },
62
- });
63
- fs.writeFileSync("index.js", `export default {};`);
64
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
65
- await runWrangler("dev");
66
- expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
67
- "some-host.com"
68
- );
69
- });
70
-
71
- it("should read --route", async () => {
72
- writeWranglerToml({
73
- main: "index.js",
74
- });
75
- fs.writeFileSync("index.js", `export default {};`);
76
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
77
- await runWrangler("dev --route http://some-host.com/some/path/*");
78
- expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
79
- "some-host.com"
80
- );
81
- });
82
-
83
- it("should read wrangler.toml's routes", async () => {
84
- writeWranglerToml({
85
- main: "index.js",
86
- routes: [
87
- "http://some-host.com/some/path/*",
88
- "http://some-other-host.com/path/*",
89
- ],
90
- });
91
- fs.writeFileSync("index.js", `export default {};`);
92
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
93
- await runWrangler("dev");
94
- expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
95
- "some-host.com"
96
- );
97
- });
98
-
99
- it("should read wrangler.toml's environment specific routes", async () => {
100
- writeWranglerToml({
101
- main: "index.js",
102
- routes: [
103
- "http://a-host.com/some/path/*",
104
- "http://another-host.com/path/*",
105
- ],
106
- env: {
107
- staging: {
108
- routes: [
109
- "http://some-host.com/some/path/*",
110
- "http://some-other-host.com/path/*",
111
- ],
112
- },
113
- },
114
- });
115
- fs.writeFileSync("index.js", `export default {};`);
116
- mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
117
- await runWrangler("dev --env staging");
118
- expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
119
- "some-host.com"
120
- );
121
- });
122
-
123
- it("given a long host, it should use the longest subdomain that resolves to a zone", async () => {
124
- writeWranglerToml({
125
- main: "index.js",
126
- });
127
- fs.writeFileSync("index.js", `export default {};`);
128
- mockGetZones("111.222.333.some-host.com", []);
129
- mockGetZones("222.333.some-host.com", []);
130
- mockGetZones("333.some-host.com", [{ id: "some-zone-id" }]);
131
- await runWrangler("dev --host 111.222.333.some-host.com");
132
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
133
- host: "111.222.333.some-host.com",
134
- id: "some-zone-id",
135
- });
136
- });
137
-
138
- it("should, in order, use args.host/config.dev.host/args.routes/(config.route|config.routes)", async () => {
139
- // This test might seem like it's testing implementation details, but let's be specific and consider it a spec
140
-
141
- fs.writeFileSync("index.js", `export default {};`);
142
-
143
- // config.routes
144
- mockGetZones("5.some-host.com", [{ id: "some-zone-id-5" }]);
145
- writeWranglerToml({
146
- main: "index.js",
147
- routes: ["http://5.some-host.com/some/path/*"],
148
- });
149
- await runWrangler("dev");
150
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
151
- host: "5.some-host.com",
152
- id: "some-zone-id-5",
153
- });
154
- (Dev as jest.Mock).mockClear();
155
-
156
- // config.route
157
- mockGetZones("4.some-host.com", [{ id: "some-zone-id-4" }]);
158
- writeWranglerToml({
159
- main: "index.js",
160
- route: "https://4.some-host.com/some/path/*",
161
- });
162
- await runWrangler("dev");
163
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
164
- host: "4.some-host.com",
165
- id: "some-zone-id-4",
166
- });
167
- (Dev as jest.Mock).mockClear();
168
-
169
- // --routes
170
- mockGetZones("3.some-host.com", [{ id: "some-zone-id-3" }]);
171
- writeWranglerToml({
172
- main: "index.js",
173
- route: "https://4.some-host.com/some/path/*",
174
- });
175
- await runWrangler("dev --routes http://3.some-host.com/some/path/*");
176
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
177
- host: "3.some-host.com",
178
- id: "some-zone-id-3",
179
- });
180
- (Dev as jest.Mock).mockClear();
181
-
182
- // config.dev.host
183
- mockGetZones("2.some-host.com", [{ id: "some-zone-id-2" }]);
184
- writeWranglerToml({
185
- main: "index.js",
186
- dev: {
187
- host: `2.some-host.com`,
188
- },
189
- route: "4.some-host.com/some/path/*",
190
- });
191
- await runWrangler("dev --routes http://3.some-host.com/some/path/*");
192
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
193
- host: "2.some-host.com",
194
- id: "some-zone-id-2",
195
- });
196
- (Dev as jest.Mock).mockClear();
197
-
198
- // --host
199
- mockGetZones("1.some-host.com", [{ id: "some-zone-id-1" }]);
200
- writeWranglerToml({
201
- main: "index.js",
202
- dev: {
203
- host: `2.some-host.com`,
204
- },
205
- route: "4.some-host.com/some/path/*",
206
- });
207
- await runWrangler(
208
- "dev --routes http://3.some-host.com/some/path/* --host 1.some-host.com"
209
- );
210
- expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
211
- host: "1.some-host.com",
212
- id: "some-zone-id-1",
213
- });
214
- (Dev as jest.Mock).mockClear();
215
- });
216
-
217
- it("should error if a host can't resolve to a zone", async () => {
218
- writeWranglerToml({
219
- main: "index.js",
220
- });
221
- fs.writeFileSync("index.js", `export default {};`);
222
- mockGetZones("some-host.com", []);
223
- await expect(
224
- runWrangler("dev --host some-host.com")
225
- ).rejects.toThrowErrorMatchingInlineSnapshot(
226
- `"Could not find zone for some-host.com"`
227
- );
228
- });
229
- });
230
-
231
- describe("custom builds", () => {
232
- it("should run a custom build before starting `dev`", async () => {
233
- writeWranglerToml({
234
- build: {
235
- command: `node -e "console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')"`,
236
- },
237
- });
238
-
239
- await runWrangler("dev index.js");
240
-
241
- expect(readFileSync("index.js", "utf-8")).toMatchInlineSnapshot(
242
- `"export default { fetch(){ return new Response(123) } }"`
243
- );
244
-
245
- // and the command would pass through
246
- expect((Dev as jest.Mock).mock.calls[0][0].buildCommand).toEqual({
247
- command:
248
- "node -e \"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\"",
249
- cwd: undefined,
250
- watch_dir: "src",
251
- });
252
- expect(std.out).toMatchInlineSnapshot(
253
- `"running: node -e \\"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\""`
254
- );
255
- expect(std.err).toMatchInlineSnapshot(`""`);
256
- expect(std.warn).toMatchInlineSnapshot(`""`);
257
- });
258
-
259
- if (process.platform !== "win32") {
260
- it("should run a custom build of multiple steps combined by && before starting `dev`", async () => {
261
- writeWranglerToml({
262
- build: {
263
- command: `echo "custom build" && echo "export default { fetch(){ return new Response(123) } }" > index.js`,
264
- },
265
- });
266
-
267
- await runWrangler("dev index.js");
268
-
269
- expect(readFileSync("index.js", "utf-8")).toMatchInlineSnapshot(`
270
- "export default { fetch(){ return new Response(123) } }
271
- "
272
- `);
273
-
274
- expect(std.out).toMatchInlineSnapshot(
275
- `"running: echo \\"custom build\\" && echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js"`
276
- );
277
- expect(std.err).toMatchInlineSnapshot(`""`);
278
- expect(std.warn).toMatchInlineSnapshot(`""`);
279
- });
280
- }
281
-
282
- it("should throw an error if the entry doesn't exist after the build finishes", async () => {
283
- writeWranglerToml({
284
- main: "index.js",
285
- build: {
286
- command: `node -e "console.log('custom build');"`,
287
- },
288
- });
289
-
290
- await expect(
291
- runWrangler("dev")
292
- ).rejects.toThrowErrorMatchingInlineSnapshot(
293
- `"Could not resolve \\"index.js\\" after running custom build: node -e \\"console.log('custom build');\\""`
294
- );
295
- expect(std.out).toMatchInlineSnapshot(
296
- `"running: node -e \\"console.log('custom build');\\""`
297
- );
298
- expect(std.err).toMatchInlineSnapshot(`
299
- "Could not resolve \\"index.js\\" after running custom build: node -e \\"console.log('custom build');\\"
300
-
301
- %s If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
302
- `);
303
- expect(std.warn).toMatchInlineSnapshot(`""`);
304
- });
305
- });
306
-
307
- describe("upstream-protocol", () => {
308
- it("should default upstream-protocol to `https`", async () => {
309
- writeWranglerToml({
310
- main: "index.js",
311
- });
312
- fs.writeFileSync("index.js", `export default {};`);
313
- await runWrangler("dev");
314
- expect((Dev as jest.Mock).mock.calls[0][0].upstreamProtocol).toEqual(
315
- "https"
316
- );
317
- expect(std.out).toMatchInlineSnapshot(`""`);
318
- expect(std.warn).toMatchInlineSnapshot(`""`);
319
- expect(std.err).toMatchInlineSnapshot(`""`);
320
- });
321
-
322
- it("should warn if `--upstream-protocol=http` is used", async () => {
323
- writeWranglerToml({
324
- main: "index.js",
325
- });
326
- fs.writeFileSync("index.js", `export default {};`);
327
- await runWrangler("dev --upstream-protocol=http");
328
- expect((Dev as jest.Mock).mock.calls[0][0].upstreamProtocol).toEqual(
329
- "http"
330
- );
331
- expect(std.out).toMatchInlineSnapshot(`""`);
332
- expect(std.warn).toMatchInlineSnapshot(`
333
- "Setting upstream-protocol to http is not currently implemented.
334
- If this is required in your project, please add your use case to the following issue:
335
- https://github.com/cloudflare/wrangler2/issues/583."
336
- `);
337
- expect(std.err).toMatchInlineSnapshot(`""`);
338
- });
339
- });
340
-
341
- describe("local-protocol", () => {
342
- it("should default local-protocol to `http`", async () => {
343
- writeWranglerToml({
344
- main: "index.js",
345
- });
346
- fs.writeFileSync("index.js", `export default {};`);
347
- await runWrangler("dev");
348
- expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual("http");
349
- expect(std.out).toMatchInlineSnapshot(`""`);
350
- expect(std.warn).toMatchInlineSnapshot(`""`);
351
- expect(std.err).toMatchInlineSnapshot(`""`);
352
- });
353
-
354
- it("should use to `local_protocol` from `wrangler.toml`, if available", async () => {
355
- writeWranglerToml({
356
- main: "index.js",
357
- dev: {
358
- local_protocol: "https",
359
- },
360
- });
361
- fs.writeFileSync("index.js", `export default {};`);
362
- await runWrangler("dev");
363
- expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual(
364
- "https"
365
- );
366
- expect(std.out).toMatchInlineSnapshot(`""`);
367
- expect(std.warn).toMatchInlineSnapshot(`""`);
368
- expect(std.err).toMatchInlineSnapshot(`""`);
369
- });
370
-
371
- it("should use --local-protocol command line arg, if provided", async () => {
372
- // Here we show that the command line overrides the wrangler.toml by
373
- // setting the config to https, and then setting it back to http on the command line.
374
- writeWranglerToml({
375
- main: "index.js",
376
- dev: {
377
- local_protocol: "https",
378
- },
379
- });
380
- fs.writeFileSync("index.js", `export default {};`);
381
- await runWrangler("dev --local-protocol=http");
382
- expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual("http");
383
- expect(std.out).toMatchInlineSnapshot(`""`);
384
- expect(std.warn).toMatchInlineSnapshot(`""`);
385
- expect(std.err).toMatchInlineSnapshot(`""`);
386
- });
387
- });
388
-
389
- describe("ip", () => {
390
- it("should default ip to localhost", async () => {
391
- writeWranglerToml({
392
- main: "index.js",
393
- });
394
- fs.writeFileSync("index.js", `export default {};`);
395
- await runWrangler("dev");
396
- expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("localhost");
397
- expect(std.out).toMatchInlineSnapshot(`""`);
398
- expect(std.warn).toMatchInlineSnapshot(`""`);
399
- expect(std.err).toMatchInlineSnapshot(`""`);
400
- });
401
-
402
- it("should use to `ip` from `wrangler.toml`, if available", async () => {
403
- writeWranglerToml({
404
- main: "index.js",
405
- dev: {
406
- ip: "0.0.0.0",
407
- },
408
- });
409
- fs.writeFileSync("index.js", `export default {};`);
410
- await runWrangler("dev");
411
- expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("0.0.0.0");
412
- expect(std.out).toMatchInlineSnapshot(`""`);
413
- expect(std.warn).toMatchInlineSnapshot(`""`);
414
- expect(std.err).toMatchInlineSnapshot(`""`);
415
- });
416
-
417
- it("should use --ip command line arg, if provided", async () => {
418
- writeWranglerToml({
419
- main: "index.js",
420
- dev: {
421
- ip: "1.1.1.1",
422
- },
423
- });
424
- fs.writeFileSync("index.js", `export default {};`);
425
- await runWrangler("dev --ip=0.0.0.0");
426
- expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("0.0.0.0");
427
- expect(std.out).toMatchInlineSnapshot(`""`);
428
- expect(std.warn).toMatchInlineSnapshot(`""`);
429
- expect(std.err).toMatchInlineSnapshot(`""`);
430
- });
431
- });
432
- });
433
-
434
- function mockGetZones(domain: string, zones: { id: string }[] = []) {
435
- const removeMock = setMockResponse(
436
- "/zones",
437
- "GET",
438
- (_urlPieces, _init, queryParams) => {
439
- expect([...queryParams.entries()]).toEqual([["name", domain]]);
440
- // 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.
441
- removeMock();
442
- return zones;
443
- }
444
- );
445
- }
@@ -1,154 +0,0 @@
1
- import * as fs from "node:fs";
2
- import React from "react";
3
- import TestRenderer from "react-test-renderer";
4
- import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
5
- import { unsetAllMocks } from "./helpers/mock-cfetch";
6
- import { mockConsoleMethods } from "./helpers/mock-console";
7
- import { runInTempDir } from "./helpers/run-in-tmp";
8
- import type { DevProps, default as DevType } from "../dev/dev";
9
-
10
- function sleep(period = 100): Promise<void> {
11
- return new Promise((resolve) => setTimeout(resolve, period));
12
- }
13
-
14
- // we use this ["mock"] form to avoid esbuild-jest from rewriting it
15
- jest["mock"]("../proxy", () => {
16
- return {
17
- usePreviewServer() {},
18
- waitForPortToBeAvailable() {},
19
- };
20
- });
21
- jest["mock"]("../inspect", () => {
22
- return () => {};
23
- });
24
-
25
- const Dev: typeof DevType = jest.requireActual("../dev/dev").DevImplementation;
26
-
27
- mockAccountId();
28
- mockApiToken();
29
- runInTempDir();
30
- mockConsoleMethods();
31
- afterEach(() => {
32
- unsetAllMocks();
33
- });
34
-
35
- describe("dev", () => {
36
- it("should render", async () => {
37
- fs.writeFileSync("./index.js", `export default {}`);
38
-
39
- const testRenderer = await renderDev({
40
- entry: {
41
- file: "./index.js",
42
- directory: process.cwd(),
43
- format: "modules",
44
- },
45
- });
46
- expect(testRenderer.toJSON()).toMatchInlineSnapshot(`
47
- <ink-box
48
- style={
49
- Object {
50
- "borderStyle": "round",
51
- "flexDirection": "row",
52
- "flexGrow": 0,
53
- "flexShrink": 1,
54
- "marginBottom": 0,
55
- "marginLeft": 0,
56
- "marginRight": 0,
57
- "marginTop": 0,
58
- "paddingBottom": 0,
59
- "paddingLeft": 1,
60
- "paddingRight": 1,
61
- "paddingTop": 0,
62
- }
63
- }
64
- >
65
- <ink-text
66
- internal_transform={[Function]}
67
- style={
68
- Object {
69
- "flexDirection": "row",
70
- "flexGrow": 0,
71
- "flexShrink": 1,
72
- "textWrap": "wrap",
73
- }
74
- }
75
- >
76
- B to open a browser, D to open Devtools, L to turn off local mode, X to exit
77
- </ink-text>
78
- </ink-box>
79
- `);
80
- await TestRenderer.act(async () => {
81
- // TODO: get rid of these sleep statements
82
- await sleep(50);
83
- testRenderer.unmount();
84
- await sleep(50);
85
- });
86
- await sleep(50);
87
- });
88
- });
89
-
90
- async function renderDev({
91
- name,
92
- entry = { file: "index.js", directory: "", format: "modules" },
93
- port,
94
- ip = "localhost",
95
- inspectorPort = 9229,
96
- accountId,
97
- legacyEnv = true,
98
- initialMode = "local",
99
- jsxFactory,
100
- jsxFragment,
101
- localProtocol = "http",
102
- upstreamProtocol = "https",
103
- rules = [],
104
- bindings = {
105
- kv_namespaces: [],
106
- vars: {},
107
- durable_objects: { bindings: [] },
108
- r2_buckets: [],
109
- wasm_modules: undefined,
110
- text_blobs: undefined,
111
- unsafe: [],
112
- },
113
- public: publicDir,
114
- assetPaths,
115
- compatibilityDate,
116
- compatibilityFlags,
117
- usageModel,
118
- buildCommand = {},
119
- enableLocalPersistence = false,
120
- env,
121
- zone,
122
- }: Partial<DevProps>): Promise<TestRenderer.ReactTestRenderer> {
123
- let instance: TestRenderer.ReactTestRenderer | undefined;
124
- await TestRenderer.act(async () => {
125
- instance = TestRenderer.create(
126
- <Dev
127
- name={name}
128
- entry={entry}
129
- env={env}
130
- rules={rules}
131
- port={port}
132
- ip={ip}
133
- inspectorPort={inspectorPort}
134
- legacyEnv={legacyEnv}
135
- buildCommand={buildCommand}
136
- initialMode={initialMode}
137
- localProtocol={localProtocol}
138
- upstreamProtocol={upstreamProtocol}
139
- jsxFactory={jsxFactory}
140
- jsxFragment={jsxFragment}
141
- accountId={accountId}
142
- assetPaths={assetPaths}
143
- public={publicDir}
144
- compatibilityDate={compatibilityDate}
145
- compatibilityFlags={compatibilityFlags}
146
- usageModel={usageModel}
147
- bindings={bindings}
148
- enableLocalPersistence={enableLocalPersistence}
149
- zone={zone}
150
- />
151
- );
152
- });
153
- return instance as TestRenderer.ReactTestRenderer;
154
- }
@@ -1,58 +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
- });
@@ -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
- }