wrangler 0.0.0-e7a0cd5b → 0.0.0-e7cf0caa

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