wrangler 0.0.0-e98613f8 → 0.0.0-e9a45766c

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 (244) hide show
  1. package/README.md +10 -4
  2. package/bin/wrangler.js +10 -2
  3. package/miniflare-dist/index.mjs +257 -132
  4. package/package.json +26 -19
  5. package/src/__tests__/api-dev.test.ts +65 -36
  6. package/src/__tests__/api-devregistry.test.ts +121 -0
  7. package/src/__tests__/api.test.ts +27 -5
  8. package/src/__tests__/configuration.test.ts +575 -39
  9. package/src/__tests__/constellation.test.ts +371 -0
  10. package/src/__tests__/d1/d1.test.ts +82 -0
  11. package/src/__tests__/d1/execute.test.ts +66 -0
  12. package/src/__tests__/d1/migrate.test.ts +257 -0
  13. package/src/__tests__/d1/splitter.test.ts +255 -0
  14. package/src/__tests__/delete.test.ts +11 -2
  15. package/src/__tests__/deployments.test.ts +330 -52
  16. package/src/__tests__/dev.test.tsx +146 -82
  17. package/src/__tests__/generate.test.ts +10 -8
  18. package/src/__tests__/guess-worker-format.test.ts +35 -0
  19. package/src/__tests__/helpers/end-event-loop.ts +6 -0
  20. package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
  21. package/src/__tests__/helpers/mock-console.ts +6 -0
  22. package/src/__tests__/helpers/mock-dialogs.ts +71 -85
  23. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
  24. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
  25. package/src/__tests__/helpers/mock-known-routes.ts +7 -2
  26. package/src/__tests__/helpers/mock-kv.ts +29 -16
  27. package/src/__tests__/helpers/mock-oauth-flow.ts +99 -92
  28. package/src/__tests__/helpers/mock-process.ts +8 -13
  29. package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
  30. package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
  31. package/src/__tests__/helpers/msw/handlers/deployments.ts +127 -26
  32. package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
  33. package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
  34. package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
  35. package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
  36. package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
  37. package/src/__tests__/helpers/msw/index.ts +32 -1
  38. package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
  39. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
  40. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  41. package/src/__tests__/index.test.ts +92 -74
  42. package/src/__tests__/init.test.ts +909 -628
  43. package/src/__tests__/jest.setup.ts +19 -42
  44. package/src/__tests__/kv.test.ts +355 -231
  45. package/src/__tests__/logger.test.ts +68 -2
  46. package/src/__tests__/logout.test.ts +1 -1
  47. package/src/__tests__/metrics.test.ts +93 -50
  48. package/src/__tests__/middleware.scheduled.test.ts +42 -32
  49. package/src/__tests__/middleware.test.ts +212 -122
  50. package/src/__tests__/mtls-certificates.test.ts +589 -0
  51. package/src/__tests__/pages/deployment-list.test.ts +80 -0
  52. package/src/__tests__/pages/functions-build.test.ts +528 -0
  53. package/src/__tests__/pages/pages.test.ts +81 -0
  54. package/src/__tests__/pages/project-create.test.ts +63 -0
  55. package/src/__tests__/pages/project-list.test.ts +110 -0
  56. package/src/__tests__/pages/project-upload.test.ts +500 -0
  57. package/src/__tests__/pages/publish.test.ts +2864 -0
  58. package/src/__tests__/pages-deployment-tail.test.ts +239 -102
  59. package/src/__tests__/parse.test.ts +106 -0
  60. package/src/__tests__/publish.test.ts +2218 -1002
  61. package/src/__tests__/pubsub.test.ts +226 -100
  62. package/src/__tests__/queues.test.ts +42 -32
  63. package/src/__tests__/r2.test.ts +37 -56
  64. package/src/__tests__/secret.test.ts +179 -130
  65. package/src/__tests__/tail.test.ts +113 -23
  66. package/src/__tests__/test-old-node-version.js +3 -3
  67. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  68. package/src/__tests__/tsconfig-sanity.ts +12 -0
  69. package/src/__tests__/tsconfig.json +8 -0
  70. package/src/__tests__/tsconfig.tsbuildinfo +1 -0
  71. package/src/__tests__/type-generation.test.ts +8 -0
  72. package/src/__tests__/user.test.ts +7 -18
  73. package/src/__tests__/whoami.test.tsx +8 -114
  74. package/src/__tests__/worker-namespace.test.ts +83 -69
  75. package/src/api/dev.ts +172 -61
  76. package/src/api/index.ts +10 -1
  77. package/src/api/mtls-certificate.ts +148 -0
  78. package/src/api/pages/create-worker-bundle-contents.ts +77 -0
  79. package/src/api/pages/index.ts +5 -0
  80. package/src/api/pages/publish.tsx +371 -0
  81. package/src/bundle.ts +139 -33
  82. package/src/cfetch/index.ts +0 -2
  83. package/src/cfetch/internal.ts +16 -21
  84. package/src/cli.ts +4 -4
  85. package/src/config/config.ts +14 -7
  86. package/src/config/environment.ts +80 -16
  87. package/src/config/index.ts +99 -30
  88. package/src/config/validation-helpers.ts +1 -1
  89. package/src/config/validation.ts +275 -9
  90. package/src/constellation/createProject.tsx +51 -0
  91. package/src/constellation/deleteProject.ts +51 -0
  92. package/src/constellation/deleteProjectModel.ts +68 -0
  93. package/src/constellation/index.ts +75 -0
  94. package/src/constellation/listCatalog.tsx +35 -0
  95. package/src/constellation/listModel.tsx +41 -0
  96. package/src/constellation/listProject.tsx +28 -0
  97. package/src/constellation/listRuntime.tsx +28 -0
  98. package/src/constellation/options.ts +17 -0
  99. package/src/constellation/types.ts +17 -0
  100. package/src/constellation/uploadModel.tsx +64 -0
  101. package/src/constellation/utils.ts +90 -0
  102. package/src/create-worker-preview.ts +19 -8
  103. package/src/create-worker-upload-form.ts +52 -5
  104. package/src/d1/backups.tsx +40 -44
  105. package/src/d1/create.tsx +50 -43
  106. package/src/d1/{delete.tsx → delete.ts} +8 -11
  107. package/src/d1/execute.tsx +171 -166
  108. package/src/d1/index.ts +5 -6
  109. package/src/d1/list.tsx +27 -13
  110. package/src/d1/migrations/apply.tsx +92 -64
  111. package/src/d1/migrations/create.tsx +31 -29
  112. package/src/d1/migrations/helpers.ts +66 -44
  113. package/src/d1/migrations/list.tsx +47 -31
  114. package/src/d1/migrations/options.ts +7 -2
  115. package/src/d1/options.ts +3 -3
  116. package/src/d1/splitter.ts +161 -0
  117. package/src/d1/{types.tsx → types.ts} +1 -0
  118. package/src/d1/utils.ts +2 -1
  119. package/src/delete.ts +8 -16
  120. package/src/deployments.ts +333 -42
  121. package/src/deprecated/index.ts +8 -302
  122. package/src/dev/dev.tsx +13 -22
  123. package/src/dev/local.tsx +131 -69
  124. package/src/dev/remote.tsx +35 -3
  125. package/src/dev/start-server.ts +83 -77
  126. package/src/dev/use-esbuild.ts +63 -52
  127. package/src/dev/validate-dev-props.ts +9 -0
  128. package/src/{dev-registry.tsx → dev-registry.ts} +9 -8
  129. package/src/dev.tsx +131 -110
  130. package/src/dialogs.ts +136 -0
  131. package/src/dispatch-namespace.ts +21 -17
  132. package/src/docs/helpers.ts +50 -0
  133. package/src/docs/index.ts +54 -0
  134. package/src/entry.ts +26 -11
  135. package/src/environment-variables/factory.ts +89 -0
  136. package/src/environment-variables/misc-variables.ts +30 -0
  137. package/src/generate/index.ts +298 -0
  138. package/src/{index.tsx → index.ts} +137 -56
  139. package/src/init.ts +254 -187
  140. package/src/inspect.ts +170 -9
  141. package/src/jest.d.ts +4 -0
  142. package/src/kv/helpers.ts +7 -4
  143. package/src/kv/index.ts +15 -17
  144. package/src/logger.ts +36 -5
  145. package/src/metrics/metrics-config.ts +1 -1
  146. package/src/metrics/send-event.ts +4 -1
  147. package/src/miniflare-cli/assets.ts +66 -31
  148. package/src/miniflare-cli/index.ts +5 -8
  149. package/src/miniflare-cli/tsconfig.json +9 -0
  150. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  151. package/src/miniflare-cli/types.ts +11 -0
  152. package/src/module-collection.ts +92 -26
  153. package/src/mtls-certificate/cli.ts +155 -0
  154. package/src/pages/build.ts +423 -0
  155. package/src/pages/buildFunctions.ts +140 -0
  156. package/src/pages/{deployment-tails.tsx → deployment-tails.ts} +7 -10
  157. package/src/pages/deployments.tsx +9 -9
  158. package/src/pages/{dev.tsx → dev.ts} +167 -139
  159. package/src/pages/errors.ts +1 -0
  160. package/src/pages/functions/buildPlugin.ts +61 -54
  161. package/src/pages/functions/buildWorker.ts +217 -33
  162. package/src/pages/functions/tsconfig.json +8 -0
  163. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  164. package/src/pages/{functions.tsx → functions.ts} +8 -4
  165. package/src/pages/{index.tsx → index.ts} +3 -3
  166. package/src/pages/projects.tsx +12 -22
  167. package/src/pages/publish.tsx +43 -227
  168. package/src/pages/types.ts +5 -0
  169. package/src/pages/upload.tsx +57 -14
  170. package/src/pages/utils.ts +1 -1
  171. package/src/parse.ts +23 -1
  172. package/src/paths.ts +1 -1
  173. package/src/publish/index.ts +20 -16
  174. package/src/publish/publish.ts +76 -46
  175. package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +19 -20
  176. package/src/queues/cli/commands/consumer/add.ts +24 -24
  177. package/src/queues/cli/commands/consumer/index.ts +3 -6
  178. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  179. package/src/queues/cli/commands/create.ts +8 -8
  180. package/src/queues/cli/commands/delete.ts +8 -8
  181. package/src/queues/cli/commands/index.ts +3 -4
  182. package/src/queues/cli/commands/list.ts +8 -8
  183. package/src/queues/client.ts +1 -0
  184. package/src/r2/helpers.ts +1 -0
  185. package/src/r2/index.ts +28 -28
  186. package/src/secret/index.ts +15 -16
  187. package/src/{sites.tsx → sites.ts} +165 -53
  188. package/src/tail/createTail.ts +37 -1
  189. package/src/tail/filters.ts +1 -1
  190. package/src/tail/index.ts +8 -11
  191. package/src/tail/printing.ts +25 -0
  192. package/src/traverse-module-graph.ts +54 -0
  193. package/src/tsconfig-sanity.ts +16 -0
  194. package/src/type-generation.ts +11 -3
  195. package/src/user/access.ts +0 -1
  196. package/src/user/auth-variables.ts +113 -0
  197. package/src/user/choose-account.tsx +1 -31
  198. package/src/user/index.ts +0 -1
  199. package/src/user/{user.tsx → user.ts} +114 -77
  200. package/src/utils/render.ts +93 -0
  201. package/src/{whoami.tsx → whoami.ts} +37 -71
  202. package/src/worker.ts +35 -1
  203. package/src/yargs-types.ts +18 -5
  204. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  205. package/templates/__tests__/tsconfig.json +8 -0
  206. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  207. package/templates/checked-fetch.js +9 -3
  208. package/templates/d1-beta-facade.js +42 -3
  209. package/templates/facade.d.ts +14 -0
  210. package/templates/first-party-worker-module-facade.ts +4 -3
  211. package/templates/format-dev-errors.ts +8 -6
  212. package/templates/gitignore +1 -0
  213. package/templates/init-tests/test-jest-new-worker.js +3 -5
  214. package/templates/init-tests/test-vitest-new-worker.js +3 -5
  215. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  216. package/templates/middleware/loader-modules.ts +2 -2
  217. package/templates/middleware/loader-sw.ts +6 -0
  218. package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
  219. package/templates/new-worker.ts +3 -0
  220. package/templates/pages-dev-pipeline.ts +4 -1
  221. package/templates/pages-shim.ts +4 -1
  222. package/templates/pages-template-plugin.ts +19 -10
  223. package/templates/serve-static-assets.ts +17 -14
  224. package/templates/service-bindings-module-facade.js +1 -0
  225. package/templates/tsconfig-sanity.ts +11 -0
  226. package/templates/tsconfig.init.json +105 -0
  227. package/templates/tsconfig.json +5 -103
  228. package/templates/tsconfig.tsbuildinfo +1 -0
  229. package/wrangler-dist/cli.d.ts +871 -73
  230. package/wrangler-dist/cli.js +80512 -90686
  231. package/wrangler-dist/wasm-sync.wasm +0 -0
  232. package/src/__tests__/api-devregistry.test.js +0 -56
  233. package/src/__tests__/d1.test.ts +0 -80
  234. package/src/__tests__/dialogs.test.tsx +0 -40
  235. package/src/__tests__/helpers/mock-cfetch.ts +0 -333
  236. package/src/__tests__/pages.test.ts +0 -2442
  237. package/src/dialogs.tsx +0 -168
  238. package/src/environment-variables.ts +0 -50
  239. package/src/pages/build.tsx +0 -270
  240. package/src/user/env-vars.ts +0 -46
  241. /package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
  242. /package/src/d1/migrations/{index.tsx → index.ts} +0 -0
  243. /package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
  244. /package/src/pages/{hash.tsx → hash.ts} +0 -0
