wrangler 0.0.0-e7a0cd5b → 0.0.0-e87ad068

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 (255) hide show
  1. package/README.md +3 -3
  2. package/bin/wrangler.js +30 -10
  3. package/miniflare-dist/index.mjs +254 -128
  4. package/package.json +27 -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 +797 -98
  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 +91 -49
  15. package/src/__tests__/deployments.test.ts +330 -56
  16. package/src/__tests__/dev.test.tsx +198 -90
  17. package/src/__tests__/generate.test.ts +12 -10
  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 +103 -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 +128 -27
  32. package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
  33. package/src/__tests__/helpers/msw/handlers/oauth.ts +13 -18
  34. package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
  35. package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
  36. package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
  37. package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
  38. package/src/__tests__/helpers/msw/index.ts +32 -1
  39. package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
  40. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
  41. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  42. package/src/__tests__/index.test.ts +92 -72
  43. package/src/__tests__/init.test.ts +1033 -631
  44. package/src/__tests__/jest.setup.ts +19 -42
  45. package/src/__tests__/kv.test.ts +355 -231
  46. package/src/__tests__/logger.test.ts +68 -2
  47. package/src/__tests__/logout.test.ts +47 -0
  48. package/src/__tests__/metrics.test.ts +94 -51
  49. package/src/__tests__/middleware.scheduled.test.ts +42 -32
  50. package/src/__tests__/middleware.test.ts +212 -122
  51. package/src/__tests__/mtls-certificates.test.ts +589 -0
  52. package/src/__tests__/pages/deployment-list.test.ts +80 -0
  53. package/src/__tests__/pages/functions-build.test.ts +529 -0
  54. package/src/__tests__/pages/pages.test.ts +81 -0
  55. package/src/__tests__/pages/project-create.test.ts +63 -0
  56. package/src/__tests__/pages/project-list.test.ts +110 -0
  57. package/src/__tests__/pages/project-upload.test.ts +500 -0
  58. package/src/__tests__/pages/publish.test.ts +2864 -0
  59. package/src/__tests__/pages-deployment-tail.test.ts +957 -0
  60. package/src/__tests__/parse.test.ts +106 -0
  61. package/src/__tests__/publish.test.ts +2227 -1005
  62. package/src/__tests__/pubsub.test.ts +226 -100
  63. package/src/__tests__/queues.test.ts +238 -77
  64. package/src/__tests__/r2.test.ts +55 -57
  65. package/src/__tests__/secret.test.ts +179 -130
  66. package/src/__tests__/tail.test.ts +313 -113
  67. package/src/__tests__/test-old-node-version.js +3 -3
  68. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  69. package/src/__tests__/tsconfig-sanity.ts +12 -0
  70. package/src/__tests__/tsconfig.json +8 -0
  71. package/src/__tests__/tsconfig.tsbuildinfo +1 -0
  72. package/src/__tests__/type-generation.test.ts +43 -26
  73. package/src/__tests__/unstableDev.test.ts +61 -0
  74. package/src/__tests__/user.test.ts +35 -72
  75. package/src/__tests__/whoami.test.tsx +8 -114
  76. package/src/__tests__/worker-namespace.test.ts +83 -69
  77. package/src/api/dev.ts +180 -60
  78. package/src/api/index.ts +10 -1
  79. package/src/api/mtls-certificate.ts +148 -0
  80. package/src/api/pages/create-worker-bundle-contents.ts +80 -0
  81. package/src/api/pages/index.ts +5 -0
  82. package/src/api/pages/publish.tsx +371 -0
  83. package/src/bundle.ts +315 -148
  84. package/src/cfetch/index.ts +0 -2
  85. package/src/cfetch/internal.ts +33 -33
  86. package/src/cli.ts +4 -4
  87. package/src/config/config.ts +14 -7
  88. package/src/config/environment.ts +120 -24
  89. package/src/config/index.ts +117 -35
  90. package/src/config/validation-helpers.ts +1 -1
  91. package/src/config/validation.ts +430 -19
  92. package/src/constellation/createProject.tsx +51 -0
  93. package/src/constellation/deleteProject.ts +51 -0
  94. package/src/constellation/deleteProjectModel.ts +76 -0
  95. package/src/constellation/index.ts +75 -0
  96. package/src/constellation/listCatalog.tsx +35 -0
  97. package/src/constellation/listModel.tsx +49 -0
  98. package/src/constellation/listProject.tsx +28 -0
  99. package/src/constellation/listRuntime.tsx +28 -0
  100. package/src/constellation/options.ts +17 -0
  101. package/src/constellation/types.ts +17 -0
  102. package/src/constellation/uploadModel.tsx +84 -0
  103. package/src/constellation/utils.ts +90 -0
  104. package/src/create-worker-preview.ts +19 -8
  105. package/src/create-worker-upload-form.ts +81 -18
  106. package/src/d1/backups.tsx +47 -46
  107. package/src/d1/constants.ts +5 -0
  108. package/src/d1/create.tsx +85 -37
  109. package/src/d1/{delete.tsx → delete.ts} +12 -15
  110. package/src/d1/execute.tsx +228 -156
  111. package/src/d1/index.ts +31 -7
  112. package/src/d1/list.tsx +27 -13
  113. package/src/d1/migrations/apply.tsx +235 -0
  114. package/src/d1/migrations/create.tsx +79 -0
  115. package/src/d1/migrations/helpers.ts +171 -0
  116. package/src/d1/migrations/index.ts +3 -0
  117. package/src/d1/migrations/list.tsx +95 -0
  118. package/src/d1/migrations/options.ts +23 -0
  119. package/src/d1/options.ts +12 -2
  120. package/src/d1/splitter.ts +161 -0
  121. package/src/d1/types.ts +32 -0
  122. package/src/d1/utils.ts +12 -2
  123. package/src/delete.ts +8 -16
  124. package/src/deployments.ts +340 -46
  125. package/src/deprecated/index.ts +8 -302
  126. package/src/dev/dev.tsx +66 -46
  127. package/src/dev/local.tsx +339 -104
  128. package/src/dev/remote.tsx +36 -3
  129. package/src/dev/start-server.ts +146 -101
  130. package/src/dev/use-esbuild.ts +82 -56
  131. package/src/dev/validate-dev-props.ts +9 -0
  132. package/src/{dev-registry.tsx → dev-registry.ts} +13 -1
  133. package/src/dev.tsx +202 -125
  134. package/src/dialogs.ts +136 -0
  135. package/src/dispatch-namespace.ts +21 -17
  136. package/src/docs/helpers.ts +50 -0
  137. package/src/docs/index.ts +54 -0
  138. package/src/entry.ts +26 -11
  139. package/src/environment-variables/factory.ts +89 -0
  140. package/src/environment-variables/misc-variables.ts +30 -0
  141. package/src/generate/index.ts +303 -0
  142. package/src/git-client.ts +15 -4
  143. package/src/{index.tsx → index.ts} +148 -63
  144. package/src/init.ts +301 -197
  145. package/src/inspect.ts +122 -6
  146. package/src/jest.d.ts +4 -0
  147. package/src/kv/helpers.ts +7 -4
  148. package/src/kv/index.ts +15 -17
  149. package/src/logger.ts +36 -5
  150. package/src/metrics/metrics-config.ts +3 -3
  151. package/src/metrics/send-event.ts +6 -1
  152. package/src/miniflare-cli/assets.ts +64 -28
  153. package/src/miniflare-cli/index.ts +6 -9
  154. package/src/miniflare-cli/tsconfig.json +9 -0
  155. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  156. package/src/miniflare-cli/types.ts +11 -0
  157. package/src/module-collection.ts +92 -26
  158. package/src/mtls-certificate/cli.ts +155 -0
  159. package/src/pages/build.ts +423 -0
  160. package/src/pages/buildFunctions.ts +140 -0
  161. package/src/pages/deployment-tails.ts +281 -0
  162. package/src/pages/deployments.tsx +11 -33
  163. package/src/pages/{dev.tsx → dev.ts} +192 -126
  164. package/src/pages/errors.ts +1 -0
  165. package/src/pages/functions/buildPlugin.ts +73 -69
  166. package/src/pages/functions/buildWorker.ts +342 -117
  167. package/src/pages/functions/tsconfig.json +8 -0
  168. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  169. package/src/pages/{functions.tsx → functions.ts} +8 -4
  170. package/src/pages/{index.tsx → index.ts} +11 -3
  171. package/src/pages/projects.tsx +12 -22
  172. package/src/pages/prompt-select-project.tsx +31 -0
  173. package/src/pages/publish.tsx +45 -214
  174. package/src/pages/types.ts +6 -9
  175. package/src/pages/upload.tsx +58 -14
  176. package/src/pages/utils.ts +14 -3
  177. package/src/parse.ts +23 -1
  178. package/src/paths.ts +1 -1
  179. package/src/proxy.ts +5 -0
  180. package/src/publish/index.ts +20 -16
  181. package/src/publish/publish.ts +81 -48
  182. package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +19 -20
  183. package/src/queues/cli/commands/consumer/add.ts +24 -24
  184. package/src/queues/cli/commands/consumer/index.ts +3 -6
  185. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  186. package/src/queues/cli/commands/create.ts +8 -8
  187. package/src/queues/cli/commands/delete.ts +8 -8
  188. package/src/queues/cli/commands/index.ts +6 -4
  189. package/src/queues/cli/commands/list.ts +8 -8
  190. package/src/queues/client.ts +1 -0
  191. package/src/queues/utils.ts +18 -0
  192. package/src/r2/constants.ts +4 -0
  193. package/src/r2/helpers.ts +1 -0
  194. package/src/r2/index.ts +40 -28
  195. package/src/secret/index.ts +18 -17
  196. package/src/{sites.tsx → sites.ts} +165 -53
  197. package/src/tail/createTail.ts +103 -3
  198. package/src/tail/filters.ts +1 -1
  199. package/src/tail/index.ts +8 -11
  200. package/src/tail/printing.ts +27 -0
  201. package/src/traverse-module-graph.ts +54 -0
  202. package/src/tsconfig-sanity.ts +16 -0
  203. package/src/type-generation.ts +85 -57
  204. package/src/user/access.ts +0 -1
  205. package/src/user/auth-variables.ts +113 -0
  206. package/src/user/choose-account.tsx +1 -31
  207. package/src/user/index.ts +0 -1
  208. package/src/user/{user.tsx → user.ts} +124 -82
  209. package/src/utils/render.ts +93 -0
  210. package/src/{whoami.tsx → whoami.ts} +37 -71
  211. package/src/worker.ts +61 -3
  212. package/src/yargs-types.ts +22 -5
  213. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  214. package/templates/__tests__/tsconfig.json +8 -0
  215. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  216. package/templates/checked-fetch.js +9 -3
  217. package/templates/d1-beta-facade.js +95 -25
  218. package/templates/facade.d.ts +14 -0
  219. package/templates/first-party-worker-module-facade.ts +4 -3
  220. package/templates/format-dev-errors.ts +8 -6
  221. package/templates/gitignore +1 -0
  222. package/templates/init-tests/test-jest-new-worker.js +3 -5
  223. package/templates/init-tests/test-vitest-new-worker.js +3 -5
  224. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  225. package/templates/middleware/loader-modules.ts +2 -2
  226. package/templates/middleware/loader-sw.ts +51 -31
  227. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  228. package/templates/new-worker.ts +3 -0
  229. package/templates/pages-dev-pipeline.ts +4 -1
  230. package/templates/pages-dev-util.ts +4 -1
  231. package/templates/pages-shim.ts +4 -1
  232. package/templates/pages-template-plugin.ts +19 -10
  233. package/templates/serve-static-assets.ts +17 -14
  234. package/templates/service-bindings-module-facade.js +1 -0
  235. package/templates/tsconfig-sanity.ts +11 -0
  236. package/templates/tsconfig.init.json +105 -0
  237. package/templates/tsconfig.json +5 -103
  238. package/templates/tsconfig.tsbuildinfo +1 -0
  239. package/wrangler-dist/cli.d.ts +902 -77
  240. package/wrangler-dist/cli.js +131685 -140615
  241. package/wrangler-dist/wasm-sync.wasm +0 -0
  242. package/src/__tests__/api-devregistry.test.js +0 -57
  243. package/src/__tests__/d1.test.ts +0 -72
  244. package/src/__tests__/dialogs.test.tsx +0 -40
  245. package/src/__tests__/helpers/mock-cfetch.ts +0 -333
  246. package/src/__tests__/pages.test.ts +0 -2223
  247. package/src/d1/types.tsx +0 -14
  248. package/src/dialogs.tsx +0 -163
  249. package/src/environment-variables.ts +0 -50
  250. package/src/pages/build.tsx +0 -238
  251. package/src/user/env-vars.ts +0 -46
  252. package/templates/experimental-local-cache-stubs.js +0 -27
  253. /package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
  254. /package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
  255. /package/src/pages/{hash.tsx → hash.ts} +0 -0
@@ -2,23 +2,16 @@ import * as fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import * as TOML from "@iarna/toml";
4
4
  import { execa, execaSync } from "execa";
5
+ import { rest } from "msw";
5
6
  import { parseConfigFileTextToJson } from "typescript";
7
+ import { FormData } from "undici";
6
8
  import { version as wranglerVersion } from "../../package.json";
7
9
  import { getPackageManager } from "../package-manager";
8
10
  import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
9
- import {
10
- setMockFetchDashScript,
11
- setMockResponse,
12
- unsetAllMocks,
13
- unsetSpecialMockFns,
14
- } from "./helpers/mock-cfetch";
15
11
  import { mockConsoleMethods } from "./helpers/mock-console";
16
- import {
17
- mockConfirm,
18
- clearConfirmMocks,
19
- mockSelect,
20
- clearSelectMocks,
21
- } from "./helpers/mock-dialogs";
12
+ import { clearDialogs, mockConfirm, mockSelect } from "./helpers/mock-dialogs";
13
+ import { useMockIsTTY } from "./helpers/mock-istty";
14
+ import { msw } from "./helpers/msw";
22
15
  import { runInTempDir } from "./helpers/run-in-tmp";
23
16
  import { runWrangler } from "./helpers/run-wrangler";
24
17
  import type { PackageManager } from "../package-manager";
@@ -35,8 +28,11 @@ const MINIMAL_WRANGLER_TOML = {
35
28
  describe("init", () => {
36
29
  let mockPackageManager: PackageManager;
37
30
  runInTempDir();
31
+ const { setIsTTY } = useMockIsTTY();
38
32
 
39
33
  beforeEach(() => {
34
+ setIsTTY(true);
35
+
40
36
  mockPackageManager = {
41
37
  cwd: process.cwd(),
42
38
  // @ts-expect-error we're making a fake package manager here
@@ -48,8 +44,7 @@ describe("init", () => {
48
44
  });
49
45
 
50
46
  afterEach(() => {
51
- clearConfirmMocks();
52
- clearSelectMocks();
47
+ clearDialogs();
53
48
  });
54
49
 
55
50
  const std = mockConsoleMethods();
@@ -69,16 +64,18 @@ describe("init", () => {
69
64
  });
70
65
 
71
66
  expect(std.out).toMatchInlineSnapshot(`
72
- "✨ Created wrangler.toml
73
- ✨ Initialized git repository
74
- ✨ Created package.json
75
- ✨ Created tsconfig.json
76
- ✨ Created src/index.ts
77
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
67
+ "✨ Created wrangler.toml
68
+ ✨ Initialized git repository
69
+ ✨ Created package.json
70
+ ✨ Created tsconfig.json
71
+ ✨ Created src/index.ts
72
+ ✨ Created src/index.test.ts
73
+ ✨ Installed @cloudflare/workers-types, typescript, and vitest into devDependencies
78
74
 
79
- To start developing your Worker, run \`npm start\`
80
- To publish your Worker to the Internet, run \`npm run deploy\`"
81
- `);
75
+ To start developing your Worker, run \`npm start\`
76
+ To start testing your Worker, run \`npm test\`
77
+ To publish your Worker to the Internet, run \`npm run deploy\`"
78
+ `);
82
79
  expect(std.err).toMatchInlineSnapshot(`""`);
83
80
  expect(std.warn).toMatchInlineSnapshot(`""`);
84
81
  });
@@ -100,16 +97,18 @@ describe("init", () => {
100
97
  });
101
98
 
102
99
  expect(std.out).toMatchInlineSnapshot(`
103
- "✨ Created my-worker/wrangler.toml
104
- ✨ Initialized git repository at my-worker
105
- ✨ Created my-worker/package.json
106
- ✨ Created my-worker/tsconfig.json
107
- ✨ Created my-worker/src/index.ts
108
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
109
-
110
- To start developing your Worker, run \`cd my-worker && npm start\`
111
- To publish your Worker to the Internet, run \`npm run deploy\`"
112
- `);
100
+ "✨ Created my-worker/wrangler.toml
101
+ ✨ Initialized git repository at my-worker
102
+ ✨ Created my-worker/package.json
103
+ ✨ Created my-worker/tsconfig.json
104
+ ✨ Created my-worker/src/index.ts
105
+ ✨ Created my-worker/src/index.test.ts
106
+ ✨ Installed @cloudflare/workers-types, typescript, and vitest into devDependencies
107
+
108
+ To start developing your Worker, run \`cd my-worker && npm start\`
109
+ To start testing your Worker, run \`npm test\`
110
+ To publish your Worker to the Internet, run \`npm run deploy\`"
111
+ `);
113
112
  expect(std.err).toMatchInlineSnapshot(`""`);
114
113
  expect(std.warn).toMatchInlineSnapshot(`""`);
115
114
  });
@@ -128,21 +127,24 @@ describe("init", () => {
128
127
  });
129
128
 
130
129
  expect(std).toMatchInlineSnapshot(`
131
- Object {
132
- "debug": "",
133
- "err": "",
134
- "out": "✨ Created wrangler.toml
135
- ✨ Initialized git repository
136
- ✨ Created package.json
137
- ✨ Created tsconfig.json
138
- ✨ Created src/index.ts
139
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
130
+ Object {
131
+ "debug": "",
132
+ "err": "",
133
+ "info": "Your project will use Vitest to run your tests.",
134
+ "out": "✨ Created wrangler.toml
135
+ ✨ Initialized git repository
136
+ ✨ Created package.json
137
+ ✨ Created tsconfig.json
138
+ ✨ Created src/index.ts
139
+ ✨ Created src/index.test.ts
140
+ ✨ Installed @cloudflare/workers-types, typescript, and vitest into devDependencies
140
141
 
141
- To start developing your Worker, run \`npm start\`
142
- To publish your Worker to the Internet, run \`npm run deploy\`",
143
- "warn": "",
144
- }
145
- `);
142
+ To start developing your Worker, run \`npm start\`
143
+ To start testing your Worker, run \`npm test\`
144
+ To publish your Worker to the Internet, run \`npm run deploy\`",
145
+ "warn": "",
146
+ }
147
+ `);
146
148
  });
147
149
 
148
150
  it("should error if `--type javascript` is used", async () => {
@@ -211,13 +213,14 @@ describe("init", () => {
211
213
  });
212
214
 
213
215
  expect(std).toMatchInlineSnapshot(`
214
- Object {
215
- "debug": "",
216
- "err": "",
217
- "out": "✨ Created wrangler.toml",
218
- "warn": "",
219
- }
220
- `);
216
+ Object {
217
+ "debug": "",
218
+ "err": "",
219
+ "info": "",
220
+ "out": "✨ Created wrangler.toml",
221
+ "warn": "",
222
+ }
223
+ `);
221
224
  });
222
225
 
223
226
  it("should create a wrangler.toml and a directory for a named Worker ", async () => {
@@ -245,13 +248,14 @@ describe("init", () => {
245
248
  });
246
249
 
247
250
  expect(std).toMatchInlineSnapshot(`
248
- Object {
249
- "debug": "",
250
- "err": "",
251
- "out": "✨ Created my-worker/wrangler.toml",
252
- "warn": "",
253
- }
254
- `);
251
+ Object {
252
+ "debug": "",
253
+ "err": "",
254
+ "info": "",
255
+ "out": "✨ Created my-worker/wrangler.toml",
256
+ "warn": "",
257
+ }
258
+ `);
255
259
  });
256
260
 
257
261
  it("should display warning when wrangler.toml already exists, and exit if user does not want to carry on", async () => {
@@ -283,15 +287,16 @@ describe("init", () => {
283
287
  });
284
288
 
285
289
  expect(std).toMatchInlineSnapshot(`
286
- Object {
287
- "debug": "",
288
- "err": "",
289
- "out": "",
290
- "warn": "▲ [WARNING] wrangler.toml already exists!
291
-
292
- ",
293
- }
294
- `);
290
+ Object {
291
+ "debug": "",
292
+ "err": "",
293
+ "info": "",
294
+ "out": "",
295
+ "warn": "▲ [WARNING] wrangler.toml already exists!
296
+
297
+ ",
298
+ }
299
+ `);
295
300
  });
296
301
 
297
302
  it("should display warning when wrangler.toml already exists in the target directory, and exit if user does not want to carry on", async () => {
@@ -320,15 +325,16 @@ describe("init", () => {
320
325
  },
321
326
  });
322
327
  expect(std).toMatchInlineSnapshot(`
323
- Object {
324
- "debug": "",
325
- "err": "",
326
- "out": "",
327
- "warn": "▲ [WARNING] path/to/worker/wrangler.toml already exists!
328
-
329
- ",
330
- }
331
- `);
328
+ Object {
329
+ "debug": "",
330
+ "err": "",
331
+ "info": "",
332
+ "out": "",
333
+ "warn": "▲ [WARNING] path/to/worker/wrangler.toml already exists!
334
+
335
+ ",
336
+ }
337
+ `);
332
338
  });
333
339
 
334
340
  it("should not overwrite an existing wrangler.toml, after agreeing to other prompts", async () => {
@@ -341,11 +347,11 @@ describe("init", () => {
341
347
  });
342
348
  mockConfirm(
343
349
  {
344
- text: "Would you like to use git to manage this Worker?",
350
+ text: "Do you want to continue initializing this project?",
345
351
  result: true,
346
352
  },
347
353
  {
348
- text: "Do you want to continue initializing this project?",
354
+ text: "Would you like to use git to manage this Worker?",
349
355
  result: true,
350
356
  },
351
357
  {
@@ -359,9 +365,16 @@ describe("init", () => {
359
365
  );
360
366
 
361
367
  mockSelect({
362
- text: "Would you like to create a Worker at src/index.ts?",
368
+ text: `Would you like to create a Worker at ${path.join(
369
+ "src",
370
+ "index.ts"
371
+ )}?`,
363
372
  result: "fetch",
364
373
  });
374
+ mockConfirm({
375
+ text: "Would you like us to write your first test with Vitest?",
376
+ result: true,
377
+ });
365
378
 
366
379
  await runWrangler("init");
367
380
 
@@ -408,15 +421,16 @@ describe("init", () => {
408
421
  },
409
422
  });
410
423
  expect(std).toMatchInlineSnapshot(`
411
- Object {
412
- "debug": "",
413
- "err": "",
414
- "out": "",
415
- "warn": "▲ [WARNING] wrangler.toml already exists!
416
-
417
- ",
418
- }
419
- `);
424
+ Object {
425
+ "debug": "",
426
+ "err": "",
427
+ "info": "",
428
+ "out": "",
429
+ "warn": "▲ [WARNING] wrangler.toml already exists!
430
+
431
+ ",
432
+ }
433
+ `);
420
434
  });
421
435
 
422
436
  it("should not add a Cron Trigger to wrangler.toml when creating a Scheduled Worker if wrangler.toml already exists", async () => {
@@ -429,13 +443,14 @@ describe("init", () => {
429
443
  });
430
444
  mockConfirm(
431
445
  {
432
- text: "Would you like to use git to manage this Worker?",
446
+ text: "Do you want to continue initializing this project?",
433
447
  result: true,
434
448
  },
435
449
  {
436
- text: "Do you want to continue initializing this project?",
450
+ text: "Would you like to use git to manage this Worker?",
437
451
  result: true,
438
452
  },
453
+
439
454
  {
440
455
  text: "No package.json found. Would you like to create one?",
441
456
  result: true,
@@ -446,10 +461,17 @@ describe("init", () => {
446
461
  }
447
462
  );
448
463
  mockSelect({
449
- text: "Would you like to create a Worker at src/index.ts?",
464
+ text: `Would you like to create a Worker at ${path.join(
465
+ "src",
466
+ "index.ts"
467
+ )}?`,
450
468
  result: "scheduled",
451
469
  });
452
470
 
471
+ mockConfirm({
472
+ text: "Would you like us to write your first test with Vitest?",
473
+ result: true,
474
+ });
453
475
  await runWrangler("init");
454
476
 
455
477
  checkFiles({
@@ -477,10 +499,16 @@ describe("init", () => {
477
499
  }
478
500
  );
479
501
  mockSelect({
480
- text: "Would you like to create a Worker at src/index.ts?",
502
+ text: `Would you like to create a Worker at ${path.join(
503
+ "src",
504
+ "index.ts"
505
+ )}?`,
481
506
  result: "scheduled",
482
507
  });
483
-
508
+ mockConfirm({
509
+ text: "Would you like us to write your first test with Vitest?",
510
+ result: true,
511
+ });
484
512
  await runWrangler("init");
485
513
 
486
514
  checkFiles({
@@ -520,16 +548,17 @@ describe("init", () => {
520
548
  },
521
549
  });
522
550
  expect(std).toMatchInlineSnapshot(`
523
- Object {
524
- "debug": "",
525
- "err": "",
526
- "out": "✨ Created wrangler.toml
527
- ✨ Initialized git repository",
528
- "warn": "",
529
- }
530
- `);
551
+ Object {
552
+ "debug": "",
553
+ "err": "",
554
+ "info": "",
555
+ "out": "✨ Created wrangler.toml
556
+ ✨ Initialized git repository",
557
+ "warn": "",
558
+ }
559
+ `);
531
560
  expect((await execa("git", ["branch", "--show-current"])).stdout).toEqual(
532
- "main"
561
+ getDefaultBranchName()
533
562
  );
534
563
  });
535
564
 
@@ -552,20 +581,23 @@ describe("init", () => {
552
581
 
553
582
  // Note the lack of "✨ Initialized git repository" in the log
554
583
  expect(std).toMatchInlineSnapshot(`
555
- Object {
556
- "debug": "",
557
- "err": "",
558
- "out": "✨ Created wrangler.toml
559
- ✨ Created package.json
560
- ✨ Created tsconfig.json
561
- ✨ Created src/index.ts
562
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
584
+ Object {
585
+ "debug": "",
586
+ "err": "",
587
+ "info": "Your project will use Vitest to run your tests.",
588
+ "out": "✨ Created wrangler.toml
589
+ ✨ Created package.json
590
+ ✨ Created tsconfig.json
591
+ ✨ Created src/index.ts
592
+ ✨ Created src/index.test.ts
593
+ ✨ Installed @cloudflare/workers-types, typescript, and vitest into devDependencies
563
594
 
564
- To start developing your Worker, run \`npm start\`
565
- To publish your Worker to the Internet, run \`npm run deploy\`",
566
- "warn": "",
567
- }
568
- `);
595
+ To start developing your Worker, run \`npm start\`
596
+ To start testing your Worker, run \`npm test\`
597
+ To publish your Worker to the Internet, run \`npm run deploy\`",
598
+ "warn": "",
599
+ }
600
+ `);
569
601
  });