@@ -1,11 +1,11 @@
1
1
  import * as fs from "node:fs";
2
2
  import getPort from "get-port";
3
+ import { rest } from "msw";
3
4
  import patchConsole from "patch-console";
4
5
  import dedent from "ts-dedent";
5
6
  import Dev from "../dev/dev";
6
7
  import { CI } from "../is-ci";
7
8
  import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
8
- import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
9
9
  import { mockConsoleMethods } from "./helpers/mock-console";
10
10
  import {
11
11
  msw,
@@ -33,7 +33,7 @@ describe("wrangler dev", () => {
33
33
  afterEach(() => {
34
34
  (Dev as jest.Mock).mockClear();
35
35
  patchConsole(() => {});
36
- unsetAllMocks();
36
+ msw.resetHandlers();
37
37
  });
38
38
 
39
39
  describe("authorization", () => {
@@ -136,7 +136,7 @@ describe("wrangler dev", () => {
136
136
 
137
137
  expect(std.out).toMatchInlineSnapshot(`
138
138
  "
139
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
139
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
140
140
  `);
141
141
  expect(std.err).toMatchInlineSnapshot(`
142
142
  "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.
@@ -439,16 +439,44 @@ describe("wrangler dev", () => {
439
439
  main: "index.js",
440
440
  });
441
441
  fs.writeFileSync("index.js", `export default {};`);
442
- mockGetZones("111.222.333.some-host.com", []);
443
- mockGetZones("222.333.some-host.com", []);
444
- mockGetZones("333.some-host.com", [{ id: "some-zone-id" }]);
445
- await runWrangler("dev --host 111.222.333.some-host.com");
446
- expect((Dev as jest.Mock).mock.calls[0][0]).toEqual(
447
- expect.objectContaining({
448
- host: "111.222.333.some-host.com",
449
- zone: "some-zone-id",
442
+
443
+ msw.use(
444
+ rest.get("*/zones", (req, res, ctx) => {
445
+ let zone: [] | [{ id: "some-zone-id" }] = [];
446
+ if (
447
+ req.url.searchParams.get("name") === "111.222.333.some-host.com"
448
+ ) {
449
+ zone = [];
450
+ } else if (
451
+ req.url.searchParams.get("name") === "222.333.some-host.com"
452
+ ) {
453
+ zone = [];
454
+ } else if (req.url.searchParams.get("name") === "333.some-host.com") {
455
+ zone = [{ id: "some-zone-id" }];
456
+ }
457
+
458
+ return res(
459
+ ctx.status(200),
460
+ ctx.json({
461
+ success: true,
462
+ errors: [],
463
+ messages: [],
464
+ result: zone,
465
+ })
466
+ );
450
467
  })
451
468
  );
469
+
470
+ await runWrangler("dev --host 111.222.333.some-host.com");
471
+
472
+ const devMockCall = (Dev as jest.Mock).mock.calls[0][0];
473
+
474
+ expect(devMockCall).toHaveProperty("host", "111.222.333.some-host.com");
475
+ expect(devMockCall).toHaveProperty(
476
+ "localUpstream",
477
+ "111.222.333.some-host.com"
478
+ );
479
+ expect(devMockCall).toHaveProperty("zone", "some-zone-id");
452
480
  });
453
481
 
454
482
  it("should, in order, use args.host/config.dev.host/args.routes/(config.route|config.routes)", async () => {
@@ -607,7 +635,7 @@ describe("wrangler dev", () => {
607
635
  it("should run a custom build before starting `dev`", async () => {
608
636
  writeWranglerToml({
609
637
  build: {
610
- command: `node -e "console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')"`,
638
+ command: `node -e "4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')"`,
611
639
  },
612
640
  });
613
641
 
@@ -620,12 +648,12 @@ describe("wrangler dev", () => {
620
648
  // and the command would pass through
621
649
  expect((Dev as jest.Mock).mock.calls[0][0].build).toEqual({
622
650
  command:
623
- "node -e \"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\"",
651
+ "node -e \"4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\"",
624
652
  cwd: undefined,
625
653
  watch_dir: "src",
626
654
  });
627
655
  expect(std.out).toMatchInlineSnapshot(
628
- `"Running custom build: node -e \\"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\""`
656
+ `"Running custom build: node -e \\"4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\""`
629
657
  );
630
658
  expect(std.err).toMatchInlineSnapshot(`""`);
631
659
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -635,7 +663,7 @@ describe("wrangler dev", () => {
635
663
  it("should run a custom build of multiple steps combined by && before starting `dev`", async () => {
636
664
  writeWranglerToml({
637
665
  build: {
638
- command: `echo "custom build" && echo "export default { fetch(){ return new Response(123) } }" > index.js`,
666
+ command: `echo "export default { fetch(){ return new Response(123) } }" > index.js`,
639
667
  },
640
668
  });
641
669
 
@@ -647,7 +675,7 @@ describe("wrangler dev", () => {
647
675
  `);
648
676
 
649
677
  expect(std.out).toMatchInlineSnapshot(
650
- `"Running custom build: echo \\"custom build\\" && echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js"`
678
+ `"Running custom build: echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js"`
651
679
  );
652
680
  expect(std.err).toMatchInlineSnapshot(`""`);
653
681
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -658,27 +686,27 @@ describe("wrangler dev", () => {
658
686
  writeWranglerToml({
659
687
  main: "index.js",
660
688
  build: {
661
- command: `node -e "console.log('custom build');"`,
689
+ command: `node -e "4+4;"`,
662
690
  },
663
691
  });
664
692
 
665
693
  await expect(runWrangler("dev")).rejects
666
694
  .toThrowErrorMatchingInlineSnapshot(`
667
- "The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
668
- The \`main\` property in wrangler.toml should point to the file generated by the custom build."
669
- `);
695
+ "The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"4+4;\\".
696
+ The \`main\` property in wrangler.toml should point to the file generated by the custom build."
697
+ `);
670
698
  expect(std.out).toMatchInlineSnapshot(`
671
- "Running custom build: node -e \\"console.log('custom build');\\"
699
+ "Running custom build: node -e \\"4+4;\\"
672
700
 
673
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
674
- `);
701
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
702
+ `);
675
703
  expect(std.err).toMatchInlineSnapshot(`
676
- "X [ERROR] The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
704
+ "X [ERROR] The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"4+4;\\".
677
705
 
678
- The \`main\` property in wrangler.toml should point to the file generated by the custom build.
706
+ The \`main\` property in wrangler.toml should point to the file generated by the custom build.
679
707
 
680
- "
681
- `);
708
+ "
709
+ `);
682
710
  expect(std.warn).toMatchInlineSnapshot(`""`);
683
711
  });
684
712
 
@@ -746,7 +774,7 @@ describe("wrangler dev", () => {
746
774
  "▲ [WARNING] Setting upstream-protocol to http is not currently implemented.
747
775
 
748
776
  If this is required in your project, please add your use case to the following issue:
749
- https://github.com/cloudflare/wrangler2/issues/583.
777
+ https://github.com/cloudflare/workers-sdk/issues/583.
750
778
 
751
779
  "
752
780
  `);
@@ -866,6 +894,7 @@ describe("wrangler dev", () => {
866
894
  Object {
867
895
  "debug": "",
868
896
  "err": "",
897
+ "info": "",
869
898
  "out": "",
870
899
  "warn": "",
871
900
  }
@@ -883,6 +912,7 @@ describe("wrangler dev", () => {
883
912
  Object {
884
913
  "debug": "",
885
914
  "err": "",
915
+ "info": "",
886
916
  "out": "",
887
917
  "warn": "",
888
918
  }
@@ -900,6 +930,7 @@ describe("wrangler dev", () => {
900
930
  Object {
901
931
  "debug": "",
902
932
  "err": "",
933
+ "info": "",
903
934
  "out": "",
904
935
  "warn": "",
905
936
  }
@@ -920,6 +951,7 @@ describe("wrangler dev", () => {
920
951
  Object {
921
952
  "debug": "",
922
953
  "err": "",
954
+ "info": "",
923
955
  "out": "",
924
956
  "warn": "",
925
957
  }
@@ -1181,6 +1213,7 @@ describe("wrangler dev", () => {
1181
1213
  "err": "X [ERROR] Not enough arguments following: site
1182
1214
 
1183
1215
  ",
1216
+ "info": "",
1184
1217
  "out": "
1185
1218
  wrangler dev [script]
1186
1219
 
@@ -1190,10 +1223,11 @@ describe("wrangler dev", () => {
1190
1223
  script The path to an entry point for your worker [string]
1191
1224
 
1192
1225
  Flags:
1193
- -c, --config Path to .toml configuration file [string]
1194
- -e, --env Environment to use for operations and .env files [string]
1195
- -h, --help Show help [boolean]
1196
- -v, --version Show version number [boolean]
1226
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
1227
+ -c, --config Path to .toml configuration file [string]
1228
+ -e, --env Environment to use for operations and .env files [string]
1229
+ -h, --help Show help [boolean]
1230
+ -v, --version Show version number [boolean]
1197
1231
 
1198
1232
  Options:
1199
1233
  --name Name of the worker [string]
@@ -1222,7 +1256,7 @@ describe("wrangler dev", () => {
1222
1256
  --experimental-local Run on my machine using the Cloudflare Workers runtime [boolean] [default: false]
1223
1257
  --experimental-local-remote-kv Read/write KV data from/to real namespaces on the Cloudflare network [boolean] [default: false]
1224
1258
  --minify Minify the script [boolean]
1225
- --node-compat Enable node.js compatibility [boolean]
1259
+ --node-compat Enable Node.js compatibility [boolean]
1226
1260
  --persist Enable persistence for local mode, using default path: .wrangler/state [boolean]
1227
1261
  --persist-to Specify directory to use for local persistence (implies --persist) [string]
1228
1262
  --live-reload Auto reload HTML pages when change is detected in local mode [boolean]
@@ -1314,15 +1348,16 @@ describe("wrangler dev", () => {
1314
1348
 
1315
1349
  await runWrangler('dev --assets "./assets"');
1316
1350
  expect(std).toMatchInlineSnapshot(`
1317
- Object {
1318
- "debug": "",
1319
- "err": "",
1320
- "out": "",
1321
- "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1322
-
1323
- ",
1324
- }
1325
- `);
1351
+ Object {
1352
+ "debug": "",
1353
+ "err": "",
1354
+ "info": "",
1355
+ "out": "",
1356
+ "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1357
+
1358
+ ",
1359
+ }
1360
+ `);
1326
1361
  });
1327
1362
 
1328
1363
  it("should warn if config.assets is used", async () => {
@@ -1335,17 +1370,18 @@ describe("wrangler dev", () => {
1335
1370
 
1336
1371
  await runWrangler("dev");
1337
1372
  expect(std).toMatchInlineSnapshot(`
1338
- Object {
1339
- "debug": "",
1340
- "err": "",
1341
- "out": "",
1342
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1373
+ Object {
1374
+ "debug": "",
1375
+ "err": "",
1376
+ "info": "",
1377
+ "out": "",
1378
+ "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1343
1379
 
1344
- - \\"assets\\" fields are experimental and may change or break at any time.
1380
+ - \\"assets\\" fields are experimental and may change or break at any time.
1345
1381
 
1346
- ",
1347
- }
1348
- `);
1382
+ ",
1383
+ }
1384
+ `);
1349
1385
  });
1350
1386
  });
1351
1387
 
@@ -1354,15 +1390,16 @@ describe("wrangler dev", () => {
1354
1390
  fs.writeFileSync("index.js", `export default {};`);
1355
1391
  await runWrangler("dev index.js --inspect");
1356
1392
  expect(std).toMatchInlineSnapshot(`
1357
- Object {
1358
- "debug": "",
1359
- "err": "",
1360
- "out": "",
1361
- "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1362
-
1363
- ",
1364
- }
1365
- `);
1393
+ Object {
1394
+ "debug": "",
1395
+ "err": "",
1396
+ "info": "",
1397
+ "out": "",
1398
+ "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1399
+
1400
+ ",
1401
+ }
1402
+ `);
1366
1403
  });
1367
1404
 
1368
1405
  it("should default to true, without a warning", async () => {
@@ -1373,6 +1410,7 @@ describe("wrangler dev", () => {
1373
1410
  Object {
1374
1411
  "debug": "",
1375
1412
  "err": "",
1413
+ "info": "",
1376
1414
  "out": "",
1377
1415
  "warn": "",
1378
1416
  }
@@ -1387,6 +1425,7 @@ describe("wrangler dev", () => {
1387
1425
  Object {
1388
1426
  "debug": "",
1389
1427
  "err": "",
1428
+ "info": "",
1390
1429
  "out": "",
1391
1430
  "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1392
1431
 
@@ -1403,6 +1442,7 @@ describe("wrangler dev", () => {
1403
1442
  Object {
1404
1443
  "debug": "",
1405
1444
  "err": "",
1445
+ "info": "",
1406
1446
  "out": "",
1407
1447
  "warn": "",
1408
1448
  }
@@ -1418,6 +1458,7 @@ describe("wrangler dev", () => {
1418
1458
  Object {
1419
1459
  "debug": "",
1420
1460
  "err": "",
1461
+ "info": "",
1421
1462
  "out": "",
1422
1463
  "warn": "",
1423
1464
  }
@@ -1431,6 +1472,7 @@ describe("wrangler dev", () => {
1431
1472
  Object {
1432
1473
  "debug": "",
1433
1474
  "err": "",
1475
+ "info": "",
1434
1476
  "out": "",
1435
1477
  "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1436
1478
 
@@ -1487,23 +1529,24 @@ describe("wrangler dev", () => {
1487
1529
  fs.writeFileSync("index.js", `export default {};`);
1488
1530
  await runWrangler("dev index.js");
1489
1531
  expect(std).toMatchInlineSnapshot(`
1490
- Object {
1491
- "debug": "",
1492
- "err": "",
1493
- "out": "Your worker has access to the following bindings:
1494
- - Services:
1495
- - WorkerA: A
1496
- - WorkerB: B - staging",
1497
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1532
+ Object {
1533
+ "debug": "",
1534
+ "err": "",
1535
+ "info": "",
1536
+ "out": "Your worker has access to the following bindings:
1537
+ - Services:
1538
+ - WorkerA: A
1539
+ - WorkerB: B - staging",
1540
+ "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1498
1541
 
1499
- - \\"services\\" fields are experimental and may change or break at any time.
1542
+ - \\"services\\" fields are experimental and may change or break at any time.
1500
1543
 
1501
1544
 
1502
- ▲ [WARNING] This worker is bound to live services: WorkerA (A), WorkerB (B@staging)
1545
+ ▲ [WARNING] This worker is bound to live services: WorkerA (A), WorkerB (B@staging)
1503
1546
 
1504
- ",
1505
- }
1506
- `);
1547
+ ",
1548
+ }
1549
+ `);
1507
1550
  });
1508
1551
 
1509
1552
  it("should mask vars that were overriden in .dev.vars", async () => {
@@ -1526,6 +1569,7 @@ describe("wrangler dev", () => {
1526
1569
  Object {
1527
1570
  "debug": "",
1528
1571
  "err": "",
1572
+ "info": "",
1529
1573
  "out": "Using vars defined in .dev.vars
1530
1574
  Your worker has access to the following bindings:
1531
1575
  - Vars:
@@ -1537,17 +1581,37 @@ describe("wrangler dev", () => {
1537
1581
  `);
1538
1582
  });
1539
1583
  });
1584
+
1585
+ describe("`nodejs_compat` compatibility flag", () => {
1586
+ it("should conflict with the --node-compat option", async () => {
1587
+ writeWranglerToml();
1588
+ fs.writeFileSync("index.js", `export default {};`);
1589
+
1590
+ await expect(
1591
+ runWrangler(
1592
+ "dev index.js --compatibility-flag=nodejs_compat --node-compat"
1593
+ )
1594
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
1595
+ `"The \`nodejs_compat\` compatibility flag cannot be used in conjunction with the legacy \`--node-compat\` flag. If you want to use the Workers runtime Node.js compatibility features, please remove the \`--node-compat\` argument from your CLI command or \`node_compat = true\` from your config file."`
1596
+ );
1597
+ });
1598
+ });
1540
1599
  });
1541
1600
 
1542
1601
  function mockGetZones(domain: string, zones: { id: string }[] = []) {
1543
- const removeMock = setMockResponse(
1544
- "/zones",
1545
- "GET",
1546
- (_urlPieces, _init, queryParams) => {
1547
- expect([...queryParams.entries()]).toEqual([["name", domain]]);
1548
- // 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.
1549
- removeMock();
1550
- return zones;
1551
- }
1602
+ msw.use(
1603
+ rest.get("*/zones", (req, res, ctx) => {
1604
+ expect([...req.url.searchParams.entries()]).toEqual([["name", domain]]);
1605
+
1606
+ return res(
1607
+ ctx.status(200),
1608
+ ctx.json({
1609
+ success: true,
1610
+ errors: [],
1611
+ messages: [],
1612
+ result: zones,
1613
+ })
1614
+ );
1615
+ })
1552
1616
  );
1553
1617
  }
@@ -1,18 +1,21 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { mockConsoleMethods } from "./helpers/mock-console";
4
- import { mockConfirm, clearConfirmMocks } from "./helpers/mock-dialogs";
4
+ import { mockConfirm } from "./helpers/mock-dialogs";
5
+ import { useMockIsTTY } from "./helpers/mock-istty";
5
6
  import { runInTempDir } from "./helpers/run-in-tmp";
6
7
  import { runWrangler } from "./helpers/run-wrangler";
7
8
 
8
9
  describe("generate", () => {
9
10
  runInTempDir();
11
+ const { setIsTTY } = useMockIsTTY();
10
12
  const std = mockConsoleMethods();
13
+ beforeEach(() => {
14
+ setIsTTY(true);
15
+ });
11
16
 
12
17
  describe("cli functionality", () => {
13
- afterEach(() => {
14
- clearConfirmMocks();
15
- });
18
+ afterEach(() => {});
16
19
 
17
20
  it("defers to `wrangler init` when no template is given", async () => {
18
21
  mockConfirm(
@@ -113,10 +116,9 @@ describe("generate", () => {
113
116
  ".git": expect.any(Object),
114
117
  ".gitignore": expect.any(String),
115
118
  "README.md": expect.stringContaining("Template: worker-typescript"),
116
- "jest.config.json": expect.any(String),
117
119
  "package.json": expect.stringContaining("@cloudflare/workers-types"),
118
- src: expect.objectContaining({ "index.ts": expect.any(String) }),
119
- test: expect.objectContaining({
120
+ src: expect.objectContaining({
121
+ "index.ts": expect.any(String),
120
122
  "index.test.ts": expect.any(String),
121
123
  }),
122
124
  "tsconfig.json": expect.any(String),
@@ -128,7 +130,7 @@ describe("generate", () => {
128
130
  // was harder than i thought, leaving this for now.
129
131
  it.todo("clones a cloudflare template with full checkouts");
130
132
 
131
- it("clones a user/repo template", async () => {
133
+ it.skip("clones a user/repo template", async () => {
132
134
  await expect(
133
135
  runWrangler("generate my-worker caass/wrangler-generate-test-template")
134
136
  ).resolves.toBeUndefined();
@@ -32,6 +32,41 @@ describe("guess worker format", () => {
32
32
  expect(guess).toBe("service-worker");
33
33
  });
34
34
 
35
+ it('should detect a "service-worker" worker using `typeof module`', async () => {
36
+ await writeFile("./index.ts", "typeof module");
37
+ const guess = await guessWorkerFormat(
38
+ path.join(process.cwd(), "./index.ts"),
39
+ process.cwd(),
40
+ undefined
41
+ );
42
+ expect(guess).toBe("service-worker");
43
+ });
44
+
45
+ it('should detect a "service-worker" worker using imports', async () => {
46
+ await writeFile(
47
+ "./dep.ts",
48
+ `
49
+ const value = 'thing';
50
+ export default value;
51
+ `
52
+ );
53
+ await writeFile(
54
+ "./index.ts",
55
+ `
56
+ import value from './dep.ts';
57
+ addEventListener('fetch', (event) => {
58
+ event.respondWith(new Response(value));
59
+ });
60
+ `
61
+ );
62
+ const guess = await guessWorkerFormat(
63
+ path.join(process.cwd(), "./index.ts"),
64
+ process.cwd(),
65
+ undefined
66
+ );
67
+ expect(guess).toBe("service-worker");
68
+ });
69
+
35
70
  it("should throw an error when the hint doesn't match the guess (modules - service-worker)", async () => {
36
71
  await writeFile("./index.ts", "export default {};");
37
72
  await expect(
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Forces a tick and ensures that all pending promises resolve
3
+ */
4
+ export function endEventLoop() {
5
+ return new Promise((resolve) => setImmediate(resolve));
6
+ }
@@ -0,0 +1,20 @@
1
+ const ORIGINAL_WRANGLER_AUTH_DOMAIN = process.env.WRANGLER_AUTH_DOMAIN;
2
+
3
+ /**
4
+ * Mock the Auth URL domain so that we can control where we attempt to login.
5
+ *
6
+ * Note that you can remove any API token from the environment by setting the value to `null`.
7
+ * This is useful if a higher `describe()` block has already called `mockAuthDomain()`.
8
+ */
9
+ export function mockAuthDomain({ domain }: { domain: string | null }) {
10
+ beforeEach(() => {
11
+ if (domain === null) {
12
+ delete process.env.WRANGLER_AUTH_DOMAIN;
13
+ } else {
14
+ process.env.WRANGLER_AUTH_DOMAIN = domain;
15
+ }
16
+ });
17
+ afterEach(() => {
18
+ process.env.WRANGLER_AUTH_DOMAIN = ORIGINAL_WRANGLER_AUTH_DOMAIN;
19
+ });
20
+ }
@@ -8,6 +8,7 @@ import { logger } from "../../logger";
8
8
 
9
9
  let debugSpy: jest.SpyInstance,
10
10
  logSpy: jest.SpyInstance,
11
+ infoSpy: jest.SpyInstance,
11
12
  errorSpy: jest.SpyInstance,
12
13
  warnSpy: jest.SpyInstance;
13
14
 
@@ -18,6 +19,9 @@ const std = {
18
19
  get out() {
19
20
  return normalizeOutput(logSpy);
20
21
  },
22
+ get info() {
23
+ return normalizeOutput(infoSpy);
24
+ },
21
25
  get err() {
22
26
  return normalizeOutput(errorSpy);
23
27
  },
@@ -47,12 +51,14 @@ export function mockConsoleMethods() {
47
51
  logger.columns = 100;
48
52
  debugSpy = jest.spyOn(console, "debug").mockImplementation();
49
53
  logSpy = jest.spyOn(console, "log").mockImplementation();
54
+ infoSpy = jest.spyOn(console, "info").mockImplementation();
50
55
  errorSpy = jest.spyOn(console, "error").mockImplementation();
51
56
  warnSpy = jest.spyOn(console, "warn").mockImplementation();
52
57
  });
53
58
  afterEach(() => {
54
59
  debugSpy.mockRestore();
55
60
  logSpy.mockRestore();
61
+ infoSpy.mockRestore();
56
62
  errorSpy.mockRestore();
57
63
  warnSpy.mockRestore();
58
64
  });