570
602
 
571
603
  it("should not offer to initialize a git repo if it's already inside one (when using a path as name)", async () => {
@@ -577,20 +609,23 @@ describe("init", () => {
577
609
 
578
610
  // Note the lack of "✨ Initialized git repository" in the log
579
611
  expect(std).toMatchInlineSnapshot(`
580
- Object {
581
- "debug": "",
582
- "err": "",
583
- "out": "✨ Created path/to/worker/my-worker/wrangler.toml
584
- ✨ Created path/to/worker/my-worker/package.json
585
- ✨ Created path/to/worker/my-worker/tsconfig.json
586
- ✨ Created path/to/worker/my-worker/src/index.ts
587
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
588
-
589
- To start developing your Worker, run \`cd path/to/worker/my-worker && npm start\`
590
- To publish your Worker to the Internet, run \`npm run deploy\`",
591
- "warn": "",
592
- }
593
- `);
612
+ Object {
613
+ "debug": "",
614
+ "err": "",
615
+ "info": "Your project will use Vitest to run your tests.",
616
+ "out": "✨ Created path/to/worker/my-worker/wrangler.toml
617
+ ✨ Created path/to/worker/my-worker/package.json
618
+ ✨ Created path/to/worker/my-worker/tsconfig.json
619
+ ✨ Created path/to/worker/my-worker/src/index.ts
620
+ ✨ Created path/to/worker/my-worker/src/index.test.ts
621
+ ✨ Installed @cloudflare/workers-types, typescript, and vitest into devDependencies
622
+
623
+ To start developing your Worker, run \`cd path/to/worker/my-worker && npm start\`
624
+ To start testing your Worker, run \`npm test\`
625
+ To publish your Worker to the Internet, run \`npm run deploy\`",
626
+ "warn": "",
627
+ }
628
+ `);
594
629
  });
595
630
 
596
631
  // I... don't know how to test this lol
@@ -598,7 +633,7 @@ describe("init", () => {
598
633
  "should not offer to initialize a git repo if git is not installed"
599
634
  );
600
635
 
601
- it("should initialize git repo with `main` default branch", async () => {
636
+ it("should initialize git repo with the user's default branch", async () => {
602
637
  mockConfirm(
603
638
  {
604
639
  text: "Would you like to use git to manage this Worker?",
@@ -611,17 +646,18 @@ describe("init", () => {
611
646
  );
612
647
  await runWrangler("init");
613
648
  expect(std).toMatchInlineSnapshot(`
614
- Object {
615
- "debug": "",
616
- "err": "",
617
- "out": "✨ Created wrangler.toml
618
- ✨ Initialized git repository",
619
- "warn": "",
620
- }
621
- `);
649
+ Object {
650
+ "debug": "",
651
+ "err": "",
652
+ "info": "",
653
+ "out": "✨ Created wrangler.toml
654
+ ✨ Initialized git repository",
655
+ "warn": "",
656
+ }
657
+ `);
622
658
 
623
659
  expect(execaSync("git", ["symbolic-ref", "HEAD"]).stdout).toEqual(
624
- "refs/heads/main"
660
+ `refs/heads/${getDefaultBranchName()}`
625
661
  );
626
662
  });
627
663
  });
@@ -643,7 +679,10 @@ describe("init", () => {
643
679
  }
644
680
  );
645
681
  mockSelect({
646
- text: "Would you like to create a Worker at src/index.js?",
682
+ text: `Would you like to create a Worker at ${path.join(
683
+ "src",
684
+ "index.js"
685
+ )}?`,
647
686
  result: "none",
648
687
  });
649
688
 
@@ -665,14 +704,15 @@ describe("init", () => {
665
704
  });
666
705
  expect(mockPackageManager.install).toHaveBeenCalled();
667
706
  expect(std).toMatchInlineSnapshot(`
668
- Object {
669
- "debug": "",
670
- "err": "",
671
- "out": "✨ Created wrangler.toml
672
- ✨ Created package.json",
673
- "warn": "",
674
- }
675
- `);
707
+ Object {
708
+ "debug": "",
709
+ "err": "",
710
+ "info": "",
711
+ "out": "✨ Created wrangler.toml
712
+ ✨ Created package.json",
713
+ "warn": "",
714
+ }
715
+ `);
676
716
  });
677
717
 
678
718
  it("should create a package.json, with the specified name, if none is found and user confirms", async () => {
@@ -691,7 +731,11 @@ describe("init", () => {
691
731
  }
692
732
  );
693
733
  mockSelect({
694
- text: "Would you like to create a Worker at my-worker/src/index.js?",
734
+ text: `Would you like to create a Worker at ${path.join(
735
+ "my-worker",
736
+ "src",
737
+ "index.js"
738
+ )}?`,
695
739
  result: "none",
696
740
  });
697
741
 
@@ -712,14 +756,15 @@ describe("init", () => {
712
756
  },
713
757
  });
714
758
  expect(std).toMatchInlineSnapshot(`
715
- Object {
716
- "debug": "",
717
- "err": "",
718
- "out": "✨ Created my-worker/wrangler.toml
719
- ✨ Created my-worker/package.json",
720
- "warn": "",
721
- }
722
- `);
759
+ Object {
760
+ "debug": "",
761
+ "err": "",
762
+ "info": "",
763
+ "out": "✨ Created my-worker/wrangler.toml
764
+ ✨ Created my-worker/package.json",
765
+ "warn": "",
766
+ }
767
+ `);
723
768
  });
724
769
 
725
770
  it("should not touch an existing package.json in the same directory", async () => {
@@ -738,7 +783,10 @@ describe("init", () => {
738
783
  }
739
784
  );
740
785
  mockSelect({
741
- text: "Would you like to create a Worker at src/index.js?",
786
+ text: `Would you like to create a Worker at ${path.join(
787
+ "src",
788
+ "index.js"
789
+ )}?`,
742
790
  result: "none",
743
791
  });
744
792
  writeFiles({
@@ -755,13 +803,14 @@ describe("init", () => {
755
803
  },
756
804
  });
757
805
  expect(std).toMatchInlineSnapshot(`
758
- Object {
759
- "debug": "",
760
- "err": "",
761
- "out": "✨ Created wrangler.toml",
762
- "warn": "",
763
- }
764
- `);
806
+ Object {
807
+ "debug": "",
808
+ "err": "",
809
+ "info": "",
810
+ "out": "✨ Created wrangler.toml",
811
+ "warn": "",
812
+ }
813
+ `);
765
814
  });
766
815
 
767
816
  it("should not touch an existing package.json in an ancestor directory, when a name is passed", async () => {
@@ -774,17 +823,20 @@ describe("init", () => {
774
823
  text: "No package.json found. Would you like to create one?",
775
824
  result: true,
776
825
  },
777
- {
778
- text: "Would you like to install wrangler into path/to/worker/my-worker/package.json?",
779
- result: false,
780
- },
781
826
  {
782
827
  text: "Would you like to use TypeScript?",
783
828
  result: false,
784
829
  }
785
830
  );
786
831
  mockSelect({
787
- text: "Would you like to create a Worker at path/to/worker/my-worker/src/index.js?",
832
+ text: `Would you like to create a Worker at ${path.join(
833
+ "path",
834
+ "to",
835
+ "worker",
836
+ "my-worker",
837
+ "src",
838
+ "index.js"
839
+ )}?`,
788
840
  result: "none",
789
841
  });
790
842
  writeFiles({
@@ -805,14 +857,15 @@ describe("init", () => {
805
857
  },
806
858
  });
807
859
  expect(std).toMatchInlineSnapshot(`
808
- Object {
809
- "debug": "",
810
- "err": "",
811
- "out": "✨ Created path/to/worker/my-worker/wrangler.toml
812
- ✨ Created path/to/worker/my-worker/package.json",
813
- "warn": "",
814
- }
815
- `);
860
+ Object {
861
+ "debug": "",
862
+ "err": "",
863
+ "info": "",
864
+ "out": "✨ Created path/to/worker/my-worker/wrangler.toml
865
+ ✨ Created path/to/worker/my-worker/package.json",
866
+ "warn": "",
867
+ }
868
+ `);
816
869
  });
817
870
 
818
871
  it("should offer to install wrangler into an existing package.json", async () => {
@@ -831,7 +884,10 @@ describe("init", () => {
831
884
  }
832
885
  );
833
886
  mockSelect({
834
- text: "Would you like to create a Worker at src/index.js?",
887
+ text: `Would you like to create a Worker at ${path.join(
888
+ "src",
889
+ "index.js"
890
+ )}?`,
835
891
  result: "none",
836
892
  });
837
893
  writeFiles({
@@ -855,14 +911,15 @@ describe("init", () => {
855
911
  `wrangler@${wranglerVersion}`
856
912
  );
857
913
  expect(std).toMatchInlineSnapshot(`
858
- Object {
859
- "debug": "",
860
- "err": "",
861
- "out": "✨ Created wrangler.toml
862
- ✨ Installed wrangler into devDependencies",
863
- "warn": "",
864
- }
865
- `);
914
+ Object {
915
+ "debug": "",
916
+ "err": "",
917
+ "info": "",
918
+ "out": "✨ Created wrangler.toml
919
+ ✨ Installed wrangler into devDependencies",
920
+ "warn": "",
921
+ }
922
+ `);
866
923
  });
867
924
 
868
925
  it("should offer to install wrangler into a package.json relative to the target directory, if no name is provided", async () => {
@@ -872,7 +929,10 @@ describe("init", () => {
872
929
  result: false,
873
930
  },
874
931
  {
875
- text: "Would you like to install wrangler into ../package.json?",
932
+ text: `Would you like to install wrangler into ${path.join(
933
+ "..",
934
+ "package.json"
935
+ )}?`,
876
936
  result: true,
877
937
  },
878
938
  {
@@ -881,7 +941,10 @@ describe("init", () => {
881
941
  }
882
942
  );
883
943
  mockSelect({
884
- text: "Would you like to create a Worker at src/index.js?",
944
+ text: `Would you like to create a Worker at ${path.join(
945
+ "src",
946
+ "index.js"
947
+ )}?`,
885
948
  result: "none",
886
949
  });
887
950
  writeFiles({
@@ -909,14 +972,15 @@ describe("init", () => {
909
972
  );
910
973
  expect(mockPackageManager.cwd).toBe(process.cwd());
911
974
  expect(std).toMatchInlineSnapshot(`
912
- Object {
913
- "debug": "",
914
- "err": "",
915
- "out": "✨ Created wrangler.toml
916
- ✨ Installed wrangler into devDependencies",
917
- "warn": "",
918
- }
919
- `);
975
+ Object {
976
+ "debug": "",
977
+ "err": "",
978
+ "info": "",
979
+ "out": "✨ Created wrangler.toml
980
+ ✨ Installed wrangler into devDependencies",
981
+ "warn": "",
982
+ }
983
+ `);
920
984
  });
921
985
 
922
986
  it("should not touch an existing package.json in an ancestor directory", async () => {
@@ -926,7 +990,11 @@ describe("init", () => {
926
990
  result: false,
927
991
  },
928
992
  {
929
- text: "Would you like to install wrangler into ../../package.json?",
993
+ text: `Would you like to install wrangler into ${path.join(
994
+ "..",
995
+ "..",
996
+ "package.json"
997
+ )}?`,
930
998
  result: false,
931
999
  },
932
1000
  {
@@ -935,7 +1003,10 @@ describe("init", () => {
935
1003
  }
936
1004
  );
937
1005
  mockSelect({
938
- text: "Would you like to create a Worker at src/index.js?",
1006
+ text: `Would you like to create a Worker at ${path.join(
1007
+ "src",
1008
+ "index.js"
1009
+ )}?`,
939
1010
  result: "none",
940
1011
  });
941
1012
  writeFiles({
@@ -958,13 +1029,14 @@ describe("init", () => {
958
1029
  },
959
1030
  });
960
1031
  expect(std).toMatchInlineSnapshot(`
961
- Object {
962
- "debug": "",
963
- "err": "",
964
- "out": "✨ Created wrangler.toml",
965
- "warn": "",
966
- }
967
- `);
1032
+ Object {
1033
+ "debug": "",
1034
+ "err": "",
1035
+ "info": "",
1036
+ "out": "✨ Created wrangler.toml",
1037
+ "warn": "",
1038
+ }
1039
+ `);
968
1040
  });
969
1041
  });
970
1042
 
@@ -982,13 +1054,19 @@ describe("init", () => {
982
1054
  {
983
1055
  text: "Would you like to use TypeScript?",
984
1056
  result: false,
985
- },
986
- { text: "Would you like us to write your first test?", result: false }
1057
+ }
987
1058
  );
988
1059
  mockSelect({
989
- text: "Would you like to create a Worker at src/index.js?",
1060
+ text: `Would you like to create a Worker at ${path.join(
1061
+ "src",
1062
+ "index.js"
1063
+ )}?`,
990
1064
  result: "fetch",
991
1065
  });
1066
+ mockConfirm({
1067
+ text: "Would you like us to write your first test?",
1068
+ result: false,
1069
+ });
992
1070
  writeFiles({
993
1071
  items: {
994
1072
  "package.json": {
@@ -1010,17 +1088,18 @@ describe("init", () => {
1010
1088
  },
1011
1089
  });
1012
1090
  expect(std).toMatchInlineSnapshot(`
1013
- Object {
1014
- "debug": "",
1015
- "err": "",
1016
- "out": "✨ Created wrangler.toml
1017
- ✨ Created src/index.js
1091
+ Object {
1092
+ "debug": "",
1093
+ "err": "",
1094
+ "info": "",
1095
+ "out": "✨ Created wrangler.toml
1096
+ ✨ Created src/index.js
1018
1097
 
1019
- To start developing your Worker, run \`npx wrangler dev\`
1020
- To publish your Worker to the Internet, run \`npx wrangler publish\`",
1021
- "warn": "",
1022
- }
1023
- `);
1098
+ To start developing your Worker, run \`npx wrangler dev\`
1099
+ To publish your Worker to the Internet, run \`npx wrangler publish\`",
1100
+ "warn": "",
1101
+ }
1102
+ `);
1024
1103
  });
1025
1104
 
1026
1105
  it("should offer to create a worker in a typescript project", async () => {
@@ -1039,9 +1118,16 @@ describe("init", () => {
1039
1118
  }
1040
1119
  );
1041
1120
  mockSelect({
1042
- text: "Would you like to create a Worker at src/index.ts?",
1121
+ text: `Would you like to create a Worker at ${path.join(
1122
+ "src",
1123
+ "index.ts"
1124
+ )}?`,
1043
1125
  result: "fetch",
1044
1126
  });
1127
+ mockConfirm({
1128
+ text: "Would you like us to write your first test with Vitest?",
1129
+ result: true,
1130
+ });
1045
1131
  writeFiles({
1046
1132
  items: {
1047
1133
  "package.json": {
@@ -1059,19 +1145,21 @@ describe("init", () => {
1059
1145
  },
1060
1146
  });
1061
1147
  expect(std).toMatchInlineSnapshot(`
1062
- Object {
1063
- "debug": "",
1064
- "err": "",
1065
- "out": "✨ Created wrangler.toml
1066
- ✨ Created tsconfig.json
1067
- ✨ Created src/index.ts
1068
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1069
-
1070
- To start developing your Worker, run \`npx wrangler dev\`
1071
- To publish your Worker to the Internet, run \`npx wrangler publish\`",
1072
- "warn": "",
1073
- }
1074
- `);
1148
+ Object {
1149
+ "debug": "",
1150
+ "err": "",
1151
+ "info": "",
1152
+ "out": "✨ Created wrangler.toml
1153
+ ✨ Created tsconfig.json
1154
+ ✨ Created src/index.ts
1155
+ ✨ Created src/index.test.ts
1156
+ ✨ Installed @cloudflare/workers-types, typescript, and vitest into devDependencies
1157
+
1158
+ To start developing your Worker, run \`npx wrangler dev\`
1159
+ To publish your Worker to the Internet, run \`npx wrangler publish\`",
1160
+ "warn": "",
1161
+ }
1162
+ `);
1075
1163
  });
1076
1164
 
1077
1165
  it("should add scripts for a typescript project with .ts extension", async () => {
@@ -1084,19 +1172,23 @@ describe("init", () => {
1084
1172
  text: "No package.json found. Would you like to create one?",
1085
1173
  result: true,
1086
1174
  },
1087
- {
1088
- text: "Would you like to install wrangler into package.json?",
1089
- result: false,
1090
- },
1175
+
1091
1176
  {
1092
1177
  text: "Would you like to use TypeScript?",
1093
1178
  result: true,
1094
1179
  }
1095
1180
  );
1096
1181
  mockSelect({
1097
- text: "Would you like to create a Worker at src/index.ts?",
1182
+ text: `Would you like to create a Worker at ${path.join(
1183
+ "src",
1184
+ "index.ts"
1185
+ )}?`,
1098
1186
  result: "fetch",
1099
1187
  });
1188
+ mockConfirm({
1189
+ text: "Would you like us to write your first test with Vitest?",
1190
+ result: true,
1191
+ });
1100
1192
 
1101
1193
  await runWrangler("init");
1102
1194
 
@@ -1107,8 +1199,12 @@ describe("init", () => {
1107
1199
  name: expect.stringContaining("wrangler-tests"),
1108
1200
  version: "0.0.0",
1109
1201
  scripts: {
1110
- start: "wrangler dev",
1111
1202
  deploy: "wrangler publish",
1203
+ start: "wrangler dev",
1204
+ test: "vitest",
1205
+ },
1206
+ devDependencies: {
1207
+ wrangler: expect.any(String),
1112
1208
  },
1113
1209
  }),
1114
1210
  },
@@ -1117,15 +1213,17 @@ describe("init", () => {
1117
1213
  },
1118
1214
  });
1119
1215
  expect(std.out).toMatchInlineSnapshot(`
1120
- "✨ Created wrangler.toml
1121
- ✨ Created package.json
1122
- ✨ Created tsconfig.json
1123
- ✨ Created src/index.ts
1124
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1216
+ "✨ Created wrangler.toml
1217
+ ✨ Created package.json
1218
+ ✨ Created tsconfig.json
1219
+ ✨ Created src/index.ts
1220
+ ✨ Created src/index.test.ts
1221
+ ✨ Installed @cloudflare/workers-types, typescript, and vitest into devDependencies
1125
1222
 
1126
- To start developing your Worker, run \`npm start\`
1127
- To publish your Worker to the Internet, run \`npm run deploy\`"
1128
- `);
1223
+ To start developing your Worker, run \`npm start\`
1224
+ To start testing your Worker, run \`npm test\`
1225
+ To publish your Worker to the Internet, run \`npm run deploy\`"
1226
+ `);
1129
1227
  });
1130
1228
 
1131
1229
  it("should not overwrite package.json scripts for a typescript project", async () => {
@@ -1144,9 +1242,16 @@ describe("init", () => {
1144
1242
  }
1145
1243
  );
1146
1244
  mockSelect({
1147
- text: "Would you like to create a Worker at src/index.ts?",
1245
+ text: `Would you like to create a Worker at ${path.join(
1246
+ "src",
1247
+ "index.ts"
1248
+ )}?`,
1148
1249
  result: "fetch",
1149
1250
  });
1251
+ mockConfirm({
1252
+ text: "Would you like us to write your first test with Vitest?",
1253
+ result: true,
1254
+ });
1150
1255
  writeFiles({
1151
1256
  items: {
1152
1257
  "package.json": {
@@ -1177,14 +1282,15 @@ describe("init", () => {
1177
1282
  },
1178
1283
  });
1179
1284
  expect(std.out).toMatchInlineSnapshot(`
1180
- "✨ Created wrangler.toml
1181
- ✨ Created tsconfig.json
1182
- ✨ Created src/index.ts
1183
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1285
+ "✨ Created wrangler.toml
1286
+ ✨ Created tsconfig.json
1287
+ ✨ Created src/index.ts
1288
+ ✨ Created src/index.test.ts
1289
+ ✨ Installed @cloudflare/workers-types, typescript, and vitest into devDependencies
1184
1290
 
1185
- To start developing your Worker, run \`npx wrangler dev\`
1186
- To publish your Worker to the Internet, run \`npx wrangler publish\`"
1187
- `);
1291
+ To start developing your Worker, run \`npx wrangler dev\`
1292
+ To publish your Worker to the Internet, run \`npx wrangler publish\`"
1293
+ `);
1188
1294
  });
1189
1295
 
1190
1296
  it("should not offer to create a worker in a ts project if a file already exists at the location", async () => {
@@ -1219,15 +1325,16 @@ describe("init", () => {
1219
1325
  },
1220
1326
  });
1221
1327
  expect(std).toMatchInlineSnapshot(`
1222
- Object {
1223
- "debug": "",
1224
- "err": "",
1225
- "out": "✨ Created wrangler.toml
1226
- ✨ Created tsconfig.json
1227
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies",
1228
- "warn": "",
1229
- }
1230
- `);
1328
+ Object {
1329
+ "debug": "",
1330
+ "err": "",
1331
+ "info": "",
1332
+ "out": "✨ Created wrangler.toml
1333
+ ✨ Created tsconfig.json
1334
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies",
1335
+ "warn": "",
1336
+ }
1337
+ `);
1231
1338
  });
1232
1339
 
1233
1340
  it("should not offer to create a worker in a ts project for a named worker if a file already exists at the location", async () => {
@@ -1240,10 +1347,7 @@ describe("init", () => {
1240
1347
  text: "No package.json found. Would you like to create one?",
1241
1348
  result: true,
1242
1349
  },
1243
- {
1244
- text: "Would you like to install wrangler into package.json?",
1245
- result: false,
1246
- },
1350
+
1247
1351
  {
1248
1352
  text: "Would you like to use TypeScript?",
1249
1353
  result: true,
@@ -1266,16 +1370,17 @@ describe("init", () => {
1266
1370
  },
1267
1371
  });
1268
1372
  expect(std).toMatchInlineSnapshot(`
1269
- Object {
1270
- "debug": "",
1271
- "err": "",
1272
- "out": "✨ Created my-worker/wrangler.toml
1273
- ✨ Created my-worker/package.json
1274
- ✨ Created my-worker/tsconfig.json
1275
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies",
1276
- "warn": "",
1277
- }
1278
- `);
1373
+ Object {
1374
+ "debug": "",
1375
+ "err": "",
1376
+ "info": "",
1377
+ "out": "✨ Created my-worker/wrangler.toml
1378
+ ✨ Created my-worker/package.json
1379
+ ✨ Created my-worker/tsconfig.json
1380
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies",
1381
+ "warn": "",
1382
+ }
1383
+ `);
1279
1384
  });
1280
1385
 
1281
1386
  it("should create a tsconfig.json and install `workers-types` if none is found and user confirms", async () => {
@@ -1294,7 +1399,10 @@ describe("init", () => {
1294
1399
  }
1295
1400
  );
1296
1401
  mockSelect({
1297
- text: "Would you like to create a Worker at src/index.ts?",
1402
+ text: `Would you like to create a Worker at ${path.join(
1403
+ "src",
1404
+ "index.ts"
1405
+ )}?`,
1298
1406
  result: "none",
1299
1407
  });
1300
1408
 
@@ -1306,7 +1414,7 @@ describe("init", () => {
1306
1414
  contents: {
1307
1415
  config: {
1308
1416
  compilerOptions: expect.objectContaining({
1309
- types: ["@cloudflare/workers-types", "jest"],
1417
+ types: ["@cloudflare/workers-types"],
1310
1418
  }),
1311
1419
  },
1312
1420
  error: undefined,
@@ -1319,16 +1427,17 @@ describe("init", () => {
1319
1427
  "typescript"
1320
1428
  );
1321
1429
  expect(std).toMatchInlineSnapshot(`
1322
- Object {
1323
- "debug": "",
1324
- "err": "",
1325
- "out": "✨ Created wrangler.toml
1326
- ✨ Created package.json
1327
- ✨ Created tsconfig.json
1328
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies",
1329
- "warn": "",
1330
- }
1331
- `);
1430
+ Object {
1431
+ "debug": "",
1432
+ "err": "",
1433
+ "info": "",
1434
+ "out": "✨ Created wrangler.toml
1435
+ ✨ Created package.json
1436
+ ✨ Created tsconfig.json
1437
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies",
1438
+ "warn": "",
1439
+ }
1440
+ `);
1332
1441
  });
1333
1442
 
1334
1443
  it("should not touch an existing tsconfig.json in the same directory", async () => {
@@ -1337,9 +1446,16 @@ describe("init", () => {
1337
1446
  result: false,
1338
1447
  });
1339
1448
  mockSelect({
1340
- text: "Would you like to create a Worker at src/index.ts?",
1449
+ text: `Would you like to create a Worker at ${path.join(
1450
+ "src",
1451
+ "index.ts"
1452
+ )}?`,
1341
1453
  result: "fetch",
1342
1454
  });
1455
+ mockConfirm({
1456
+ text: "Would you like us to write your first test with Vitest?",
1457
+ result: true,
1458
+ });
1343
1459
  writeFiles({
1344
1460
  items: {
1345
1461
  "package.json": {
@@ -1366,17 +1482,20 @@ describe("init", () => {
1366
1482
  },
1367
1483
  });
1368
1484
  expect(std).toMatchInlineSnapshot(`
1369
- Object {
1370
- "debug": "",
1371
- "err": "",
1372
- "out": "✨ Created wrangler.toml
1373
- ✨ Created src/index.ts
1485
+ Object {
1486
+ "debug": "",
1487
+ "err": "",
1488
+ "info": "",
1489
+ "out": "✨ Created wrangler.toml
1490
+ ✨ Created src/index.ts
1491
+ ✨ Created src/index.test.ts
1492
+ ✨ Installed vitest into devDependencies
1374
1493
 
1375
- To start developing your Worker, run \`npx wrangler dev\`
1376
- To publish your Worker to the Internet, run \`npx wrangler publish\`",
1377
- "warn": "",
1378
- }
1379
- `);
1494
+ To start developing your Worker, run \`npx wrangler dev\`
1495
+ To publish your Worker to the Internet, run \`npx wrangler publish\`",
1496
+ "warn": "",
1497
+ }
1498
+ `);
1380
1499
  });
1381
1500
 
1382
1501
  it("should not touch an existing tsconfig.json in the ancestor of a target directory, if a name is passed", async () => {
@@ -1395,9 +1514,20 @@ describe("init", () => {
1395
1514
  }
1396
1515
  );
1397
1516
  mockSelect({
1398
- text: "Would you like to create a Worker at path/to/worker/my-worker/src/index.ts?",
1517
+ text: `Would you like to create a Worker at ${path.join(
1518
+ "path",
1519
+ "to",
1520
+ "worker",
1521
+ "my-worker",
1522
+ "src",
1523
+ "index.ts"
1524
+ )}?`,
1399
1525
  result: "fetch",
1400
1526
  });
1527
+ mockConfirm({
1528
+ text: "Would you like us to write your first test with Vitest?",
1529
+ result: true,
1530
+ });
1401
1531
  writeFiles({
1402
1532
  items: {
1403
1533
  "path/to/worker/package.json": {
@@ -1424,20 +1554,23 @@ describe("init", () => {
1424
1554
  },
1425
1555
  });
1426
1556
  expect(std).toMatchInlineSnapshot(`
1427
- Object {
1428
- "debug": "",
1429
- "err": "",
1430
- "out": "✨ Created path/to/worker/my-worker/wrangler.toml
1431
- ✨ Created path/to/worker/my-worker/package.json
1432
- ✨ Created path/to/worker/my-worker/tsconfig.json
1433
- ✨ Created path/to/worker/my-worker/src/index.ts
1434
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1435
-
1436
- To start developing your Worker, run \`cd path/to/worker/my-worker && npm start\`
1437
- To publish your Worker to the Internet, run \`npm run deploy\`",
1438
- "warn": "",
1439
- }
1440
- `);
1557
+ Object {
1558
+ "debug": "",
1559
+ "err": "",
1560
+ "info": "",
1561
+ "out": "✨ Created path/to/worker/my-worker/wrangler.toml
1562
+ ✨ Created path/to/worker/my-worker/package.json
1563
+ ✨ Created path/to/worker/my-worker/tsconfig.json
1564
+ ✨ Created path/to/worker/my-worker/src/index.ts
1565
+ ✨ Created path/to/worker/my-worker/src/index.test.ts
1566
+ ✨ Installed @cloudflare/workers-types, typescript, and vitest into devDependencies
1567
+
1568
+ To start developing your Worker, run \`cd path/to/worker/my-worker && npm start\`
1569
+ To start testing your Worker, run \`npm test\`
1570
+ To publish your Worker to the Internet, run \`npm run deploy\`",
1571
+ "warn": "",
1572
+ }
1573
+ `);
1441
1574
  });
1442
1575
 
1443
1576
  it("should offer to install type definitions in an existing typescript project", async () => {
@@ -1456,7 +1589,10 @@ describe("init", () => {
1456
1589
  }
1457
1590
  );
1458
1591
  mockSelect({
1459
- text: "Would you like to create a Worker at src/index.ts?",
1592
+ text: `Would you like to create a Worker at ${path.join(
1593
+ "src",
1594
+ "index.ts"
1595
+ )}?`,
1460
1596
  result: "none",
1461
1597
  });
1462
1598
  writeFiles({
@@ -1483,15 +1619,16 @@ describe("init", () => {
1483
1619
  "@cloudflare/workers-types"
1484
1620
  );
1485
1621
  expect(std).toMatchInlineSnapshot(`
1486
- Object {
1487
- "debug": "",
1488
- "err": "",
1489
- "out": "✨ Created wrangler.toml
1490
- ✨ Installed @cloudflare/workers-types into devDependencies
1491
- 🚨 Please add \\"@cloudflare/workers-types\\" to compilerOptions.types in tsconfig.json",
1492
- "warn": "",
1493
- }
1494
- `);
1622
+ Object {
1623
+ "debug": "",
1624
+ "err": "",
1625
+ "info": "",
1626
+ "out": "✨ Created wrangler.toml
1627
+ ✨ Installed @cloudflare/workers-types into devDependencies
1628
+ 🚨 Please add \\"@cloudflare/workers-types\\" to compilerOptions.types in tsconfig.json",
1629
+ "warn": "",
1630
+ }
1631
+ `);
1495
1632
  });
1496
1633
 
1497
1634
  it("should not touch an existing tsconfig.json in an ancestor directory", async () => {
@@ -1500,9 +1637,16 @@ describe("init", () => {
1500
1637
  result: false,
1501
1638
  });
1502
1639
  mockSelect({
1503
- text: "Would you like to create a Worker at src/index.ts?",
1640
+ text: `Would you like to create a Worker at ${path.join(
1641
+ "src",
1642
+ "index.ts"
1643
+ )}?`,
1504
1644
  result: "fetch",
1505
1645
  });
1646
+ mockConfirm({
1647
+ text: "Would you like us to write your first test with Vitest?",
1648
+ result: true,
1649
+ });
1506
1650
  writeFiles({
1507
1651
  items: {
1508
1652
  "package.json": {
@@ -1531,17 +1675,20 @@ describe("init", () => {
1531
1675
  },
1532
1676
  });
1533
1677
  expect(std).toMatchInlineSnapshot(`
1534
- Object {
1535
- "debug": "",
1536
- "err": "",
1537
- "out": "✨ Created wrangler.toml
1538
- ✨ Created src/index.ts
1678
+ Object {
1679
+ "debug": "",
1680
+ "err": "",
1681
+ "info": "",
1682
+ "out": "✨ Created wrangler.toml
1683
+ ✨ Created src/index.ts
1684
+ ✨ Created src/index.test.ts
1685
+ ✨ Installed vitest into devDependencies
1539
1686
 
1540
- To start developing your Worker, run \`npx wrangler dev\`
1541
- To publish your Worker to the Internet, run \`npx wrangler publish\`",
1542
- "warn": "",
1543
- }
1544
- `);
1687
+ To start developing your Worker, run \`npx wrangler dev\`
1688
+ To publish your Worker to the Internet, run \`npx wrangler publish\`",
1689
+ "warn": "",
1690
+ }
1691
+ `);
1545
1692
  });
1546
1693
  });
1547
1694
 
@@ -1556,21 +1703,23 @@ describe("init", () => {
1556
1703
  text: "No package.json found. Would you like to create one?",
1557
1704
  result: true,
1558
1705
  },
1559
- {
1560
- text: "Would you like to install wrangler into package.json?",
1561
- result: false,
1562
- },
1706
+
1563
1707
  {
1564
1708
  text: "Would you like to use TypeScript?",
1565
1709
  result: false,
1566
- },
1567
- { text: "Would you like us to write your first test?", result: false }
1710
+ }
1568
1711
  );
1569
1712
  mockSelect({
1570
- text: "Would you like to create a Worker at src/index.js?",
1713
+ text: `Would you like to create a Worker at ${path.join(
1714
+ "src",
1715
+ "index.js"
1716
+ )}?`,
1571
1717
  result: "fetch",
1572
1718
  });
1573
-
1719
+ mockConfirm({
1720
+ text: "Would you like us to write your first test?",
1721
+ result: false,
1722
+ });
1574
1723
  await runWrangler("init");
1575
1724
 
1576
1725
  checkFiles({
@@ -1608,24 +1757,26 @@ describe("init", () => {
1608
1757
  text: "No package.json found. Would you like to create one?",
1609
1758
  result: true,
1610
1759
  },
1611
- {
1612
- text: "Would you like to install wrangler into package.json?",
1613
- result: false,
1614
- },
1615
1760
  {
1616
1761
  text: "Would you like to use TypeScript?",
1617
1762
  result: false,
1618
- },
1619
- { text: "Would you like us to write your first test?", result: true }
1620
- );
1621
- mockSelect(
1622
- {
1623
- text: "Would you like to create a Worker at src/index.js?",
1624
- result: "fetch",
1625
- },
1626
- { text: "Which test runner would you like to use?", result: "jest" }
1763
+ }
1627
1764
  );
1628
-
1765
+ mockSelect({
1766
+ text: `Would you like to create a Worker at ${path.join(
1767
+ "src",
1768
+ "index.js"
1769
+ )}?`,
1770
+ result: "fetch",
1771
+ });
1772
+ mockConfirm({
1773
+ text: "Would you like us to write your first test?",
1774
+ result: true,
1775
+ });
1776
+ mockSelect({
1777
+ text: "Which test runner would you like to use?",
1778
+ result: "jest",
1779
+ });
1629
1780
  await runWrangler("init");
1630
1781
 
1631
1782
  checkFiles({
@@ -1669,24 +1820,26 @@ describe("init", () => {
1669
1820
  text: "No package.json found. Would you like to create one?",
1670
1821
  result: true,
1671
1822
  },
1672
- {
1673
- text: "Would you like to install wrangler into package.json?",
1674
- result: false,
1675
- },
1676
1823
  {
1677
1824
  text: "Would you like to use TypeScript?",
1678
1825
  result: false,
1679
- },
1680
- { text: "Would you like us to write your first test?", result: true }
1681
- );
1682
- mockSelect(
1683
- {
1684
- text: "Would you like to create a Worker at src/index.js?",
1685
- result: "fetch",
1686
- },
1687
- { text: "Which test runner would you like to use?", result: "vitest" }
1826
+ }
1688
1827
  );
1689
-
1828
+ mockSelect({
1829
+ text: `Would you like to create a Worker at ${path.join(
1830
+ "src",
1831
+ "index.js"
1832
+ )}?`,
1833
+ result: "fetch",
1834
+ });
1835
+ mockConfirm({
1836
+ text: "Would you like us to write your first test?",
1837
+ result: true,
1838
+ });
1839
+ mockSelect({
1840
+ text: "Which test runner would you like to use?",
1841
+ result: "vitest",
1842
+ });
1690
1843
  await runWrangler("init");
1691
1844
 
1692
1845
  checkFiles({
@@ -1733,13 +1886,19 @@ describe("init", () => {
1733
1886
  {
1734
1887
  text: "Would you like to use TypeScript?",
1735
1888
  result: false,
1736
- },
1737
- { text: "Would you like us to write your first test?", result: false }
1889
+ }
1738
1890
  );
1739
1891
  mockSelect({
1740
- text: "Would you like to create a Worker at src/index.js?",
1892
+ text: `Would you like to create a Worker at ${path.join(
1893
+ "src",
1894
+ "index.js"
1895
+ )}?`,
1741
1896
  result: "fetch",
1742
1897
  });
1898
+ mockConfirm({
1899
+ text: "Would you like us to write your first test?",
1900
+ result: false,
1901
+ });
1743
1902
  writeFiles({
1744
1903
  items: {
1745
1904
  "package.json": {
@@ -1810,13 +1969,14 @@ describe("init", () => {
1810
1969
  },
1811
1970
  });
1812
1971
  expect(std).toMatchInlineSnapshot(`
1813
- Object {
1814
- "debug": "",
1815
- "err": "",
1816
- "out": "✨ Created wrangler.toml",
1817
- "warn": "",
1818
- }
1819
- `);
1972
+ Object {
1973
+ "debug": "",
1974
+ "err": "",
1975
+ "info": "",
1976
+ "out": "✨ Created wrangler.toml",
1977
+ "warn": "",
1978
+ }
1979
+ `);
1820
1980
  });
1821
1981
 
1822
1982
  it("should not offer to create a worker in a non-ts named worker project if a file already exists at the location", async () => {
@@ -1826,7 +1986,10 @@ describe("init", () => {
1826
1986
  result: false,
1827
1987
  },
1828
1988
  {
1829
- text: "Would you like to install wrangler into my-worker/package.json?",
1989
+ text: `Would you like to install wrangler into ${path.join(
1990
+ "my-worker",
1991
+ "package.json"
1992
+ )}?`,
1830
1993
  result: false,
1831
1994
  },
1832
1995
  {
@@ -1853,13 +2016,14 @@ describe("init", () => {
1853
2016
  },
1854
2017
  });
1855
2018
  expect(std).toMatchInlineSnapshot(`
1856
- Object {
1857
- "debug": "",
1858
- "err": "",
1859
- "out": "✨ Created my-worker/wrangler.toml",
1860
- "warn": "",
1861
- }
1862
- `);
2019
+ Object {
2020
+ "debug": "",
2021
+ "err": "",
2022
+ "info": "",
2023
+ "out": "✨ Created my-worker/wrangler.toml",
2024
+ "warn": "",
2025
+ }
2026
+ `);
1863
2027
  });
1864
2028
  });
1865
2029
 
@@ -1887,24 +2051,41 @@ describe("init", () => {
1887
2051
  ...MINIMAL_WRANGLER_TOML,
1888
2052
  name: workerName,
1889
2053
  }),
2054
+ "package.json": {
2055
+ contents: expect.objectContaining({
2056
+ name: expect.stringContaining("wrangler-tests"),
2057
+ version: "0.0.0",
2058
+ scripts: {
2059
+ deploy: "wrangler publish",
2060
+ start: "wrangler dev",
2061
+ test: "vitest",
2062
+ },
2063
+ devDependencies: {
2064
+ wrangler: expect.any(String),
2065
+ },
2066
+ }),
2067
+ },
1890
2068
  },
1891
2069
  });
1892
2070
  expect(std).toMatchInlineSnapshot(`
1893
- Object {
1894
- "debug": "",
1895
- "err": "",
1896
- "out": "✨ Created wrangler.toml
1897
- ✨ Initialized git repository
1898
- ✨ Created package.json
1899
- ✨ Created tsconfig.json
1900
- ✨ Created src/index.ts
1901
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
2071
+ Object {
2072
+ "debug": "",
2073
+ "err": "",
2074
+ "info": "Your project will use Vitest to run your tests.",
2075
+ "out": "✨ Created wrangler.toml
2076
+ ✨ Initialized git repository
2077
+ ✨ Created package.json
2078
+ ✨ Created tsconfig.json
2079
+ ✨ Created src/index.ts
2080
+ ✨ Created src/index.test.ts
2081
+ ✨ Installed @cloudflare/workers-types, typescript, and vitest into devDependencies
1902
2082
 
1903
- To start developing your Worker, run \`npm start\`
1904
- To publish your Worker to the Internet, run \`npm run deploy\`",
1905
- "warn": "",
1906
- }
1907
- `);
2083
+ To start developing your Worker, run \`npm start\`
2084
+ To start testing your Worker, run \`npm test\`
2085
+ To publish your Worker to the Internet, run \`npm run deploy\`",
2086
+ "warn": "",
2087
+ }
2088
+ `);
1908
2089
  });
1909
2090
 
1910
2091
  it('should create a worker in a nested directory if "name" is path/to/worker', async () => {
@@ -1919,21 +2100,24 @@ describe("init", () => {
1919
2100
  },
1920
2101
  });
1921
2102
  expect(std).toMatchInlineSnapshot(`
1922
- Object {
1923
- "debug": "",
1924
- "err": "",
1925
- "out": "✨ Created path/to/worker/wrangler.toml
1926
- ✨ Initialized git repository at path/to/worker
1927
- ✨ Created path/to/worker/package.json
1928
- ✨ Created path/to/worker/tsconfig.json
1929
- ✨ Created path/to/worker/src/index.ts
1930
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1931
-
1932
- To start developing your Worker, run \`cd path/to/worker && npm start\`
1933
- To publish your Worker to the Internet, run \`npm run deploy\`",
1934
- "warn": "",
1935
- }
1936
- `);
2103
+ Object {
2104
+ "debug": "",
2105
+ "err": "",
2106
+ "info": "Your project will use Vitest to run your tests.",
2107
+ "out": "✨ Created path/to/worker/wrangler.toml
2108
+ ✨ Initialized git repository at path/to/worker
2109
+ ✨ Created path/to/worker/package.json
2110
+ ✨ Created path/to/worker/tsconfig.json
2111
+ ✨ Created path/to/worker/src/index.ts
2112
+ ✨ Created path/to/worker/src/index.test.ts
2113
+ ✨ Installed @cloudflare/workers-types, typescript, and vitest into devDependencies
2114
+
2115
+ To start developing your Worker, run \`cd path/to/worker && npm start\`
2116
+ To start testing your Worker, run \`npm test\`
2117
+ To publish your Worker to the Internet, run \`npm run deploy\`",
2118
+ "warn": "",
2119
+ }
2120
+ `);
1937
2121
  });
1938
2122
 
1939
2123
  it("should normalize characters that aren't lowercase alphanumeric, underscores, or dashes", async () => {
@@ -1948,21 +2132,24 @@ describe("init", () => {
1948
2132
  },
1949
2133
  });
1950
2134
  expect(std).toMatchInlineSnapshot(`
1951
- Object {
1952
- "debug": "",
1953
- "err": "",
1954
- "out": "✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/wrangler.toml
1955
- ✨ Initialized git repository at WEIRD_w0rkr_N4m3.js.tsx.tar.gz
1956
- ✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/package.json
1957
- ✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/tsconfig.json
1958
- ✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/src/index.ts
1959
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1960
-
1961
- To start developing your Worker, run \`cd WEIRD_w0rkr_N4m3.js.tsx.tar.gz && npm start\`
1962
- To publish your Worker to the Internet, run \`npm run deploy\`",
1963
- "warn": "",
1964
- }
1965
- `);
2135
+ Object {
2136
+ "debug": "",
2137
+ "err": "",
2138
+ "info": "Your project will use Vitest to run your tests.",
2139
+ "out": "✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/wrangler.toml
2140
+ ✨ Initialized git repository at WEIRD_w0rkr_N4m3.js.tsx.tar.gz
2141
+ ✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/package.json
2142
+ ✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/tsconfig.json
2143
+ ✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/src/index.ts
2144
+ ✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/src/index.test.ts
2145
+ ✨ Installed @cloudflare/workers-types, typescript, and vitest into devDependencies
2146
+
2147
+ To start developing your Worker, run \`cd WEIRD_w0rkr_N4m3.js.tsx.tar.gz && npm start\`
2148
+ To start testing your Worker, run \`npm test\`
2149
+ To publish your Worker to the Internet, run \`npm run deploy\`",
2150
+ "warn": "",
2151
+ }
2152
+ `);
1966
2153
  });
1967
2154
 
1968
2155
  it("should ignore ancestor files (such as wrangler.toml, package.json and tsconfig.json) if a name/path is given", async () => {
@@ -1971,23 +2158,29 @@ describe("init", () => {
1971
2158
  text: "Would you like to use git to manage this Worker?",
1972
2159
  result: false,
1973
2160
  },
1974
- {
1975
- text: "Would you like to use TypeScript?",
1976
- result: true,
1977
- },
1978
2161
  {
1979
2162
  text: "No package.json found. Would you like to create one?",
1980
2163
  result: true,
1981
2164
  },
1982
2165
  {
1983
- text: "Would you like to install the type definitions for Workers into your package.json?",
2166
+ text: "Would you like to use TypeScript?",
1984
2167
  result: true,
1985
2168
  }
1986
2169
  );
1987
2170
  mockSelect({
1988
- text: "Would you like to create a Worker at sub/folder/worker/src/index.ts?",
2171
+ text: `Would you like to create a Worker at ${path.join(
2172
+ "sub",
2173
+ "folder",
2174
+ "worker",
2175
+ "src",
2176
+ "index.ts"
2177
+ )}?`,
1989
2178
  result: "fetch",
1990
2179
  });
2180
+ mockConfirm({
2181
+ text: "Would you like us to write your first test with Vitest?",
2182
+ result: true,
2183
+ });
1991
2184
  writeFiles({
1992
2185
  items: {
1993
2186
  "package.json": { contents: { name: "top-level" } },
@@ -2035,10 +2228,7 @@ describe("init", () => {
2035
2228
  describe("from dashboard", () => {
2036
2229
  mockApiToken();
2037
2230
  mockAccountId({ accountId: "LCARS" });
2038
- afterEach(() => {
2039
- unsetAllMocks();
2040
- unsetSpecialMockFns();
2041
- });
2231
+
2042
2232
  const mockDashboardScript = `
2043
2233
  export default {
2044
2234
  async fetch(request, env, ctx) {
@@ -2046,6 +2236,12 @@ describe("init", () => {
2046
2236
  },
2047
2237
  };
2048
2238
  `;
2239
+ afterEach(() => {
2240
+ // some test has a side-effect which is overwriting the compatibility_date
2241
+ mockServiceMetadata.default_environment.script.compatibility_date =
2242
+ "1987-9-27";
2243
+ mockConfigExpected.compatibility_date = "1987-9-27";
2244
+ });
2049
2245
  const mockServiceMetadata = {
2050
2246
  id: "memory-crystal",
2051
2247
  default_environment: {
@@ -2062,6 +2258,7 @@ describe("init", () => {
2062
2258
  migration_tag: "some-migration-tag",
2063
2259
  usage_model: "bundled",
2064
2260
  compatibility_date: "1987-9-27",
2261
+ tail_consumers: [{ service: "listener" }],
2065
2262
  },
2066
2263
  },
2067
2264
  created_on: "1987-9-27",
@@ -2114,7 +2311,7 @@ describe("init", () => {
2114
2311
  type: "service",
2115
2312
  },
2116
2313
  {
2117
- type: "namespace",
2314
+ type: "dispatch_namespace",
2118
2315
  name: "name-namespace-mock",
2119
2316
  namespace: "namespace-mock",
2120
2317
  },
@@ -2263,6 +2460,7 @@ describe("init", () => {
2263
2460
  },
2264
2461
  ],
2265
2462
  },
2463
+ tail_consumers: [{ service: "listener" }],
2266
2464
  };
2267
2465
 
2268
2466
  function mockSupportingDashRequests({
@@ -2276,69 +2474,108 @@ describe("init", () => {
2276
2474
  expectedEnvironment: string;
2277
2475
  expectedCompatDate: string | undefined;
2278
2476
  }) {
2279
- setMockResponse(
2280
- `/accounts/:accountId/workers/services/:scriptName`,
2281
- "GET",
2282
- ([_url, accountId, scriptName]) => {
2283
- expect(accountId).toEqual(expectedAccountId);
2284
- expect(scriptName).toEqual(expectedScriptName);
2285
-
2286
- if (expectedCompatDate === undefined)
2287
- (mockServiceMetadata.default_environment.script
2288
- .compatibility_date as unknown) = expectedCompatDate;
2289
- return mockServiceMetadata;
2290
- }
2291
- );
2292
- setMockResponse(
2293
- `/accounts/:accountId/workers/services/:scriptName/environments/:environment/bindings`,
2294
- "GET",
2295
- ([_url, accountId, scriptName, environment]) => {
2296
- expect(accountId).toEqual(expectedAccountId);
2297
- expect(scriptName).toEqual(expectedScriptName);
2298
- expect(environment).toEqual(expectedEnvironment);
2299
-
2300
- return mockBindingsRes;
2301
- }
2302
- );
2303
- setMockResponse(
2304
- `/accounts/:accountId/workers/services/:scriptName/environments/:environment/routes`,
2305
- "GET",
2306
- ([_url, accountId, scriptName, environment]) => {
2307
- expect(accountId).toEqual(expectedAccountId);
2308
- expect(scriptName).toEqual(expectedScriptName);
2309
- expect(environment).toEqual(expectedEnvironment);
2310
-
2311
- return mockRoutesRes;
2312
- }
2313
- );
2314
- setMockResponse(
2315
- `/accounts/:accountId/workers/services/:scriptName/environments/:environment`,
2316
- "GET",
2317
- ([_url, accountId, scriptName, environment]) => {
2318
- expect(accountId).toEqual(expectedAccountId);
2319
- expect(scriptName).toEqual(expectedScriptName);
2320
- expect(environment).toEqual(expectedEnvironment);
2321
-
2322
- return mockServiceMetadata.default_environment;
2323
- }
2324
- );
2325
- setMockResponse(
2326
- `/accounts/:accountId/workers/scripts/:scriptName/schedules`,
2327
- "GET",
2328
- ([_url, accountId, scriptName]) => {
2329
- expect(accountId).toEqual(expectedAccountId);
2330
- expect(scriptName).toEqual(expectedScriptName);
2331
-
2332
- return {
2333
- schedules: [
2334
- {
2335
- cron: "0 0 0 * * *",
2336
- created_on: new Date(1987, 9, 27),
2337
- modified_on: new Date(1987, 9, 27),
2338
- },
2339
- ],
2340
- };
2341
- }
2477
+ msw.use(
2478
+ rest.get(
2479
+ `*/accounts/:accountId/workers/services/:scriptName`,
2480
+ (req, res, ctx) => {
2481
+ expect(req.params.accountId).toEqual(expectedAccountId);
2482
+ expect(req.params.scriptName).toEqual(expectedScriptName);
2483
+
2484
+ if (expectedCompatDate === undefined)
2485
+ (mockServiceMetadata.default_environment.script
2486
+ .compatibility_date as unknown) = expectedCompatDate;
2487
+
2488
+ return res.once(
2489
+ ctx.status(200),
2490
+ ctx.json({
2491
+ success: true,
2492
+ errors: [],
2493
+ messages: [],
2494
+ result: mockServiceMetadata,
2495
+ })
2496
+ );
2497
+ }
2498
+ ),
2499
+ rest.get(
2500
+ `*/accounts/:accountId/workers/services/:scriptName/environments/:environment/bindings`,
2501
+ (req, res, ctx) => {
2502
+ expect(req.params.accountId).toEqual(expectedAccountId);
2503
+ expect(req.params.scriptName).toEqual(expectedScriptName);
2504
+ expect(req.params.environment).toEqual(expectedEnvironment);
2505
+
2506
+ return res.once(
2507
+ ctx.status(200),
2508
+ ctx.json({
2509
+ success: true,
2510
+ errors: [],
2511
+ messages: [],
2512
+ result: mockBindingsRes,
2513
+ })
2514
+ );
2515
+ }
2516
+ ),
2517
+ rest.get(
2518
+ `*/accounts/:accountId/workers/services/:scriptName/environments/:environment/routes`,
2519
+ (req, res, ctx) => {
2520
+ expect(req.params.accountId).toEqual(expectedAccountId);
2521
+ expect(req.params.scriptName).toEqual(expectedScriptName);
2522
+ expect(req.params.environment).toEqual(expectedEnvironment);
2523
+
2524
+ return res.once(
2525
+ ctx.status(200),
2526
+ ctx.json({
2527
+ success: true,
2528
+ errors: [],
2529
+ messages: [],
2530
+ result: mockRoutesRes,
2531
+ })
2532
+ );
2533
+ }
2534
+ ),
2535
+ rest.get(
2536
+ `*/accounts/:accountId/workers/services/:scriptName/environments/:environment`,
2537
+
2538
+ (req, res, ctx) => {
2539
+ expect(req.params.accountId).toEqual(expectedAccountId);
2540
+ expect(req.params.scriptName).toEqual(expectedScriptName);
2541
+ expect(req.params.environment).toEqual(expectedEnvironment);
2542
+
2543
+ return res.once(
2544
+ ctx.status(200),
2545
+ ctx.json({
2546
+ success: true,
2547
+ errors: [],
2548
+ messages: [],
2549
+ result: mockServiceMetadata.default_environment,
2550
+ })
2551
+ );
2552
+ }
2553
+ ),
2554
+ rest.get(
2555
+ `*/accounts/:accountId/workers/scripts/:scriptName/schedules`,
2556
+ (req, res, ctx) => {
2557
+ expect(req.params.accountId).toEqual(expectedAccountId);
2558
+ expect(req.params.scriptName).toEqual(expectedScriptName);
2559
+
2560
+ return res.once(
2561
+ ctx.status(200),
2562
+ ctx.json({
2563
+ success: true,
2564
+ errors: [],
2565
+ messages: [],
2566
+ result: {
2567
+ schedules: [
2568
+ {
2569
+ cron: "0 0 0 * * *",
2570
+ created_on: new Date(1987, 9, 27),
2571
+ modified_on: new Date(1987, 9, 27),
2572
+ },
2573
+ ],
2574
+ },
2575
+ })
2576
+ );
2577
+ }
2578
+ )
2342
2579
  );
2343
2580
  }
2344
2581
 
@@ -2350,27 +2587,18 @@ describe("init", () => {
2350
2587
  expectedEnvironment: "test",
2351
2588
  expectedCompatDate: "1987-9-27",
2352
2589
  });
2353
- setMockFetchDashScript({
2354
- accountId: "LCARS",
2355
- fromDashScriptName: "memory-crystal",
2356
- environment: mockServiceMetadata.default_environment.environment,
2357
- mockResponse: mockDashboardScript,
2358
- });
2590
+ setMockFetchDashScript(mockDashboardScript);
2359
2591
  mockConfirm(
2360
2592
  {
2361
2593
  text: "Would you like to use git to manage this Worker?",
2362
2594
  result: false,
2363
2595
  },
2364
- {
2365
- text: "Would you like to use TypeScript?",
2366
- result: true,
2367
- },
2368
2596
  {
2369
2597
  text: "No package.json found. Would you like to create one?",
2370
2598
  result: true,
2371
2599
  },
2372
2600
  {
2373
- text: "Would you like to install the type definitions for Workers into your package.json?",
2601
+ text: "Would you like to use TypeScript?",
2374
2602
  result: true,
2375
2603
  }
2376
2604
  );
@@ -2400,6 +2628,44 @@ describe("init", () => {
2400
2628
  });
2401
2629
  });
2402
2630
 
2631
+ it("should fail on init --from-dash on non-existent worker name", async () => {
2632
+ msw.use(
2633
+ rest.get(
2634
+ `*/accounts/:accountId/workers/services/:scriptName`,
2635
+ (req, res, ctx) => {
2636
+ return res.once(
2637
+ ctx.status(200),
2638
+ ctx.json({
2639
+ success: true,
2640
+ errors: [],
2641
+ messages: [],
2642
+ result: mockServiceMetadata,
2643
+ })
2644
+ );
2645
+ }
2646
+ )
2647
+ );
2648
+ setMockFetchDashScript(mockDashboardScript);
2649
+ mockConfirm(
2650
+ {
2651
+ text: "Would you like to use git to manage this Worker?",
2652
+ result: false,
2653
+ },
2654
+ {
2655
+ text: "No package.json found. Would you like to create one?",
2656
+ result: true,
2657
+ },
2658
+ {
2659
+ text: "Would you like to use TypeScript?",
2660
+ result: true,
2661
+ }
2662
+ );
2663
+
2664
+ await expect(
2665
+ runWrangler("init isolinear-optical-chip --from-dash i-dont-exist")
2666
+ ).rejects.toThrowError();
2667
+ });
2668
+
2403
2669
  it("should download source script from dashboard w/ out positional <name>", async () => {
2404
2670
  mockSupportingDashRequests({
2405
2671
  expectedAccountId: "LCARS",
@@ -2407,32 +2673,23 @@ describe("init", () => {
2407
2673
  expectedEnvironment: "test",
2408
2674
  expectedCompatDate: "1987-9-27",
2409
2675
  });
2410
- setMockFetchDashScript({
2411
- accountId: "LCARS",
2412
- fromDashScriptName: "isolinear-optical-chip",
2413
- environment: mockServiceMetadata.default_environment.environment,
2414
- mockResponse: mockDashboardScript,
2415
- });
2676
+ setMockFetchDashScript(mockDashboardScript);
2416
2677
  mockConfirm(
2417
2678
  {
2418
2679
  text: "Would you like to use git to manage this Worker?",
2419
2680
  result: false,
2420
2681
  },
2421
- {
2422
- text: "Would you like to use TypeScript?",
2423
- result: true,
2424
- },
2425
2682
  {
2426
2683
  text: "No package.json found. Would you like to create one?",
2427
2684
  result: true,
2428
2685
  },
2429
2686
  {
2430
- text: "Would you like to install the type definitions for Workers into your package.json?",
2687
+ text: "Would you like to use TypeScript?",
2431
2688
  result: true,
2432
2689
  }
2433
2690
  );
2434
2691
 
2435
- await runWrangler("init --from-dash isolinear-optical-chip");
2692
+ await runWrangler("init --from-dash isolinear-optical-chip");
2436
2693
 
2437
2694
  expect(fs.readFileSync("./isolinear-optical-chip/wrangler.toml", "utf8"))
2438
2695
  .toMatchInlineSnapshot(`
@@ -2453,6 +2710,9 @@ describe("init", () => {
2453
2710
  test = { }
2454
2711
  staging = { }
2455
2712
 
2713
+ [[tail_consumers]]
2714
+ service = \\"listener\\"
2715
+
2456
2716
  [vars]
2457
2717
  ANOTHER-NAME = \\"thing-TEXT\\"
2458
2718
 
@@ -2502,17 +2762,18 @@ describe("init", () => {
2502
2762
  DATA_BLOB_ONE = \\"DATA_BLOB_ONE\\"
2503
2763
  DATA_BLOB_TWO = \\"DATA_BLOB_TWO\\"
2504
2764
 
2505
- [[unsafe.bindings]]
2506
- type = \\"some unsafe thing\\"
2507
- name = \\"UNSAFE_BINDING_ONE\\"
2765
+ [unsafe]
2766
+ [[unsafe.bindings]]
2767
+ type = \\"some unsafe thing\\"
2768
+ name = \\"UNSAFE_BINDING_ONE\\"
2508
2769
 
2509
2770
  [unsafe.bindings.data.some]
2510
2771
  unsafe = \\"thing\\"
2511
2772
 
2512
- [[unsafe.bindings]]
2513
- type = \\"another unsafe thing\\"
2514
- name = \\"UNSAFE_BINDING_TWO\\"
2515
- data = 1_337
2773
+ [[unsafe.bindings]]
2774
+ type = \\"another unsafe thing\\"
2775
+ name = \\"UNSAFE_BINDING_TWO\\"
2776
+ data = 1_337
2516
2777
  "
2517
2778
  `);
2518
2779
  expect(std.out).toContain("cd isolinear-optical-chip");
@@ -2544,28 +2805,19 @@ describe("init", () => {
2544
2805
  expectedEnvironment: "test",
2545
2806
  expectedCompatDate: "1987-9-27",
2546
2807
  });
2547
- setMockFetchDashScript({
2548
- accountId: "LCARS",
2549
- fromDashScriptName: "isolinear-optical-chip",
2550
- environment: mockServiceMetadata.default_environment.environment,
2551
- mockResponse: mockDashboardScript,
2552
- });
2808
+ setMockFetchDashScript(mockDashboardScript);
2553
2809
  mockConfirm(
2554
2810
  {
2555
2811
  text: "Would you like to use git to manage this Worker?",
2556
2812
  result: false,
2557
2813
  },
2558
- {
2559
- text: "Would you like to use TypeScript?",
2560
- result: false,
2561
- },
2562
2814
  {
2563
2815
  text: "No package.json found. Would you like to create one?",
2564
2816
  result: true,
2565
2817
  },
2566
2818
  {
2567
- text: "Would you like to install the type definitions for Workers into your package.json?",
2568
- result: true,
2819
+ text: "Would you like to use TypeScript?",
2820
+ result: false,
2569
2821
  }
2570
2822
  );
2571
2823
 
@@ -2586,6 +2838,7 @@ describe("init", () => {
2586
2838
  "isolinear-optical-chip/wrangler.toml": wranglerToml({
2587
2839
  ...mockConfigExpected,
2588
2840
  name: "isolinear-optical-chip",
2841
+ main: "src/index.js",
2589
2842
  }),
2590
2843
  },
2591
2844
  });
@@ -2603,27 +2856,18 @@ describe("init", () => {
2603
2856
  expectedEnvironment: "test",
2604
2857
  expectedCompatDate: undefined,
2605
2858
  });
2606
- setMockFetchDashScript({
2607
- accountId: "LCARS",
2608
- fromDashScriptName: "isolinear-optical-chip",
2609
- environment: mockServiceMetadata.default_environment.environment,
2610
- mockResponse: mockDashboardScript,
2611
- });
2859
+ setMockFetchDashScript(mockDashboardScript);
2612
2860
  mockConfirm(
2613
2861
  {
2614
2862
  text: "Would you like to use git to manage this Worker?",
2615
2863
  result: false,
2616
2864
  },
2617
- {
2618
- text: "Would you like to use TypeScript?",
2619
- result: true,
2620
- },
2621
2865
  {
2622
2866
  text: "No package.json found. Would you like to create one?",
2623
2867
  result: true,
2624
2868
  },
2625
2869
  {
2626
- text: "Would you like to install the type definitions for Workers into your package.json?",
2870
+ text: "Would you like to use TypeScript?",
2627
2871
  result: true,
2628
2872
  }
2629
2873
  );
@@ -2651,23 +2895,32 @@ describe("init", () => {
2651
2895
  });
2652
2896
 
2653
2897
  it("should throw an error to retry if a request fails", async () => {
2654
- setMockResponse(
2655
- `/accounts/:accountId/workers/services/:scriptName`,
2656
- "GET",
2657
- () => mockServiceMetadata
2658
- );
2659
- setMockResponse(
2660
- `/accounts/:accountId/workers/services/:scriptName/environments/:environment/bindings`,
2661
- "GET",
2662
- () => Promise.reject()
2898
+ msw.use(
2899
+ rest.get(
2900
+ `*/accounts/:accountId/workers/services/:scriptName`,
2901
+ (req, res, ctx) => {
2902
+ expect(req.params.accountId).toBe("LCARS");
2903
+ expect(req.params.scriptName).toBe("isolinear-optical-chip");
2904
+ return res.once(
2905
+ ctx.status(200),
2906
+ ctx.json({
2907
+ success: true,
2908
+ errors: [],
2909
+ messages: [],
2910
+ result: mockServiceMetadata,
2911
+ })
2912
+ );
2913
+ }
2914
+ ),
2915
+ rest.get(
2916
+ `*/accounts/:accountId/workers/services/:scriptName/environments/:environment/bindings`,
2917
+ (req, res) => {
2918
+ return res.networkError("Mock Network Error");
2919
+ }
2920
+ )
2663
2921
  );
2664
2922
 
2665
- setMockFetchDashScript({
2666
- accountId: "LCARS",
2667
- fromDashScriptName: "isolinear-optical-chip",
2668
- environment: mockServiceMetadata.default_environment.environment,
2669
- mockResponse: mockDashboardScript,
2670
- });
2923
+ setMockFetchDashScript(mockDashboardScript);
2671
2924
  mockConfirm(
2672
2925
  {
2673
2926
  text: "Would you like to use git to manage this Worker?",
@@ -2676,23 +2929,15 @@ describe("init", () => {
2676
2929
  {
2677
2930
  text: "Would you like to use TypeScript?",
2678
2931
  result: false,
2679
- },
2680
- {
2681
- text: "No package.json found. Would you like to create one?",
2682
- result: true,
2683
- },
2684
- {
2685
- text: "Would you like to install the type definitions for Workers into your package.json?",
2686
- result: true,
2687
2932
  }
2688
2933
  );
2689
2934
 
2690
2935
  await expect(
2691
- runWrangler("init --from-dash isolinear-optical-chip")
2936
+ runWrangler("init --from-dash isolinear-optical-chip")
2692
2937
  ).rejects.toThrowError();
2693
2938
  });
2694
2939
 
2695
- it("should not inlcude migrations in config file when none are necessary", async () => {
2940
+ it("should not include migrations in config file when none are necessary", async () => {
2696
2941
  const mockDate = "1988-08-07";
2697
2942
  jest
2698
2943
  .spyOn(Date.prototype, "toISOString")
@@ -2712,63 +2957,98 @@ describe("init", () => {
2712
2957
  created_on: "1988-08-07",
2713
2958
  usage_model: "bundled",
2714
2959
  compatibility_date: "1988-08-07",
2960
+ tail_consumers: [{ service: "listener" }],
2715
2961
  },
2716
2962
  },
2717
2963
  environments: [],
2718
2964
  };
2719
-
2720
- setMockResponse(
2721
- `/accounts/:accountId/workers/services/:scriptName`,
2722
- "GET",
2723
- () => mockData
2724
- );
2725
- setMockResponse(
2726
- `/accounts/:accountId/workers/services/:scriptName/environments/:environment/bindings`,
2727
- "GET",
2728
- () => []
2729
- );
2730
- setMockResponse(
2731
- `/accounts/:accountId/workers/services/:scriptName/environments/:environment/routes`,
2732
- "GET",
2733
- () => []
2734
- );
2735
- setMockResponse(
2736
- `/accounts/:accountId/workers/services/:scriptName/environments/:environment`,
2737
- "GET",
2738
- () => mockServiceMetadata.default_environment
2739
- );
2740
- setMockResponse(
2741
- `/accounts/:accountId/workers/scripts/:scriptName/schedules`,
2742
- "GET",
2743
- () => {
2744
- return {
2745
- schedules: [],
2746
- };
2747
- }
2965
+ msw.use(
2966
+ rest.get(
2967
+ `*/accounts/:accountId/workers/services/:scriptName`,
2968
+ (req, res, ctx) => {
2969
+ return res.once(
2970
+ ctx.status(200),
2971
+ ctx.json({
2972
+ success: true,
2973
+ errors: [],
2974
+ messages: [],
2975
+ result: mockData,
2976
+ })
2977
+ );
2978
+ }
2979
+ ),
2980
+ rest.get(
2981
+ `*/accounts/:accountId/workers/services/:scriptName/environments/:environment/bindings`,
2982
+ (req, res, ctx) => {
2983
+ return res.once(
2984
+ ctx.status(200),
2985
+ ctx.json({
2986
+ success: true,
2987
+ errors: [],
2988
+ messages: [],
2989
+ result: [],
2990
+ })
2991
+ );
2992
+ }
2993
+ ),
2994
+ rest.get(
2995
+ `*/accounts/:accountId/workers/services/:scriptName/environments/:environment/routes`,
2996
+ (req, res, ctx) => {
2997
+ return res.once(
2998
+ ctx.status(200),
2999
+ ctx.json({
3000
+ success: true,
3001
+ errors: [],
3002
+ messages: [],
3003
+ result: [],
3004
+ })
3005
+ );
3006
+ }
3007
+ ),
3008
+ rest.get(
3009
+ `*/accounts/:accountId/workers/services/:scriptName/environments/:environment`,
3010
+ (req, res, ctx) => {
3011
+ return res.once(
3012
+ ctx.status(200),
3013
+ ctx.json({
3014
+ success: true,
3015
+ errors: [],
3016
+ messages: [],
3017
+ result: mockData.default_environment,
3018
+ })
3019
+ );
3020
+ }
3021
+ ),
3022
+ rest.get(
3023
+ `*/accounts/:accountId/workers/scripts/:scriptName/schedules`,
3024
+ (req, res, ctx) => {
3025
+ return res.once(
3026
+ ctx.status(200),
3027
+ ctx.json({
3028
+ success: true,
3029
+ errors: [],
3030
+ messages: [],
3031
+ result: { schedules: [] },
3032
+ })
3033
+ );
3034
+ }
3035
+ )
2748
3036
  );
2749
3037
 
2750
- setMockFetchDashScript({
2751
- accountId: "LCARS",
2752
- fromDashScriptName: "isolinear-optical-chip",
2753
- environment: mockServiceMetadata.default_environment.environment,
2754
- mockResponse: mockDashboardScript,
2755
- });
3038
+ setMockFetchDashScript(mockDashboardScript);
2756
3039
 
2757
3040
  mockConfirm(
2758
3041
  {
2759
3042
  text: "Would you like to use git to manage this Worker?",
2760
3043
  result: false,
2761
3044
  },
2762
- {
2763
- text: "Would you like to use TypeScript?",
2764
- result: true,
2765
- },
3045
+
2766
3046
  {
2767
3047
  text: "No package.json found. Would you like to create one?",
2768
3048
  result: true,
2769
3049
  },
2770
3050
  {
2771
- text: "Would you like to install the type definitions for Workers into your package.json?",
3051
+ text: "Would you like to use TypeScript?",
2772
3052
  result: true,
2773
3053
  }
2774
3054
  );
@@ -2786,6 +3066,7 @@ describe("init", () => {
2786
3066
  },
2787
3067
  usage_model: "bundled",
2788
3068
  name: "isolinear-optical-chip",
3069
+ tail_consumers: [{ service: "listener" }],
2789
3070
  }),
2790
3071
  },
2791
3072
  });
@@ -2795,7 +3076,7 @@ describe("init", () => {
2795
3076
  await expect(
2796
3077
  runWrangler("init --from-dash")
2797
3078
  ).rejects.toMatchInlineSnapshot(
2798
- `[YError: Not enough arguments following: from-dash]`
3079
+ `[Error: Not enough arguments following: from-dash]`
2799
3080
  );
2800
3081
  checkFiles({
2801
3082
  items: {
@@ -2807,9 +3088,130 @@ describe("init", () => {
2807
3088
  },
2808
3089
  });
2809
3090
  });
3091
+
3092
+ it("should download multi-module source scripts from dashboard", async () => {
3093
+ mockSupportingDashRequests({
3094
+ expectedAccountId: "LCARS",
3095
+ expectedScriptName: "isolinear-optical-chip",
3096
+ expectedEnvironment: "test",
3097
+ expectedCompatDate: "1987-9-27",
3098
+ });
3099
+ const indexjs = `
3100
+ import handleRequest from './handleRequest.js';
3101
+
3102
+ export default {
3103
+ async fetch(request, env, ctx) {
3104
+ return handleRequest(request, env, ctx);
3105
+ },
3106
+ };
3107
+ `;
3108
+ const otherjs = `
3109
+ export default function (request, env, ctx) {
3110
+ return new Response("Hello World!");
3111
+ }
3112
+ `;
3113
+ setMockFetchDashScript([
3114
+ { name: "index.js", contents: indexjs },
3115
+ { name: "nested/other.js", contents: otherjs },
3116
+ ]);
3117
+ mockConfirm(
3118
+ {
3119
+ text: "Would you like to use git to manage this Worker?",
3120
+ result: false,
3121
+ },
3122
+ {
3123
+ text: "No package.json found. Would you like to create one?",
3124
+ result: true,
3125
+ },
3126
+ {
3127
+ text: "Would you like to use TypeScript?",
3128
+ result: false,
3129
+ }
3130
+ );
3131
+
3132
+ await runWrangler("init --from-dash isolinear-optical-chip");
3133
+
3134
+ checkFiles({
3135
+ items: {
3136
+ "isolinear-optical-chip/src/index.js": {
3137
+ contents: indexjs,
3138
+ },
3139
+ "isolinear-optical-chip/src/nested/other.js": {
3140
+ contents: otherjs,
3141
+ },
3142
+ "isolinear-optical-chip/src/index.ts": false,
3143
+ "isolinear-optical-chip/package.json": {
3144
+ contents: expect.objectContaining({
3145
+ name: "isolinear-optical-chip",
3146
+ }),
3147
+ },
3148
+ "isolinear-optical-chip/tsconfig.json": false,
3149
+ "isolinear-optical-chip/wrangler.toml": wranglerToml({
3150
+ ...mockConfigExpected,
3151
+ name: "isolinear-optical-chip",
3152
+ main: "src/index.js",
3153
+ }),
3154
+ },
3155
+ });
3156
+ });
2810
3157
  });
2811
3158
  });
2812
3159
 
3160
+ function getDefaultBranchName() {
3161
+ try {
3162
+ const { stdout: defaultBranchName } = execaSync("git", [
3163
+ "config",
3164
+ "--get",
3165
+ "init.defaultBranch",
3166
+ ]);
3167
+
3168
+ return defaultBranchName;
3169
+ } catch {
3170
+ // ew
3171
+ return "master";
3172
+ }
3173
+ }
3174
+
3175
+ /**
3176
+ * Mock setter for usage within test blocks for dashboard script
3177
+ */
3178
+ export function setMockFetchDashScript(
3179
+ mockResponse: string | { name: string; contents: string }[]
3180
+ ) {
3181
+ msw.use(
3182
+ rest.get(
3183
+ `*/accounts/:accountId/workers/services/:fromDashScriptName/environments/:environment/content`,
3184
+ (_, res, ctx) => {
3185
+ if (typeof mockResponse === "string") {
3186
+ return res(ctx.text(mockResponse));
3187
+ }
3188
+
3189
+ const fd = new FormData();
3190
+
3191
+ for (const { name, contents } of mockResponse) {
3192
+ fd.set(name, contents);
3193
+ }
3194
+
3195
+ const boundary = "--------boundary-12761293712";
3196
+ const responseText =
3197
+ `--${boundary}\r\n` +
3198
+ mockResponse
3199
+ .map(
3200
+ ({ name, contents }) =>
3201
+ `Content-Disposition: form-data; name="${name}"\r\n\r\n${contents}`
3202
+ )
3203
+ .join(`\r\n--${boundary}\r\n`) +
3204
+ `\r\n--${boundary}--`;
3205
+
3206
+ return res(
3207
+ ctx.set("Content-Type", `multipart/form-data; boundary=${boundary}`),
3208
+ ctx.body(responseText)
3209
+ );
3210
+ }
3211
+ )
3212
+ );
3213
+ }
3214
+
2813
3215
  /**
2814
3216
  * Change the current working directory, ensuring that this exists.
2815
3217
  */