wrangler 0.0.0-e87ad068 → 0.0.0-e8a2a1d9

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 (322) hide show
  1. package/README.md +10 -12
  2. package/bin/wrangler.js +13 -74
  3. package/package.json +213 -199
  4. package/templates/__tests__/tsconfig.json +1 -1
  5. package/templates/checked-fetch.js +10 -3
  6. package/templates/facade.d.ts +4 -1
  7. package/templates/middleware/common.ts +9 -4
  8. package/templates/middleware/loader-modules.ts +64 -11
  9. package/templates/middleware/loader-sw.ts +2 -7
  10. package/templates/middleware/middleware-d1-beta.d.ts +3 -0
  11. package/templates/middleware/middleware-miniflare3-json-error.ts +1 -0
  12. package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
  13. package/templates/middleware/middleware-multiworker-dev.ts +68 -0
  14. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  15. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  16. package/templates/modules-watch-stub.js +4 -0
  17. package/templates/new-worker-scheduled.ts +1 -1
  18. package/templates/new-worker.ts +1 -1
  19. package/templates/pages-shim.ts +0 -3
  20. package/templates/pages-template-plugin.ts +12 -2
  21. package/templates/pages-template-worker.ts +11 -2
  22. package/templates/startDevWorker/InspectorProxyWorker.ts +652 -0
  23. package/templates/startDevWorker/ProxyWorker.ts +252 -0
  24. package/templates/tsconfig.json +1 -1
  25. package/wrangler-dist/InspectorProxyWorker.js +460 -0
  26. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  27. package/wrangler-dist/ProxyWorker.js +186 -0
  28. package/wrangler-dist/ProxyWorker.js.map +6 -0
  29. package/wrangler-dist/cli.d.ts +21989 -199
  30. package/wrangler-dist/cli.js +110619 -103132
  31. package/wrangler-dist/wasm-sync.wasm +0 -0
  32. package/import_meta_url.js +0 -3
  33. package/miniflare-config-stubs/.env.empty +0 -0
  34. package/miniflare-config-stubs/package.empty.json +0 -1
  35. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  36. package/miniflare-dist/index.mjs +0 -6442
  37. package/src/__tests__/access.test.ts +0 -25
  38. package/src/__tests__/api-dev.test.ts +0 -238
  39. package/src/__tests__/api-devregistry.test.ts +0 -121
  40. package/src/__tests__/api.test.ts +0 -102
  41. package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
  42. package/src/__tests__/config-cache.test.ts +0 -42
  43. package/src/__tests__/configuration.test.ts +0 -4727
  44. package/src/__tests__/constellation.test.ts +0 -371
  45. package/src/__tests__/d1/d1.test.ts +0 -82
  46. package/src/__tests__/d1/execute.test.ts +0 -66
  47. package/src/__tests__/d1/migrate.test.ts +0 -257
  48. package/src/__tests__/d1/splitter.test.ts +0 -255
  49. package/src/__tests__/delete.test.ts +0 -272
  50. package/src/__tests__/deployments.test.ts +0 -369
  51. package/src/__tests__/dev.test.tsx +0 -1617
  52. package/src/__tests__/generate.test.ts +0 -237
  53. package/src/__tests__/get-host-from-url.test.ts +0 -16
  54. package/src/__tests__/guess-worker-format.test.ts +0 -120
  55. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  56. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  57. package/src/__tests__/helpers/end-event-loop.ts +0 -6
  58. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  59. package/src/__tests__/helpers/mock-auth-domain.ts +0 -20
  60. package/src/__tests__/helpers/mock-bin.ts +0 -36
  61. package/src/__tests__/helpers/mock-console.ts +0 -112
  62. package/src/__tests__/helpers/mock-dialogs.ts +0 -139
  63. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +0 -25
  64. package/src/__tests__/helpers/mock-get-zone-from-host.ts +0 -11
  65. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  66. package/src/__tests__/helpers/mock-istty.ts +0 -74
  67. package/src/__tests__/helpers/mock-known-routes.ts +0 -12
  68. package/src/__tests__/helpers/mock-kv.ts +0 -46
  69. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -263
  70. package/src/__tests__/helpers/mock-process.ts +0 -34
  71. package/src/__tests__/helpers/mock-set-timeout.ts +0 -16
  72. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  73. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  74. package/src/__tests__/helpers/msw/blob-worker.cjs +0 -19
  75. package/src/__tests__/helpers/msw/handlers/access.ts +0 -13
  76. package/src/__tests__/helpers/msw/handlers/deployments.ts +0 -160
  77. package/src/__tests__/helpers/msw/handlers/namespaces.ts +0 -81
  78. package/src/__tests__/helpers/msw/handlers/oauth.ts +0 -31
  79. package/src/__tests__/helpers/msw/handlers/r2.ts +0 -60
  80. package/src/__tests__/helpers/msw/handlers/script.ts +0 -56
  81. package/src/__tests__/helpers/msw/handlers/user.ts +0 -52
  82. package/src/__tests__/helpers/msw/handlers/zones.ts +0 -20
  83. package/src/__tests__/helpers/msw/index.ts +0 -52
  84. package/src/__tests__/helpers/msw/read-file-sync.js +0 -61
  85. package/src/__tests__/helpers/run-in-tmp.ts +0 -38
  86. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  87. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +0 -28
  88. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +0 -1
  89. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +0 -5
  90. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +0 -1
  91. package/src/__tests__/helpers/worker-scripts/parent-worker.js +0 -11
  92. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +0 -5
  93. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  94. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  95. package/src/__tests__/https-options.test.ts +0 -163
  96. package/src/__tests__/index.test.ts +0 -282
  97. package/src/__tests__/init.test.ts +0 -3302
  98. package/src/__tests__/jest.setup.ts +0 -179
  99. package/src/__tests__/kv.test.ts +0 -1799
  100. package/src/__tests__/logger.test.ts +0 -207
  101. package/src/__tests__/logout.test.ts +0 -47
  102. package/src/__tests__/metrics.test.ts +0 -493
  103. package/src/__tests__/middleware.scheduled.test.ts +0 -145
  104. package/src/__tests__/middleware.test.ts +0 -816
  105. package/src/__tests__/mtls-certificates.test.ts +0 -589
  106. package/src/__tests__/package-manager.test.ts +0 -353
  107. package/src/__tests__/pages/deployment-list.test.ts +0 -80
  108. package/src/__tests__/pages/functions-build.test.ts +0 -529
  109. package/src/__tests__/pages/pages.test.ts +0 -81
  110. package/src/__tests__/pages/project-create.test.ts +0 -63
  111. package/src/__tests__/pages/project-list.test.ts +0 -110
  112. package/src/__tests__/pages/project-upload.test.ts +0 -500
  113. package/src/__tests__/pages/publish.test.ts +0 -2864
  114. package/src/__tests__/pages-deployment-tail.test.ts +0 -957
  115. package/src/__tests__/parse.test.ts +0 -436
  116. package/src/__tests__/paths.test.ts +0 -39
  117. package/src/__tests__/publish.test.ts +0 -8882
  118. package/src/__tests__/pubsub.test.ts +0 -496
  119. package/src/__tests__/queues.test.ts +0 -532
  120. package/src/__tests__/r2.test.ts +0 -374
  121. package/src/__tests__/route.test.ts +0 -45
  122. package/src/__tests__/secret.test.ts +0 -693
  123. package/src/__tests__/tail.test.ts +0 -1000
  124. package/src/__tests__/test-old-node-version.js +0 -31
  125. package/src/__tests__/traverse-module-graph.test.ts +0 -220
  126. package/src/__tests__/tsconfig-sanity.ts +0 -12
  127. package/src/__tests__/tsconfig.json +0 -8
  128. package/src/__tests__/tsconfig.tsbuildinfo +0 -1
  129. package/src/__tests__/type-generation.test.ts +0 -234
  130. package/src/__tests__/unstableDev.test.ts +0 -61
  131. package/src/__tests__/user.test.ts +0 -118
  132. package/src/__tests__/utils-collectKeyValues.test.ts +0 -47
  133. package/src/__tests__/validate-dev-props.test.ts +0 -56
  134. package/src/__tests__/version.test.ts +0 -35
  135. package/src/__tests__/whoami.test.tsx +0 -172
  136. package/src/__tests__/worker-namespace.test.ts +0 -340
  137. package/src/abort.d.ts +0 -3
  138. package/src/api/dev.ts +0 -328
  139. package/src/api/index.ts +0 -11
  140. package/src/api/mtls-certificate.ts +0 -148
  141. package/src/api/pages/create-worker-bundle-contents.ts +0 -80
  142. package/src/api/pages/index.ts +0 -5
  143. package/src/api/pages/publish.tsx +0 -371
  144. package/src/bundle-reporter.ts +0 -68
  145. package/src/bundle.ts +0 -952
  146. package/src/cfetch/index.ts +0 -158
  147. package/src/cfetch/internal.ts +0 -263
  148. package/src/cli.ts +0 -28
  149. package/src/config/README.md +0 -107
  150. package/src/config/config.ts +0 -282
  151. package/src/config/diagnostics.ts +0 -80
  152. package/src/config/environment.ts +0 -659
  153. package/src/config/index.ts +0 -424
  154. package/src/config/validation-helpers.ts +0 -597
  155. package/src/config/validation.ts +0 -2524
  156. package/src/config-cache.ts +0 -85
  157. package/src/constellation/createProject.tsx +0 -51
  158. package/src/constellation/deleteProject.ts +0 -51
  159. package/src/constellation/deleteProjectModel.ts +0 -76
  160. package/src/constellation/index.ts +0 -75
  161. package/src/constellation/listCatalog.tsx +0 -35
  162. package/src/constellation/listModel.tsx +0 -49
  163. package/src/constellation/listProject.tsx +0 -28
  164. package/src/constellation/listRuntime.tsx +0 -28
  165. package/src/constellation/options.ts +0 -17
  166. package/src/constellation/types.ts +0 -17
  167. package/src/constellation/uploadModel.tsx +0 -84
  168. package/src/constellation/utils.ts +0 -90
  169. package/src/create-worker-preview.ts +0 -293
  170. package/src/create-worker-upload-form.ts +0 -384
  171. package/src/d1/backups.tsx +0 -219
  172. package/src/d1/constants.ts +0 -5
  173. package/src/d1/create.tsx +0 -102
  174. package/src/d1/delete.ts +0 -53
  175. package/src/d1/execute.tsx +0 -371
  176. package/src/d1/formatTimeAgo.ts +0 -14
  177. package/src/d1/index.ts +0 -100
  178. package/src/d1/list.tsx +0 -62
  179. package/src/d1/migrations/apply.tsx +0 -235
  180. package/src/d1/migrations/create.tsx +0 -79
  181. package/src/d1/migrations/helpers.ts +0 -171
  182. package/src/d1/migrations/index.ts +0 -3
  183. package/src/d1/migrations/list.tsx +0 -95
  184. package/src/d1/migrations/options.ts +0 -23
  185. package/src/d1/options.ts +0 -22
  186. package/src/d1/splitter.ts +0 -161
  187. package/src/d1/types.ts +0 -32
  188. package/src/d1/utils.ts +0 -49
  189. package/src/delete.ts +0 -100
  190. package/src/deployments.ts +0 -368
  191. package/src/deprecated/index.ts +0 -144
  192. package/src/dev/dev-vars.ts +0 -39
  193. package/src/dev/dev.tsx +0 -607
  194. package/src/dev/get-local-persistence-path.ts +0 -31
  195. package/src/dev/local.tsx +0 -952
  196. package/src/dev/remote.tsx +0 -636
  197. package/src/dev/start-server.ts +0 -558
  198. package/src/dev/use-esbuild.ts +0 -230
  199. package/src/dev/validate-dev-props.ts +0 -40
  200. package/src/dev-registry.ts +0 -213
  201. package/src/dev.tsx +0 -946
  202. package/src/dialogs.ts +0 -136
  203. package/src/dispatch-namespace.ts +0 -211
  204. package/src/docs/helpers.ts +0 -50
  205. package/src/docs/index.ts +0 -54
  206. package/src/durable.ts +0 -102
  207. package/src/entry.ts +0 -344
  208. package/src/environment-variables/factory.ts +0 -89
  209. package/src/environment-variables/misc-variables.ts +0 -30
  210. package/src/errors.ts +0 -11
  211. package/src/generate/index.ts +0 -303
  212. package/src/git-client.ts +0 -135
  213. package/src/global-wrangler-config-path.ts +0 -26
  214. package/src/https-options.ts +0 -127
  215. package/src/index.ts +0 -769
  216. package/src/init.ts +0 -1074
  217. package/src/inspect.ts +0 -883
  218. package/src/intl-polyfill.d.ts +0 -139
  219. package/src/is-ci.ts +0 -14
  220. package/src/is-interactive.ts +0 -16
  221. package/src/jest.d.ts +0 -4
  222. package/src/kv/helpers.ts +0 -433
  223. package/src/kv/index.ts +0 -594
  224. package/src/logger.ts +0 -123
  225. package/src/metrics/index.ts +0 -5
  226. package/src/metrics/metrics-config.ts +0 -239
  227. package/src/metrics/metrics-dispatcher.ts +0 -96
  228. package/src/metrics/metrics-usage-headers.ts +0 -24
  229. package/src/metrics/send-event.ts +0 -99
  230. package/src/miniflare-cli/README.md +0 -30
  231. package/src/miniflare-cli/assets.ts +0 -251
  232. package/src/miniflare-cli/index.ts +0 -210
  233. package/src/miniflare-cli/request-context.ts +0 -40
  234. package/src/miniflare-cli/tsconfig.json +0 -9
  235. package/src/miniflare-cli/tsconfig.tsbuildinfo +0 -1
  236. package/src/miniflare-cli/types.ts +0 -11
  237. package/src/module-collection.ts +0 -333
  238. package/src/mtls-certificate/cli.ts +0 -155
  239. package/src/open-in-browser.ts +0 -17
  240. package/src/package-manager.ts +0 -219
  241. package/src/pages/build.ts +0 -423
  242. package/src/pages/buildFunctions.ts +0 -140
  243. package/src/pages/constants.ts +0 -18
  244. package/src/pages/deployment-tails.ts +0 -281
  245. package/src/pages/deployments.tsx +0 -84
  246. package/src/pages/dev.ts +0 -759
  247. package/src/pages/errors.ts +0 -67
  248. package/src/pages/functions/buildPlugin.ts +0 -114
  249. package/src/pages/functions/buildWorker.ts +0 -381
  250. package/src/pages/functions/filepath-routing.test.ts +0 -234
  251. package/src/pages/functions/filepath-routing.ts +0 -189
  252. package/src/pages/functions/identifiers.ts +0 -78
  253. package/src/pages/functions/routes-consolidation.test.ts +0 -250
  254. package/src/pages/functions/routes-consolidation.ts +0 -73
  255. package/src/pages/functions/routes-transformation.test.ts +0 -282
  256. package/src/pages/functions/routes-transformation.ts +0 -115
  257. package/src/pages/functions/routes-validation.test.ts +0 -403
  258. package/src/pages/functions/routes-validation.ts +0 -202
  259. package/src/pages/functions/routes.ts +0 -151
  260. package/src/pages/functions/tsconfig.json +0 -8
  261. package/src/pages/functions/tsconfig.tsbuildinfo +0 -1
  262. package/src/pages/functions.ts +0 -86
  263. package/src/pages/hash.ts +0 -13
  264. package/src/pages/index.ts +0 -102
  265. package/src/pages/projects.tsx +0 -159
  266. package/src/pages/prompt-select-project.tsx +0 -31
  267. package/src/pages/publish.tsx +0 -267
  268. package/src/pages/types.ts +0 -46
  269. package/src/pages/upload.tsx +0 -469
  270. package/src/pages/utils.ts +0 -23
  271. package/src/parse.ts +0 -308
  272. package/src/paths.ts +0 -71
  273. package/src/proxy.ts +0 -694
  274. package/src/publish/index.ts +0 -274
  275. package/src/publish/publish.ts +0 -1068
  276. package/src/pubsub/index.ts +0 -286
  277. package/src/pubsub/pubsub-commands.ts +0 -623
  278. package/src/queues/cli/commands/consumer/add.ts +0 -71
  279. package/src/queues/cli/commands/consumer/index.ts +0 -19
  280. package/src/queues/cli/commands/consumer/remove.ts +0 -31
  281. package/src/queues/cli/commands/create.ts +0 -25
  282. package/src/queues/cli/commands/delete.ts +0 -26
  283. package/src/queues/cli/commands/index.ts +0 -35
  284. package/src/queues/cli/commands/list.ts +0 -25
  285. package/src/queues/client.ts +0 -136
  286. package/src/queues/utils.ts +0 -18
  287. package/src/r2/constants.ts +0 -4
  288. package/src/r2/helpers.ts +0 -132
  289. package/src/r2/index.ts +0 -289
  290. package/src/routes.ts +0 -140
  291. package/src/secret/index.ts +0 -380
  292. package/src/selfsigned.d.ts +0 -29
  293. package/src/sites.ts +0 -484
  294. package/src/tail/createTail.ts +0 -415
  295. package/src/tail/filters.ts +0 -277
  296. package/src/tail/index.ts +0 -211
  297. package/src/tail/printing.ts +0 -134
  298. package/src/traverse-module-graph.ts +0 -54
  299. package/src/tsconfig-sanity.ts +0 -16
  300. package/src/type-generation.ts +0 -187
  301. package/src/update-check.ts +0 -19
  302. package/src/user/access.ts +0 -68
  303. package/src/user/auth-variables.ts +0 -113
  304. package/src/user/choose-account.tsx +0 -39
  305. package/src/user/generate-auth-url.ts +0 -33
  306. package/src/user/generate-random-state.ts +0 -16
  307. package/src/user/index.ts +0 -2
  308. package/src/user/user.ts +0 -1234
  309. package/src/utils/collectKeyValues.ts +0 -14
  310. package/src/utils/render.ts +0 -93
  311. package/src/whoami.ts +0 -135
  312. package/src/worker.ts +0 -300
  313. package/src/yargs-types.ts +0 -37
  314. package/src/zones.ts +0 -191
  315. package/templates/__tests__/tsconfig.tsbuildinfo +0 -1
  316. package/templates/d1-beta-facade.js +0 -244
  317. package/templates/first-party-worker-module-facade.ts +0 -19
  318. package/templates/format-dev-errors.ts +0 -34
  319. package/templates/serve-static-assets.ts +0 -66
  320. package/templates/service-bindings-module-facade.js +0 -55
  321. package/templates/service-bindings-sw-facade.js +0 -42
  322. package/templates/tsconfig.tsbuildinfo +0 -1
@@ -1,3302 +0,0 @@
1
- import * as fs from "node:fs";
2
- import path from "node:path";
3
- import * as TOML from "@iarna/toml";
4
- import { execa, execaSync } from "execa";
5
- import { rest } from "msw";
6
- import { parseConfigFileTextToJson } from "typescript";
7
- import { FormData } from "undici";
8
- import { version as wranglerVersion } from "../../package.json";
9
- import { getPackageManager } from "../package-manager";
10
- import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
11
- import { mockConsoleMethods } from "./helpers/mock-console";
12
- import { clearDialogs, mockConfirm, mockSelect } from "./helpers/mock-dialogs";
13
- import { useMockIsTTY } from "./helpers/mock-istty";
14
- import { msw } from "./helpers/msw";
15
- import { runInTempDir } from "./helpers/run-in-tmp";
16
- import { runWrangler } from "./helpers/run-wrangler";
17
- import type { PackageManager } from "../package-manager";
18
-
19
- /**
20
- * An expectation matcher for the minimal generated wrangler.toml.
21
- */
22
- const MINIMAL_WRANGLER_TOML = {
23
- compatibility_date: expect.any(String),
24
- name: expect.stringContaining("wrangler-tests"),
25
- main: "src/index.ts",
26
- };
27
-
28
- describe("init", () => {
29
- let mockPackageManager: PackageManager;
30
- runInTempDir();
31
- const { setIsTTY } = useMockIsTTY();
32
-
33
- beforeEach(() => {
34
- setIsTTY(true);
35
-
36
- mockPackageManager = {
37
- cwd: process.cwd(),
38
- // @ts-expect-error we're making a fake package manager here
39
- type: "mockpm",
40
- addDevDeps: jest.fn(),
41
- install: jest.fn(),
42
- };
43
- (getPackageManager as jest.Mock).mockResolvedValue(mockPackageManager);
44
- });
45
-
46
- afterEach(() => {
47
- clearDialogs();
48
- });
49
-
50
- const std = mockConsoleMethods();
51
-
52
- describe("options", () => {
53
- it("should initialize with no interactive prompts if `--yes` is used", async () => {
54
- await runWrangler("init --yes");
55
-
56
- checkFiles({
57
- items: {
58
- "./src/index.js": false,
59
- "./src/index.ts": true,
60
- "./tsconfig.json": true,
61
- "./package.json": true,
62
- "./wrangler.toml": true,
63
- },
64
- });
65
-
66
- expect(std.out).toMatchInlineSnapshot(`
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
74
-
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
- `);
79
- expect(std.err).toMatchInlineSnapshot(`""`);
80
- expect(std.warn).toMatchInlineSnapshot(`""`);
81
- });
82
-
83
- it("should initialize with no interactive prompts if `--yes` is used (named worker)", async () => {
84
- await runWrangler("init my-worker --yes");
85
-
86
- checkFiles({
87
- items: {
88
- "./my-worker/src/index.js": false,
89
- "./my-worker/src/index.ts": true,
90
- "./my-worker/tsconfig.json": true,
91
- "./my-worker/package.json": true,
92
- "./my-worker/wrangler.toml": wranglerToml({
93
- ...MINIMAL_WRANGLER_TOML,
94
- name: "my-worker",
95
- }),
96
- },
97
- });
98
-
99
- expect(std.out).toMatchInlineSnapshot(`
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
- `);
112
- expect(std.err).toMatchInlineSnapshot(`""`);
113
- expect(std.warn).toMatchInlineSnapshot(`""`);
114
- });
115
-
116
- it("should initialize with no interactive prompts if `-y` is used", async () => {
117
- await runWrangler("init -y");
118
-
119
- checkFiles({
120
- items: {
121
- "./src/index.js": false,
122
- "./src/index.ts": true,
123
- "./tsconfig.json": true,
124
- "./package.json": true,
125
- "./wrangler.toml": true,
126
- },
127
- });
128
-
129
- expect(std).toMatchInlineSnapshot(`
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
141
-
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
- `);
148
- });
149
-
150
- it("should error if `--type javascript` is used", async () => {
151
- await expect(
152
- runWrangler("init --type javascript")
153
- ).rejects.toThrowErrorMatchingInlineSnapshot(
154
- `"The --type option is no longer supported."`
155
- );
156
- });
157
-
158
- it("should error if `--type rust` is used", async () => {
159
- await expect(
160
- runWrangler("init --type rust")
161
- ).rejects.toThrowErrorMatchingInlineSnapshot(
162
- `"The --type option is no longer supported."`
163
- );
164
- });
165
-
166
- it("should error if `--type webpack` is used", async () => {
167
- await expect(runWrangler("init --type webpack")).rejects
168
- .toThrowErrorMatchingInlineSnapshot(`
169
- "The --type option is no longer supported.
170
- If you wish to use webpack then you will need to create a custom build."
171
- `);
172
- });
173
-
174
- it("should error if `--site` is used", async () => {
175
- await expect(runWrangler("init --site")).rejects
176
- .toThrowErrorMatchingInlineSnapshot(`
177
- "The --site option is no longer supported.
178
- If you wish to create a brand new Worker Sites project then clone the \`worker-sites-template\` starter repository:
179
-
180
- \`\`\`
181
- git clone --depth=1 --branch=wrangler2 https://github.com/cloudflare/worker-sites-template my-site
182
- cd my-site
183
- \`\`\`
184
-
185
- Find out more about how to create and maintain Sites projects at https://developers.cloudflare.com/workers/platform/sites.
186
- Have you considered using Cloudflare Pages instead? See https://pages.cloudflare.com/."
187
- `);
188
- });
189
- });
190
-
191
- describe("wrangler.toml", () => {
192
- it("should create a wrangler.toml", async () => {
193
- mockConfirm(
194
- {
195
- text: "Would you like to use git to manage this Worker?",
196
- result: false,
197
- },
198
- {
199
- text: "No package.json found. Would you like to create one?",
200
- result: false,
201
- }
202
- );
203
- await runWrangler("init");
204
- checkFiles({
205
- items: {
206
- "wrangler.toml": wranglerToml({
207
- compatibility_date: expect.any(String),
208
- name: expect.stringContaining("wrangler-tests"),
209
- }),
210
- "package.json": false,
211
- "tsconfig.json": false,
212
- },
213
- });
214
-
215
- expect(std).toMatchInlineSnapshot(`
216
- Object {
217
- "debug": "",
218
- "err": "",
219
- "info": "",
220
- "out": "✨ Created wrangler.toml",
221
- "warn": "",
222
- }
223
- `);
224
- });
225
-
226
- it("should create a wrangler.toml and a directory for a named Worker ", async () => {
227
- mockConfirm(
228
- {
229
- text: "Would you like to use git to manage this Worker?",
230
- result: false,
231
- },
232
- {
233
- text: "No package.json found. Would you like to create one?",
234
- result: false,
235
- }
236
- );
237
- await runWrangler("init my-worker");
238
-
239
- checkFiles({
240
- items: {
241
- "my-worker/wrangler.toml": wranglerToml({
242
- compatibility_date: expect.any(String),
243
- name: "my-worker",
244
- }),
245
- "my-worker/package.json": false,
246
- "my-worker/tsconfig.json": false,
247
- },
248
- });
249
-
250
- expect(std).toMatchInlineSnapshot(`
251
- Object {
252
- "debug": "",
253
- "err": "",
254
- "info": "",
255
- "out": "✨ Created my-worker/wrangler.toml",
256
- "warn": "",
257
- }
258
- `);
259
- });
260
-
261
- it("should display warning when wrangler.toml already exists, and exit if user does not want to carry on", async () => {
262
- writeFiles({
263
- items: {
264
- "wrangler.toml": wranglerToml({
265
- // use a fake value to make sure the file is not overwritten
266
- compatibility_date: "something-else",
267
- }),
268
- },
269
- });
270
-
271
- mockConfirm({
272
- text: "Do you want to continue initializing this project?",
273
- result: false,
274
- });
275
-
276
- await runWrangler("init");
277
- expect(std.warn).toContain("wrangler.toml already exists!");
278
-
279
- checkFiles({
280
- items: {
281
- "wrangler.toml": wranglerToml({
282
- compatibility_date: "something-else",
283
- }),
284
- "package.json": false,
285
- "tsconfig.json": false,
286
- },
287
- });
288
-
289
- expect(std).toMatchInlineSnapshot(`
290
- Object {
291
- "debug": "",
292
- "err": "",
293
- "info": "",
294
- "out": "",
295
- "warn": "▲ [WARNING] wrangler.toml already exists!
296
-
297
- ",
298
- }
299
- `);
300
- });
301
-
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 () => {
303
- writeFiles({
304
- items: {
305
- "path/to/worker/wrangler.toml": wranglerToml({
306
- compatibility_date: "something-else",
307
- }),
308
- },
309
- });
310
- mockConfirm({
311
- text: "Do you want to continue initializing this project?",
312
- result: false,
313
- });
314
-
315
- await runWrangler("init path/to/worker");
316
-
317
- expect(std.warn).toContain("wrangler.toml already exists!");
318
- checkFiles({
319
- items: {
320
- "path/to/worker/wrangler.toml": wranglerToml({
321
- compatibility_date: "something-else",
322
- }),
323
- "package.json": false,
324
- "tsconfig.json": false,
325
- },
326
- });
327
- expect(std).toMatchInlineSnapshot(`
328
- Object {
329
- "debug": "",
330
- "err": "",
331
- "info": "",
332
- "out": "",
333
- "warn": "▲ [WARNING] path/to/worker/wrangler.toml already exists!
334
-
335
- ",
336
- }
337
- `);
338
- });
339
-
340
- it("should not overwrite an existing wrangler.toml, after agreeing to other prompts", async () => {
341
- writeFiles({
342
- items: {
343
- "wrangler.toml": wranglerToml({
344
- compatibility_date: "something-else",
345
- }),
346
- },
347
- });
348
- mockConfirm(
349
- {
350
- text: "Do you want to continue initializing this project?",
351
- result: true,
352
- },
353
- {
354
- text: "Would you like to use git to manage this Worker?",
355
- result: true,
356
- },
357
- {
358
- text: "No package.json found. Would you like to create one?",
359
- result: true,
360
- },
361
- {
362
- text: "Would you like to use TypeScript?",
363
- result: true,
364
- }
365
- );
366
-
367
- mockSelect({
368
- text: `Would you like to create a Worker at ${path.join(
369
- "src",
370
- "index.ts"
371
- )}?`,
372
- result: "fetch",
373
- });
374
- mockConfirm({
375
- text: "Would you like us to write your first test with Vitest?",
376
- result: true,
377
- });
378
-
379
- await runWrangler("init");
380
-
381
- checkFiles({
382
- items: {
383
- "wrangler.toml": wranglerToml({
384
- compatibility_date: "something-else",
385
- }),
386
- },
387
- });
388
- });
389
-
390
- it("should display warning when wrangler.toml already exists, but continue if user does want to carry on", async () => {
391
- writeFiles({
392
- items: {
393
- "wrangler.toml": wranglerToml({
394
- compatibility_date: "something-else",
395
- }),
396
- },
397
- });
398
- mockConfirm(
399
- {
400
- text: "Do you want to continue initializing this project?",
401
- result: true,
402
- },
403
- {
404
- text: "Would you like to use git to manage this Worker?",
405
- result: false,
406
- },
407
- {
408
- text: "No package.json found. Would you like to create one?",
409
- result: false,
410
- }
411
- );
412
-
413
- await runWrangler("init");
414
-
415
- expect(std.warn).toContain("wrangler.toml already exists!");
416
- checkFiles({
417
- items: {
418
- "wrangler.toml": wranglerToml({
419
- compatibility_date: "something-else",
420
- }),
421
- },
422
- });
423
- expect(std).toMatchInlineSnapshot(`
424
- Object {
425
- "debug": "",
426
- "err": "",
427
- "info": "",
428
- "out": "",
429
- "warn": "▲ [WARNING] wrangler.toml already exists!
430
-
431
- ",
432
- }
433
- `);
434
- });
435
-
436
- it("should not add a Cron Trigger to wrangler.toml when creating a Scheduled Worker if wrangler.toml already exists", async () => {
437
- writeFiles({
438
- items: {
439
- "wrangler.toml": wranglerToml({
440
- compatibility_date: "something-else",
441
- }),
442
- },
443
- });
444
- mockConfirm(
445
- {
446
- text: "Do you want to continue initializing this project?",
447
- result: true,
448
- },
449
- {
450
- text: "Would you like to use git to manage this Worker?",
451
- result: true,
452
- },
453
-
454
- {
455
- text: "No package.json found. Would you like to create one?",
456
- result: true,
457
- },
458
- {
459
- text: "Would you like to use TypeScript?",
460
- result: true,
461
- }
462
- );
463
- mockSelect({
464
- text: `Would you like to create a Worker at ${path.join(
465
- "src",
466
- "index.ts"
467
- )}?`,
468
- result: "scheduled",
469
- });
470
-
471
- mockConfirm({
472
- text: "Would you like us to write your first test with Vitest?",
473
- result: true,
474
- });
475
- await runWrangler("init");
476
-
477
- checkFiles({
478
- items: {
479
- "wrangler.toml": wranglerToml({
480
- compatibility_date: "something-else",
481
- }),
482
- },
483
- });
484
- });
485
-
486
- it("should add a Cron Trigger to wrangler.toml when creating a Scheduled Worker, but only if wrangler.toml is being created during init", async () => {
487
- mockConfirm(
488
- {
489
- text: "Would you like to use git to manage this Worker?",
490
- result: true,
491
- },
492
- {
493
- text: "No package.json found. Would you like to create one?",
494
- result: true,
495
- },
496
- {
497
- text: "Would you like to use TypeScript?",
498
- result: true,
499
- }
500
- );
501
- mockSelect({
502
- text: `Would you like to create a Worker at ${path.join(
503
- "src",
504
- "index.ts"
505
- )}?`,
506
- result: "scheduled",
507
- });
508
- mockConfirm({
509
- text: "Would you like us to write your first test with Vitest?",
510
- result: true,
511
- });
512
- await runWrangler("init");
513
-
514
- checkFiles({
515
- items: {
516
- "wrangler.toml": wranglerToml({
517
- ...MINIMAL_WRANGLER_TOML,
518
- triggers: { crons: ["1 * * * *"] },
519
- }),
520
- },
521
- });
522
- });
523
- });
524
-
525
- describe("git init", () => {
526
- it("should offer to initialize a git repository", async () => {
527
- mockConfirm(
528
- {
529
- text: "Would you like to use git to manage this Worker?",
530
- result: true,
531
- },
532
- {
533
- text: "No package.json found. Would you like to create one?",
534
- result: false,
535
- }
536
- );
537
-
538
- await runWrangler("init");
539
-
540
- checkFiles({
541
- items: {
542
- "wrangler.toml": wranglerToml({
543
- compatibility_date: expect.any(String),
544
- name: expect.stringContaining("wrangler-tests"),
545
- }),
546
- ".git": { items: {} },
547
- ".gitignore": true,
548
- },
549
- });
550
- expect(std).toMatchInlineSnapshot(`
551
- Object {
552
- "debug": "",
553
- "err": "",
554
- "info": "",
555
- "out": "✨ Created wrangler.toml
556
- ✨ Initialized git repository",
557
- "warn": "",
558
- }
559
- `);
560
- expect((await execa("git", ["branch", "--show-current"])).stdout).toEqual(
561
- getDefaultBranchName()
562
- );
563
- });
564
-
565
- it("should not offer to initialize a git repo if it's already inside one", async () => {
566
- await execa("git", ["init"]);
567
- setWorkingDirectory("some-folder");
568
-
569
- await runWrangler("init -y");
570
-
571
- checkFiles({
572
- items: {
573
- "wrangler.toml": wranglerToml({
574
- ...MINIMAL_WRANGLER_TOML,
575
- name: "some-folder",
576
- }),
577
- ".git": { items: {} },
578
- ".gitignore": false,
579
- },
580
- });
581
-
582
- // Note the lack of "✨ Initialized git repository" in the log
583
- expect(std).toMatchInlineSnapshot(`
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
594
-
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
- `);
601
- });
602
-
603
- it("should not offer to initialize a git repo if it's already inside one (when using a path as name)", async () => {
604
- fs.mkdirSync("path/to/worker", { recursive: true });
605
- await execa("git", ["init"], { cwd: "path/to/worker" });
606
- expect(fs.lstatSync("path/to/worker/.git").isDirectory()).toBe(true);
607
-
608
- await runWrangler("init path/to/worker/my-worker -y");
609
-
610
- // Note the lack of "✨ Initialized git repository" in the log
611
- expect(std).toMatchInlineSnapshot(`
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
- `);
629
- });
630
-
631
- // I... don't know how to test this lol
632
- it.todo(
633
- "should not offer to initialize a git repo if git is not installed"
634
- );
635
-
636
- it("should initialize git repo with the user's default branch", async () => {
637
- mockConfirm(
638
- {
639
- text: "Would you like to use git to manage this Worker?",
640
- result: true,
641
- },
642
- {
643
- text: "No package.json found. Would you like to create one?",
644
- result: false,
645
- }
646
- );
647
- await runWrangler("init");
648
- expect(std).toMatchInlineSnapshot(`
649
- Object {
650
- "debug": "",
651
- "err": "",
652
- "info": "",
653
- "out": "✨ Created wrangler.toml
654
- ✨ Initialized git repository",
655
- "warn": "",
656
- }
657
- `);
658
-
659
- expect(execaSync("git", ["symbolic-ref", "HEAD"]).stdout).toEqual(
660
- `refs/heads/${getDefaultBranchName()}`
661
- );
662
- });
663
- });
664
-
665
- describe("package.json", () => {
666
- it("should create a package.json if none is found and user confirms", async () => {
667
- mockConfirm(
668
- {
669
- text: "Would you like to use git to manage this Worker?",
670
- result: false,
671
- },
672
- {
673
- text: "No package.json found. Would you like to create one?",
674
- result: true,
675
- },
676
- {
677
- text: "Would you like to use TypeScript?",
678
- result: false,
679
- }
680
- );
681
- mockSelect({
682
- text: `Would you like to create a Worker at ${path.join(
683
- "src",
684
- "index.js"
685
- )}?`,
686
- result: "none",
687
- });
688
-
689
- await runWrangler("init");
690
-
691
- checkFiles({
692
- items: {
693
- "package.json": {
694
- contents: expect.objectContaining({
695
- name: expect.stringContaining("wrangler-tests"),
696
- version: "0.0.0",
697
- devDependencies: {
698
- wrangler: expect.any(String),
699
- },
700
- }),
701
- },
702
- "tsconfig.json": false,
703
- },
704
- });
705
- expect(mockPackageManager.install).toHaveBeenCalled();
706
- expect(std).toMatchInlineSnapshot(`
707
- Object {
708
- "debug": "",
709
- "err": "",
710
- "info": "",
711
- "out": "✨ Created wrangler.toml
712
- ✨ Created package.json",
713
- "warn": "",
714
- }
715
- `);
716
- });
717
-
718
- it("should create a package.json, with the specified name, if none is found and user confirms", async () => {
719
- mockConfirm(
720
- {
721
- text: "Would you like to use git to manage this Worker?",
722
- result: false,
723
- },
724
- {
725
- text: "No package.json found. Would you like to create one?",
726
- result: true,
727
- },
728
- {
729
- text: "Would you like to use TypeScript?",
730
- result: false,
731
- }
732
- );
733
- mockSelect({
734
- text: `Would you like to create a Worker at ${path.join(
735
- "my-worker",
736
- "src",
737
- "index.js"
738
- )}?`,
739
- result: "none",
740
- });
741
-
742
- await runWrangler("init my-worker");
743
-
744
- checkFiles({
745
- items: {
746
- "my-worker/package.json": {
747
- contents: expect.objectContaining({
748
- name: "my-worker",
749
- version: "0.0.0",
750
- devDependencies: {
751
- wrangler: expect.any(String),
752
- },
753
- }),
754
- },
755
- "my-worker/tsconfig.json": false,
756
- },
757
- });
758
- expect(std).toMatchInlineSnapshot(`
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
- `);
768
- });
769
-
770
- it("should not touch an existing package.json in the same directory", async () => {
771
- mockConfirm(
772
- {
773
- text: "Would you like to use git to manage this Worker?",
774
- result: false,
775
- },
776
- {
777
- text: "Would you like to install wrangler into package.json?",
778
- result: false,
779
- },
780
- {
781
- text: "Would you like to use TypeScript?",
782
- result: false,
783
- }
784
- );
785
- mockSelect({
786
- text: `Would you like to create a Worker at ${path.join(
787
- "src",
788
- "index.js"
789
- )}?`,
790
- result: "none",
791
- });
792
- writeFiles({
793
- items: {
794
- "package.json": { contents: { name: "test", version: "1.0.0" } },
795
- },
796
- });
797
-
798
- await runWrangler("init");
799
-
800
- checkFiles({
801
- items: {
802
- "package.json": { contents: { name: "test", version: "1.0.0" } },
803
- },
804
- });
805
- expect(std).toMatchInlineSnapshot(`
806
- Object {
807
- "debug": "",
808
- "err": "",
809
- "info": "",
810
- "out": "✨ Created wrangler.toml",
811
- "warn": "",
812
- }
813
- `);
814
- });
815
-
816
- it("should not touch an existing package.json in an ancestor directory, when a name is passed", async () => {
817
- mockConfirm(
818
- {
819
- text: "Would you like to use git to manage this Worker?",
820
- result: false,
821
- },
822
- {
823
- text: "No package.json found. Would you like to create one?",
824
- result: true,
825
- },
826
- {
827
- text: "Would you like to use TypeScript?",
828
- result: false,
829
- }
830
- );
831
- mockSelect({
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
- )}?`,
840
- result: "none",
841
- });
842
- writeFiles({
843
- items: {
844
- "path/to/worker/package.json": {
845
- contents: { name: "test", version: "1.0.0" },
846
- },
847
- },
848
- });
849
-
850
- await runWrangler("init path/to/worker/my-worker");
851
-
852
- checkFiles({
853
- items: {
854
- "path/to/worker/package.json": {
855
- contents: { name: "test", version: "1.0.0" },
856
- },
857
- },
858
- });
859
- expect(std).toMatchInlineSnapshot(`
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
- `);
869
- });
870
-
871
- it("should offer to install wrangler into an existing package.json", async () => {
872
- mockConfirm(
873
- {
874
- text: "Would you like to use git to manage this Worker?",
875
- result: false,
876
- },
877
- {
878
- text: "Would you like to install wrangler into package.json?",
879
- result: true,
880
- },
881
- {
882
- text: "Would you like to use TypeScript?",
883
- result: false,
884
- }
885
- );
886
- mockSelect({
887
- text: `Would you like to create a Worker at ${path.join(
888
- "src",
889
- "index.js"
890
- )}?`,
891
- result: "none",
892
- });
893
- writeFiles({
894
- items: {
895
- "package.json": {
896
- contents: { name: "test", version: "1.0.0" },
897
- },
898
- },
899
- });
900
-
901
- await runWrangler("init");
902
-
903
- checkFiles({
904
- items: {
905
- "package.json": {
906
- contents: { name: "test", version: "1.0.0" },
907
- },
908
- },
909
- });
910
- expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
911
- `wrangler@${wranglerVersion}`
912
- );
913
- expect(std).toMatchInlineSnapshot(`
914
- Object {
915
- "debug": "",
916
- "err": "",
917
- "info": "",
918
- "out": "✨ Created wrangler.toml
919
- ✨ Installed wrangler into devDependencies",
920
- "warn": "",
921
- }
922
- `);
923
- });
924
-
925
- it("should offer to install wrangler into a package.json relative to the target directory, if no name is provided", async () => {
926
- mockConfirm(
927
- {
928
- text: "Would you like to use git to manage this Worker?",
929
- result: false,
930
- },
931
- {
932
- text: `Would you like to install wrangler into ${path.join(
933
- "..",
934
- "package.json"
935
- )}?`,
936
- result: true,
937
- },
938
- {
939
- text: "Would you like to use TypeScript?",
940
- result: false,
941
- }
942
- );
943
- mockSelect({
944
- text: `Would you like to create a Worker at ${path.join(
945
- "src",
946
- "index.js"
947
- )}?`,
948
- result: "none",
949
- });
950
- writeFiles({
951
- items: {
952
- "path/to/worker/package.json": {
953
- contents: { name: "test", version: "1.0.0" },
954
- },
955
- },
956
- });
957
- setWorkingDirectory("path/to/worker/my-worker");
958
-
959
- await runWrangler("init");
960
-
961
- setWorkingDirectory("../../../..");
962
- checkFiles({
963
- items: {
964
- "path/to/worker/package.json": {
965
- contents: { name: "test", version: "1.0.0" },
966
- },
967
- "path/to/worker/my-worker/package.json": false,
968
- },
969
- });
970
- expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
971
- `wrangler@${wranglerVersion}`
972
- );
973
- expect(mockPackageManager.cwd).toBe(process.cwd());
974
- expect(std).toMatchInlineSnapshot(`
975
- Object {
976
- "debug": "",
977
- "err": "",
978
- "info": "",
979
- "out": "✨ Created wrangler.toml
980
- ✨ Installed wrangler into devDependencies",
981
- "warn": "",
982
- }
983
- `);
984
- });
985
-
986
- it("should not touch an existing package.json in an ancestor directory", async () => {
987
- mockConfirm(
988
- {
989
- text: "Would you like to use git to manage this Worker?",
990
- result: false,
991
- },
992
- {
993
- text: `Would you like to install wrangler into ${path.join(
994
- "..",
995
- "..",
996
- "package.json"
997
- )}?`,
998
- result: false,
999
- },
1000
- {
1001
- text: "Would you like to use TypeScript?",
1002
- result: false,
1003
- }
1004
- );
1005
- mockSelect({
1006
- text: `Would you like to create a Worker at ${path.join(
1007
- "src",
1008
- "index.js"
1009
- )}?`,
1010
- result: "none",
1011
- });
1012
- writeFiles({
1013
- items: {
1014
- "package.json": {
1015
- contents: { name: "test", version: "1.0.0" },
1016
- },
1017
- },
1018
- });
1019
- setWorkingDirectory("./sub-1/sub-2");
1020
-
1021
- await runWrangler("init");
1022
-
1023
- checkFiles({
1024
- items: {
1025
- "package.json": false,
1026
- "../../package.json": {
1027
- contents: { name: "test", version: "1.0.0" },
1028
- },
1029
- },
1030
- });
1031
- expect(std).toMatchInlineSnapshot(`
1032
- Object {
1033
- "debug": "",
1034
- "err": "",
1035
- "info": "",
1036
- "out": "✨ Created wrangler.toml",
1037
- "warn": "",
1038
- }
1039
- `);
1040
- });
1041
- });
1042
-
1043
- describe("typescript", () => {
1044
- it("should offer to create a worker in a non-typescript project", async () => {
1045
- mockConfirm(
1046
- {
1047
- text: "Would you like to use git to manage this Worker?",
1048
- result: false,
1049
- },
1050
- {
1051
- text: "Would you like to install wrangler into package.json?",
1052
- result: false,
1053
- },
1054
- {
1055
- text: "Would you like to use TypeScript?",
1056
- result: false,
1057
- }
1058
- );
1059
- mockSelect({
1060
- text: `Would you like to create a Worker at ${path.join(
1061
- "src",
1062
- "index.js"
1063
- )}?`,
1064
- result: "fetch",
1065
- });
1066
- mockConfirm({
1067
- text: "Would you like us to write your first test?",
1068
- result: false,
1069
- });
1070
- writeFiles({
1071
- items: {
1072
- "package.json": {
1073
- contents: { name: "test", version: "1.0.0" },
1074
- },
1075
- },
1076
- });
1077
-
1078
- await runWrangler("init");
1079
-
1080
- checkFiles({
1081
- items: {
1082
- "wrangler.toml": wranglerToml({
1083
- ...MINIMAL_WRANGLER_TOML,
1084
- main: "src/index.js",
1085
- }),
1086
- "src/index.js": true,
1087
- "src/index.ts": false,
1088
- },
1089
- });
1090
- expect(std).toMatchInlineSnapshot(`
1091
- Object {
1092
- "debug": "",
1093
- "err": "",
1094
- "info": "",
1095
- "out": "✨ Created wrangler.toml
1096
- ✨ Created src/index.js
1097
-
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
- `);
1103
- });
1104
-
1105
- it("should offer to create a worker in a typescript project", async () => {
1106
- mockConfirm(
1107
- {
1108
- text: "Would you like to use git to manage this Worker?",
1109
- result: false,
1110
- },
1111
- {
1112
- text: "Would you like to install wrangler into package.json?",
1113
- result: false,
1114
- },
1115
- {
1116
- text: "Would you like to use TypeScript?",
1117
- result: true,
1118
- }
1119
- );
1120
- mockSelect({
1121
- text: `Would you like to create a Worker at ${path.join(
1122
- "src",
1123
- "index.ts"
1124
- )}?`,
1125
- result: "fetch",
1126
- });
1127
- mockConfirm({
1128
- text: "Would you like us to write your first test with Vitest?",
1129
- result: true,
1130
- });
1131
- writeFiles({
1132
- items: {
1133
- "package.json": {
1134
- contents: { name: "test", version: "1.0.0" },
1135
- },
1136
- },
1137
- });
1138
-
1139
- await runWrangler("init");
1140
-
1141
- checkFiles({
1142
- items: {
1143
- "src/index.js": false,
1144
- "src/index.ts": true,
1145
- },
1146
- });
1147
- expect(std).toMatchInlineSnapshot(`
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
- `);
1163
- });
1164
-
1165
- it("should add scripts for a typescript project with .ts extension", async () => {
1166
- mockConfirm(
1167
- {
1168
- text: "Would you like to use git to manage this Worker?",
1169
- result: false,
1170
- },
1171
- {
1172
- text: "No package.json found. Would you like to create one?",
1173
- result: true,
1174
- },
1175
-
1176
- {
1177
- text: "Would you like to use TypeScript?",
1178
- result: true,
1179
- }
1180
- );
1181
- mockSelect({
1182
- text: `Would you like to create a Worker at ${path.join(
1183
- "src",
1184
- "index.ts"
1185
- )}?`,
1186
- result: "fetch",
1187
- });
1188
- mockConfirm({
1189
- text: "Would you like us to write your first test with Vitest?",
1190
- result: true,
1191
- });
1192
-
1193
- await runWrangler("init");
1194
-
1195
- checkFiles({
1196
- items: {
1197
- "package.json": {
1198
- contents: expect.objectContaining({
1199
- name: expect.stringContaining("wrangler-tests"),
1200
- version: "0.0.0",
1201
- scripts: {
1202
- deploy: "wrangler publish",
1203
- start: "wrangler dev",
1204
- test: "vitest",
1205
- },
1206
- devDependencies: {
1207
- wrangler: expect.any(String),
1208
- },
1209
- }),
1210
- },
1211
- "src/index.js": false,
1212
- "src/index.ts": true,
1213
- },
1214
- });
1215
- expect(std.out).toMatchInlineSnapshot(`
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
1222
-
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
- `);
1227
- });
1228
-
1229
- it("should not overwrite package.json scripts for a typescript project", async () => {
1230
- mockConfirm(
1231
- {
1232
- text: "Would you like to use git to manage this Worker?",
1233
- result: false,
1234
- },
1235
- {
1236
- text: "Would you like to install wrangler into package.json?",
1237
- result: false,
1238
- },
1239
- {
1240
- text: "Would you like to use TypeScript?",
1241
- result: true,
1242
- }
1243
- );
1244
- mockSelect({
1245
- text: `Would you like to create a Worker at ${path.join(
1246
- "src",
1247
- "index.ts"
1248
- )}?`,
1249
- result: "fetch",
1250
- });
1251
- mockConfirm({
1252
- text: "Would you like us to write your first test with Vitest?",
1253
- result: true,
1254
- });
1255
- writeFiles({
1256
- items: {
1257
- "package.json": {
1258
- contents: {
1259
- scripts: {
1260
- start: "test-start",
1261
- deploy: "test-publish",
1262
- },
1263
- },
1264
- },
1265
- },
1266
- });
1267
-
1268
- await runWrangler("init");
1269
-
1270
- checkFiles({
1271
- items: {
1272
- "package.json": {
1273
- contents: {
1274
- scripts: {
1275
- start: "test-start",
1276
- deploy: "test-publish",
1277
- },
1278
- },
1279
- },
1280
- "src/index.js": false,
1281
- "src/index.ts": true,
1282
- },
1283
- });
1284
- expect(std.out).toMatchInlineSnapshot(`
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
1290
-
1291
- To start developing your Worker, run \`npx wrangler dev\`
1292
- To publish your Worker to the Internet, run \`npx wrangler publish\`"
1293
- `);
1294
- });
1295
-
1296
- it("should not offer to create a worker in a ts project if a file already exists at the location", async () => {
1297
- mockConfirm(
1298
- {
1299
- text: "Would you like to use git to manage this Worker?",
1300
- result: false,
1301
- },
1302
- {
1303
- text: "Would you like to install wrangler into package.json?",
1304
- result: false,
1305
- },
1306
- {
1307
- text: "Would you like to use TypeScript?",
1308
- result: true,
1309
- }
1310
- );
1311
- const PLACEHOLDER = "/* placeholder text */";
1312
- writeFiles({
1313
- items: {
1314
- "package.json": { contents: { name: "test", version: "1.0.0" } },
1315
- "src/index.ts": { contents: PLACEHOLDER },
1316
- },
1317
- });
1318
-
1319
- await runWrangler("init");
1320
-
1321
- checkFiles({
1322
- items: {
1323
- "src/index.js": false,
1324
- "src/index.ts": { contents: PLACEHOLDER },
1325
- },
1326
- });
1327
- expect(std).toMatchInlineSnapshot(`
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
- `);
1338
- });
1339
-
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 () => {
1341
- mockConfirm(
1342
- {
1343
- text: "Would you like to use git to manage this Worker?",
1344
- result: false,
1345
- },
1346
- {
1347
- text: "No package.json found. Would you like to create one?",
1348
- result: true,
1349
- },
1350
-
1351
- {
1352
- text: "Would you like to use TypeScript?",
1353
- result: true,
1354
- }
1355
- );
1356
- const PLACEHOLDER = "/* placeholder text */";
1357
- writeFiles({
1358
- items: {
1359
- "package.json": { contents: { name: "test", version: "1.0.0" } },
1360
- "my-worker/src/index.ts": { contents: PLACEHOLDER },
1361
- },
1362
- });
1363
-
1364
- await runWrangler("init my-worker");
1365
-
1366
- checkFiles({
1367
- items: {
1368
- "my-worker/src/index.js": false,
1369
- "my-worker/src/index.ts": { contents: PLACEHOLDER },
1370
- },
1371
- });
1372
- expect(std).toMatchInlineSnapshot(`
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
- `);
1384
- });
1385
-
1386
- it("should create a tsconfig.json and install `workers-types` if none is found and user confirms", async () => {
1387
- mockConfirm(
1388
- {
1389
- text: "Would you like to use git to manage this Worker?",
1390
- result: false,
1391
- },
1392
- {
1393
- text: "No package.json found. Would you like to create one?",
1394
- result: true,
1395
- },
1396
- {
1397
- text: "Would you like to use TypeScript?",
1398
- result: true,
1399
- }
1400
- );
1401
- mockSelect({
1402
- text: `Would you like to create a Worker at ${path.join(
1403
- "src",
1404
- "index.ts"
1405
- )}?`,
1406
- result: "none",
1407
- });
1408
-
1409
- await runWrangler("init");
1410
-
1411
- checkFiles({
1412
- items: {
1413
- "tsconfig.json": {
1414
- contents: {
1415
- config: {
1416
- compilerOptions: expect.objectContaining({
1417
- types: ["@cloudflare/workers-types"],
1418
- }),
1419
- },
1420
- error: undefined,
1421
- },
1422
- },
1423
- },
1424
- });
1425
- expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
1426
- "@cloudflare/workers-types",
1427
- "typescript"
1428
- );
1429
- expect(std).toMatchInlineSnapshot(`
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
- `);
1441
- });
1442
-
1443
- it("should not touch an existing tsconfig.json in the same directory", async () => {
1444
- mockConfirm({
1445
- text: "Would you like to use git to manage this Worker?",
1446
- result: false,
1447
- });
1448
- mockSelect({
1449
- text: `Would you like to create a Worker at ${path.join(
1450
- "src",
1451
- "index.ts"
1452
- )}?`,
1453
- result: "fetch",
1454
- });
1455
- mockConfirm({
1456
- text: "Would you like us to write your first test with Vitest?",
1457
- result: true,
1458
- });
1459
- writeFiles({
1460
- items: {
1461
- "package.json": {
1462
- contents: {
1463
- name: "test",
1464
- version: "1.0.0",
1465
- devDependencies: {
1466
- wrangler: "0.0.0",
1467
- "@cloudflare/workers-types": "0.0.0",
1468
- },
1469
- },
1470
- },
1471
- "tsconfig.json": { contents: { compilerOptions: {} } },
1472
- },
1473
- });
1474
-
1475
- await runWrangler("init");
1476
-
1477
- checkFiles({
1478
- items: {
1479
- "tsconfig.json": {
1480
- contents: { config: { compilerOptions: {} }, error: undefined },
1481
- },
1482
- },
1483
- });
1484
- expect(std).toMatchInlineSnapshot(`
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
1493
-
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
- `);
1499
- });
1500
-
1501
- it("should not touch an existing tsconfig.json in the ancestor of a target directory, if a name is passed", async () => {
1502
- mockConfirm(
1503
- {
1504
- text: "Would you like to use git to manage this Worker?",
1505
- result: false,
1506
- },
1507
- {
1508
- text: "No package.json found. Would you like to create one?",
1509
- result: true,
1510
- },
1511
- {
1512
- text: "Would you like to use TypeScript?",
1513
- result: true,
1514
- }
1515
- );
1516
- mockSelect({
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
- )}?`,
1525
- result: "fetch",
1526
- });
1527
- mockConfirm({
1528
- text: "Would you like us to write your first test with Vitest?",
1529
- result: true,
1530
- });
1531
- writeFiles({
1532
- items: {
1533
- "path/to/worker/package.json": {
1534
- contents: {
1535
- name: "test",
1536
- version: "1.0.0",
1537
- devDependencies: {
1538
- wrangler: "0.0.0",
1539
- "@cloudflare/workers-types": "0.0.0",
1540
- },
1541
- },
1542
- },
1543
- "path/to/worker/tsconfig.json": { contents: { compilerOptions: {} } },
1544
- },
1545
- });
1546
-
1547
- await runWrangler("init path/to/worker/my-worker");
1548
-
1549
- checkFiles({
1550
- items: {
1551
- "path/to/worker/tsconfig.json": {
1552
- contents: { config: { compilerOptions: {}, error: undefined } },
1553
- },
1554
- },
1555
- });
1556
- expect(std).toMatchInlineSnapshot(`
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
- `);
1574
- });
1575
-
1576
- it("should offer to install type definitions in an existing typescript project", async () => {
1577
- mockConfirm(
1578
- {
1579
- text: "Would you like to use git to manage this Worker?",
1580
- result: false,
1581
- },
1582
- {
1583
- text: "Would you like to install wrangler into package.json?",
1584
- result: false,
1585
- },
1586
- {
1587
- text: "Would you like to install the type definitions for Workers into your package.json?",
1588
- result: true,
1589
- }
1590
- );
1591
- mockSelect({
1592
- text: `Would you like to create a Worker at ${path.join(
1593
- "src",
1594
- "index.ts"
1595
- )}?`,
1596
- result: "none",
1597
- });
1598
- writeFiles({
1599
- items: {
1600
- "./package.json": {
1601
- contents: {
1602
- name: "test",
1603
- version: "1.0.0",
1604
- },
1605
- },
1606
- "./tsconfig.json": { contents: { compilerOptions: {} } },
1607
- },
1608
- });
1609
-
1610
- await runWrangler("init");
1611
-
1612
- checkFiles({
1613
- items: {
1614
- // unchanged tsconfig
1615
- "tsconfig.json": { contents: { config: { compilerOptions: {} } } },
1616
- },
1617
- });
1618
- expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
1619
- "@cloudflare/workers-types"
1620
- );
1621
- expect(std).toMatchInlineSnapshot(`
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
- `);
1632
- });
1633
-
1634
- it("should not touch an existing tsconfig.json in an ancestor directory", async () => {
1635
- mockConfirm({
1636
- text: "Would you like to use git to manage this Worker?",
1637
- result: false,
1638
- });
1639
- mockSelect({
1640
- text: `Would you like to create a Worker at ${path.join(
1641
- "src",
1642
- "index.ts"
1643
- )}?`,
1644
- result: "fetch",
1645
- });
1646
- mockConfirm({
1647
- text: "Would you like us to write your first test with Vitest?",
1648
- result: true,
1649
- });
1650
- writeFiles({
1651
- items: {
1652
- "package.json": {
1653
- contents: {
1654
- name: "test",
1655
- version: "1.0.0",
1656
- devDependencies: {
1657
- wrangler: "0.0.0",
1658
- "@cloudflare/workers-types": "0.0.0",
1659
- },
1660
- },
1661
- },
1662
- "tsconfig.json": { contents: { compilerOptions: {} } },
1663
- },
1664
- });
1665
- setWorkingDirectory("./sub-1/sub-2");
1666
-
1667
- await runWrangler("init");
1668
-
1669
- checkFiles({
1670
- items: {
1671
- "tsconfig.json": false,
1672
- "../../tsconfig.json": {
1673
- contents: { config: { compilerOptions: {} } },
1674
- },
1675
- },
1676
- });
1677
- expect(std).toMatchInlineSnapshot(`
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
1686
-
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
- `);
1692
- });
1693
- });
1694
-
1695
- describe("javascript", () => {
1696
- it("should add missing scripts for a non-ts project with .js extension", async () => {
1697
- mockConfirm(
1698
- {
1699
- text: "Would you like to use git to manage this Worker?",
1700
- result: false,
1701
- },
1702
- {
1703
- text: "No package.json found. Would you like to create one?",
1704
- result: true,
1705
- },
1706
-
1707
- {
1708
- text: "Would you like to use TypeScript?",
1709
- result: false,
1710
- }
1711
- );
1712
- mockSelect({
1713
- text: `Would you like to create a Worker at ${path.join(
1714
- "src",
1715
- "index.js"
1716
- )}?`,
1717
- result: "fetch",
1718
- });
1719
- mockConfirm({
1720
- text: "Would you like us to write your first test?",
1721
- result: false,
1722
- });
1723
- await runWrangler("init");
1724
-
1725
- checkFiles({
1726
- items: {
1727
- "src/index.js": true,
1728
- "src/index.ts": false,
1729
- "package.json": {
1730
- contents: expect.objectContaining({
1731
- name: expect.stringContaining("wrangler-tests"),
1732
- version: "0.0.0",
1733
- scripts: {
1734
- start: "wrangler dev",
1735
- deploy: "wrangler publish",
1736
- },
1737
- }),
1738
- },
1739
- },
1740
- });
1741
- expect(std.out).toMatchInlineSnapshot(`
1742
- "✨ Created wrangler.toml
1743
- ✨ Created package.json
1744
- ✨ Created src/index.js
1745
-
1746
- To start developing your Worker, run \`npm start\`
1747
- To publish your Worker to the Internet, run \`npm run deploy\`"
1748
- `);
1749
- });
1750
- it("should add a jest test for a non-ts project with .js extension", async () => {
1751
- mockConfirm(
1752
- {
1753
- text: "Would you like to use git to manage this Worker?",
1754
- result: false,
1755
- },
1756
- {
1757
- text: "No package.json found. Would you like to create one?",
1758
- result: true,
1759
- },
1760
- {
1761
- text: "Would you like to use TypeScript?",
1762
- result: false,
1763
- }
1764
- );
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
- });
1780
- await runWrangler("init");
1781
-
1782
- checkFiles({
1783
- items: {
1784
- "src/index.js": true,
1785
- "src/index.test.js": true,
1786
- "src/index.ts": false,
1787
- "package.json": {
1788
- contents: expect.objectContaining({
1789
- name: expect.stringContaining("wrangler-tests"),
1790
- version: "0.0.0",
1791
- scripts: {
1792
- start: "wrangler dev",
1793
- deploy: "wrangler publish",
1794
- test: "jest",
1795
- },
1796
- }),
1797
- },
1798
- },
1799
- });
1800
- expect(std.out).toMatchInlineSnapshot(`
1801
- "✨ Created wrangler.toml
1802
- ✨ Created package.json
1803
- ✨ Created src/index.js
1804
- ✨ Created src/index.test.js
1805
- ✨ Installed jest into devDependencies
1806
-
1807
- To start developing your Worker, run \`npm start\`
1808
- To start testing your Worker, run \`npm test\`
1809
- To publish your Worker to the Internet, run \`npm run deploy\`"
1810
- `);
1811
- });
1812
-
1813
- it("should add a vitest test for a non-ts project with .js extension", async () => {
1814
- mockConfirm(
1815
- {
1816
- text: "Would you like to use git to manage this Worker?",
1817
- result: false,
1818
- },
1819
- {
1820
- text: "No package.json found. Would you like to create one?",
1821
- result: true,
1822
- },
1823
- {
1824
- text: "Would you like to use TypeScript?",
1825
- result: false,
1826
- }
1827
- );
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
- });
1843
- await runWrangler("init");
1844
-
1845
- checkFiles({
1846
- items: {
1847
- "src/index.js": true,
1848
- "src/index.test.js": true,
1849
- "src/index.ts": false,
1850
- "package.json": {
1851
- contents: expect.objectContaining({
1852
- name: expect.stringContaining("wrangler-tests"),
1853
- version: "0.0.0",
1854
- scripts: {
1855
- start: "wrangler dev",
1856
- deploy: "wrangler publish",
1857
- test: "vitest",
1858
- },
1859
- }),
1860
- },
1861
- },
1862
- });
1863
- expect(std.out).toMatchInlineSnapshot(`
1864
- "✨ Created wrangler.toml
1865
- ✨ Created package.json
1866
- ✨ Created src/index.js
1867
- ✨ Created src/index.test.js
1868
- ✨ Installed vitest into devDependencies
1869
-
1870
- To start developing your Worker, run \`npm start\`
1871
- To start testing your Worker, run \`npm test\`
1872
- To publish your Worker to the Internet, run \`npm run deploy\`"
1873
- `);
1874
- });
1875
-
1876
- it("should not overwrite package.json scripts for a non-ts project with .js extension", async () => {
1877
- mockConfirm(
1878
- {
1879
- text: "Would you like to use git to manage this Worker?",
1880
- result: false,
1881
- },
1882
- {
1883
- text: "Would you like to install wrangler into package.json?",
1884
- result: false,
1885
- },
1886
- {
1887
- text: "Would you like to use TypeScript?",
1888
- result: false,
1889
- }
1890
- );
1891
- mockSelect({
1892
- text: `Would you like to create a Worker at ${path.join(
1893
- "src",
1894
- "index.js"
1895
- )}?`,
1896
- result: "fetch",
1897
- });
1898
- mockConfirm({
1899
- text: "Would you like us to write your first test?",
1900
- result: false,
1901
- });
1902
- writeFiles({
1903
- items: {
1904
- "package.json": {
1905
- contents: {
1906
- scripts: {
1907
- start: "test-start",
1908
- deploy: "test-publish",
1909
- },
1910
- },
1911
- },
1912
- },
1913
- });
1914
-
1915
- await runWrangler("init");
1916
-
1917
- checkFiles({
1918
- items: {
1919
- "src/index.js": true,
1920
- "src/index.ts": false,
1921
- "package.json": {
1922
- contents: expect.objectContaining({
1923
- scripts: {
1924
- start: "test-start",
1925
- deploy: "test-publish",
1926
- },
1927
- }),
1928
- },
1929
- },
1930
- });
1931
- expect(std.out).toMatchInlineSnapshot(`
1932
- "✨ Created wrangler.toml
1933
- ✨ Created src/index.js
1934
-
1935
- To start developing your Worker, run \`npx wrangler dev\`
1936
- To publish your Worker to the Internet, run \`npx wrangler publish\`"
1937
- `);
1938
- });
1939
-
1940
- it("should not offer to create a worker in a non-ts project if a file already exists at the location", async () => {
1941
- mockConfirm(
1942
- {
1943
- text: "Would you like to use git to manage this Worker?",
1944
- result: false,
1945
- },
1946
- {
1947
- text: "Would you like to install wrangler into package.json?",
1948
- result: false,
1949
- },
1950
- {
1951
- text: "Would you like to use TypeScript?",
1952
- result: false,
1953
- }
1954
- );
1955
- const PLACEHOLDER = "/* placeholder text */";
1956
- writeFiles({
1957
- items: {
1958
- "package.json": { contents: { name: "test", version: "1.0.0" } },
1959
- "src/index.js": { contents: PLACEHOLDER },
1960
- },
1961
- });
1962
-
1963
- await runWrangler("init");
1964
-
1965
- checkFiles({
1966
- items: {
1967
- "src/index.js": { contents: PLACEHOLDER },
1968
- "src/index.ts": false,
1969
- },
1970
- });
1971
- expect(std).toMatchInlineSnapshot(`
1972
- Object {
1973
- "debug": "",
1974
- "err": "",
1975
- "info": "",
1976
- "out": "✨ Created wrangler.toml",
1977
- "warn": "",
1978
- }
1979
- `);
1980
- });
1981
-
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 () => {
1983
- mockConfirm(
1984
- {
1985
- text: "Would you like to use git to manage this Worker?",
1986
- result: false,
1987
- },
1988
- {
1989
- text: `Would you like to install wrangler into ${path.join(
1990
- "my-worker",
1991
- "package.json"
1992
- )}?`,
1993
- result: false,
1994
- },
1995
- {
1996
- text: "Would you like to use TypeScript?",
1997
- result: false,
1998
- }
1999
- );
2000
- const PLACEHOLDER = "/* placeholder text */";
2001
- writeFiles({
2002
- items: {
2003
- "my-worker/package.json": {
2004
- contents: { name: "test", version: "1.0.0" },
2005
- },
2006
- "my-worker/src/index.js": { contents: PLACEHOLDER },
2007
- },
2008
- });
2009
-
2010
- await runWrangler("init my-worker");
2011
-
2012
- checkFiles({
2013
- items: {
2014
- "my-worker/src/index.js": { contents: PLACEHOLDER },
2015
- "my-worker/src/index.ts": false,
2016
- },
2017
- });
2018
- expect(std).toMatchInlineSnapshot(`
2019
- Object {
2020
- "debug": "",
2021
- "err": "",
2022
- "info": "",
2023
- "out": "✨ Created my-worker/wrangler.toml",
2024
- "warn": "",
2025
- }
2026
- `);
2027
- });
2028
- });
2029
-
2030
- describe("worker names", () => {
2031
- it("should create a worker with a given name", async () => {
2032
- await runWrangler("init my-worker -y");
2033
-
2034
- checkFiles({
2035
- items: {
2036
- "my-worker/wrangler.toml": wranglerToml({
2037
- ...MINIMAL_WRANGLER_TOML,
2038
- name: "my-worker",
2039
- }),
2040
- },
2041
- });
2042
- });
2043
-
2044
- it('should create a worker with the name of the current directory if "name" is .', async () => {
2045
- await runWrangler("init . -y");
2046
-
2047
- const workerName = path.basename(process.cwd()).toLowerCase();
2048
- checkFiles({
2049
- items: {
2050
- "wrangler.toml": wranglerToml({
2051
- ...MINIMAL_WRANGLER_TOML,
2052
- name: workerName,
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
- },
2068
- },
2069
- });
2070
- expect(std).toMatchInlineSnapshot(`
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
2082
-
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
- `);
2089
- });
2090
-
2091
- it('should create a worker in a nested directory if "name" is path/to/worker', async () => {
2092
- await runWrangler("init path/to/worker -y");
2093
-
2094
- checkFiles({
2095
- items: {
2096
- "path/to/worker/wrangler.toml": wranglerToml({
2097
- ...MINIMAL_WRANGLER_TOML,
2098
- name: "worker",
2099
- }),
2100
- },
2101
- });
2102
- expect(std).toMatchInlineSnapshot(`
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
- `);
2121
- });
2122
-
2123
- it("should normalize characters that aren't lowercase alphanumeric, underscores, or dashes", async () => {
2124
- await runWrangler("init WEIRD_w0rkr_N4m3.js.tsx.tar.gz -y");
2125
-
2126
- checkFiles({
2127
- items: {
2128
- "WEIRD_w0rkr_N4m3.js.tsx.tar.gz/wrangler.toml": wranglerToml({
2129
- ...MINIMAL_WRANGLER_TOML,
2130
- name: "weird_w0rkr_n4m3-js-tsx-tar-gz",
2131
- }),
2132
- },
2133
- });
2134
- expect(std).toMatchInlineSnapshot(`
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
- `);
2153
- });
2154
-
2155
- it("should ignore ancestor files (such as wrangler.toml, package.json and tsconfig.json) if a name/path is given", async () => {
2156
- mockConfirm(
2157
- {
2158
- text: "Would you like to use git to manage this Worker?",
2159
- result: false,
2160
- },
2161
- {
2162
- text: "No package.json found. Would you like to create one?",
2163
- result: true,
2164
- },
2165
- {
2166
- text: "Would you like to use TypeScript?",
2167
- result: true,
2168
- }
2169
- );
2170
- mockSelect({
2171
- text: `Would you like to create a Worker at ${path.join(
2172
- "sub",
2173
- "folder",
2174
- "worker",
2175
- "src",
2176
- "index.ts"
2177
- )}?`,
2178
- result: "fetch",
2179
- });
2180
- mockConfirm({
2181
- text: "Would you like us to write your first test with Vitest?",
2182
- result: true,
2183
- });
2184
- writeFiles({
2185
- items: {
2186
- "package.json": { contents: { name: "top-level" } },
2187
- "tsconfig.json": { contents: { compilerOptions: {} } },
2188
- "wrangler.toml": wranglerToml({
2189
- name: "top-level",
2190
- compatibility_date: "some-date",
2191
- }),
2192
- },
2193
- });
2194
-
2195
- await runWrangler("init sub/folder/worker");
2196
-
2197
- // Ancestor files are untouched.
2198
- checkFiles({
2199
- items: {
2200
- "package.json": { contents: { name: "top-level" } },
2201
- "tsconfig.json": {
2202
- contents: { config: { compilerOptions: {} }, error: undefined },
2203
- },
2204
- "wrangler.toml": wranglerToml({
2205
- name: "top-level",
2206
- compatibility_date: "some-date",
2207
- }),
2208
- },
2209
- });
2210
- // New initialized Worker has its own files.
2211
- checkFiles({
2212
- items: {
2213
- "sub/folder/worker/package.json": {
2214
- contents: expect.objectContaining({
2215
- name: "worker",
2216
- }),
2217
- },
2218
- "sub/folder/worker/tsconfig.json": true,
2219
- "sub/folder/worker/wrangler.toml": wranglerToml({
2220
- ...MINIMAL_WRANGLER_TOML,
2221
- name: "worker",
2222
- }),
2223
- },
2224
- });
2225
- });
2226
- });
2227
-
2228
- describe("from dashboard", () => {
2229
- mockApiToken();
2230
- mockAccountId({ accountId: "LCARS" });
2231
-
2232
- const mockDashboardScript = `
2233
- export default {
2234
- async fetch(request, env, ctx) {
2235
- return new Response("Hello World!");
2236
- },
2237
- };
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
- });
2245
- const mockServiceMetadata = {
2246
- id: "memory-crystal",
2247
- default_environment: {
2248
- environment: "test",
2249
- created_on: "1987-9-27",
2250
- modified_on: "1987-9-27",
2251
- script: {
2252
- id: "memory-crystal",
2253
- tag: "test-tag",
2254
- etag: "some-etag",
2255
- handlers: [],
2256
- modified_on: "1987-9-27",
2257
- created_on: "1987-9-27",
2258
- migration_tag: "some-migration-tag",
2259
- usage_model: "bundled",
2260
- compatibility_date: "1987-9-27",
2261
- tail_consumers: [{ service: "listener" }],
2262
- },
2263
- },
2264
- created_on: "1987-9-27",
2265
- modified_on: "1987-9-27",
2266
- usage_model: "bundled",
2267
- environments: [
2268
- {
2269
- environment: "test",
2270
- created_on: "1987-9-27",
2271
- modified_on: "1987-9-27",
2272
- },
2273
- {
2274
- environment: "staging",
2275
- created_on: "1987-9-27",
2276
- modified_on: "1987-9-27",
2277
- },
2278
- ],
2279
- };
2280
- const mockBindingsRes = [
2281
- {
2282
- type: "secret_text",
2283
- name: "ABC",
2284
- },
2285
- {
2286
- type: "plain_text",
2287
- name: "ANOTHER-NAME",
2288
- text: "thing-TEXT",
2289
- },
2290
- {
2291
- type: "durable_object_namespace",
2292
- name: "DURABLE_TEST",
2293
- class_name: "Durability",
2294
- script_name: "another-durable-object-worker",
2295
- environment: "production",
2296
- },
2297
- {
2298
- type: "kv_namespace",
2299
- name: "kv_testing",
2300
- namespace_id: "some-namespace-id",
2301
- },
2302
- {
2303
- type: "r2_bucket",
2304
- bucket_name: "test-bucket",
2305
- name: "test-bucket",
2306
- },
2307
- {
2308
- environment: "production",
2309
- name: "website",
2310
- service: "website",
2311
- type: "service",
2312
- },
2313
- {
2314
- type: "dispatch_namespace",
2315
- name: "name-namespace-mock",
2316
- namespace: "namespace-mock",
2317
- },
2318
- {
2319
- name: "httplogs",
2320
- type: "logfwdr",
2321
- destination: "httplogs",
2322
- },
2323
- {
2324
- name: "trace",
2325
- type: "logfwdr",
2326
- destination: "trace",
2327
- },
2328
- {
2329
- type: "wasm_module",
2330
- name: "WASM_MODULE_ONE",
2331
- part: "./some_wasm.wasm",
2332
- },
2333
- {
2334
- type: "wasm_module",
2335
- name: "WASM_MODULE_TWO",
2336
- part: "./more_wasm.wasm",
2337
- },
2338
- {
2339
- type: "text_blob",
2340
- name: "TEXT_BLOB_ONE",
2341
- part: "./my-entire-app-depends-on-this.cfg",
2342
- },
2343
- {
2344
- type: "text_blob",
2345
- name: "TEXT_BLOB_TWO",
2346
- part: "./the-entirety-of-human-knowledge.txt",
2347
- },
2348
- { type: "data_blob", name: "DATA_BLOB_ONE", part: "DATA_BLOB_ONE" },
2349
- { type: "data_blob", name: "DATA_BLOB_TWO", part: "DATA_BLOB_TWO" },
2350
- {
2351
- type: "some unsafe thing",
2352
- name: "UNSAFE_BINDING_ONE",
2353
- data: { some: { unsafe: "thing" } },
2354
- },
2355
- {
2356
- type: "another unsafe thing",
2357
- name: "UNSAFE_BINDING_TWO",
2358
- data: 1337,
2359
- },
2360
- ];
2361
- const mockRoutesRes = [
2362
- {
2363
- id: "some-route-id",
2364
- pattern: "delta.quadrant",
2365
- },
2366
- ];
2367
- const mockConfigExpected = {
2368
- main: "src/index.ts",
2369
- compatibility_date: "1987-9-27",
2370
- name: "isolinear-optical-chip",
2371
- migrations: [
2372
- {
2373
- new_classes: ["Durability"],
2374
- tag: "some-migration-tag",
2375
- },
2376
- ],
2377
- durable_objects: {
2378
- bindings: [
2379
- {
2380
- class_name: "Durability",
2381
- name: "DURABLE_TEST",
2382
- script_name: "another-durable-object-worker",
2383
- environment: "production",
2384
- },
2385
- ],
2386
- },
2387
- kv_namespaces: [
2388
- {
2389
- binding: "kv_testing",
2390
- id: "some-namespace-id",
2391
- },
2392
- ],
2393
- r2_buckets: [
2394
- {
2395
- bucket_name: "test-bucket",
2396
- binding: "test-bucket",
2397
- },
2398
- ],
2399
- dispatch_namespaces: [
2400
- {
2401
- binding: "name-namespace-mock",
2402
- namespace: "namespace-mock",
2403
- },
2404
- ],
2405
- route: "delta.quadrant",
2406
- services: [
2407
- {
2408
- environment: "production",
2409
- binding: "website",
2410
- service: "website",
2411
- },
2412
- ],
2413
- triggers: {
2414
- crons: ["0 0 0 * * *"],
2415
- },
2416
- usage_model: "bundled",
2417
- vars: {
2418
- "ANOTHER-NAME": "thing-TEXT",
2419
- },
2420
- env: {
2421
- test: {},
2422
- staging: {},
2423
- },
2424
- unsafe: {
2425
- bindings: [
2426
- {
2427
- name: "UNSAFE_BINDING_ONE",
2428
- type: "some unsafe thing",
2429
- data: { some: { unsafe: "thing" } },
2430
- },
2431
- {
2432
- name: "UNSAFE_BINDING_TWO",
2433
- type: "another unsafe thing",
2434
- data: 1337,
2435
- },
2436
- ],
2437
- },
2438
- wasm_modules: {
2439
- WASM_MODULE_ONE: "./some_wasm.wasm",
2440
- WASM_MODULE_TWO: "./more_wasm.wasm",
2441
- },
2442
- text_blobs: {
2443
- TEXT_BLOB_ONE: "./my-entire-app-depends-on-this.cfg",
2444
- TEXT_BLOB_TWO: "./the-entirety-of-human-knowledge.txt",
2445
- },
2446
- data_blobs: {
2447
- DATA_BLOB_ONE: "DATA_BLOB_ONE",
2448
- DATA_BLOB_TWO: "DATA_BLOB_TWO",
2449
- },
2450
- logfwdr: {
2451
- schema: "",
2452
- bindings: [
2453
- {
2454
- name: "httplogs",
2455
- destination: "httplogs",
2456
- },
2457
- {
2458
- name: "trace",
2459
- destination: "trace",
2460
- },
2461
- ],
2462
- },
2463
- tail_consumers: [{ service: "listener" }],
2464
- };
2465
-
2466
- function mockSupportingDashRequests({
2467
- expectedAccountId = "",
2468
- expectedScriptName = "",
2469
- expectedEnvironment = "",
2470
- expectedCompatDate,
2471
- }: {
2472
- expectedAccountId: string;
2473
- expectedScriptName: string;
2474
- expectedEnvironment: string;
2475
- expectedCompatDate: string | undefined;
2476
- }) {
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
- )
2579
- );
2580
- }
2581
-
2582
- //TODO: Tests for a case when a worker name doesn't exist - JACOB & CASS
2583
- it("should download source script from dashboard w/ positional <name> in TypeScript project", async () => {
2584
- mockSupportingDashRequests({
2585
- expectedAccountId: "LCARS",
2586
- expectedScriptName: "memory-crystal",
2587
- expectedEnvironment: "test",
2588
- expectedCompatDate: "1987-9-27",
2589
- });
2590
- setMockFetchDashScript(mockDashboardScript);
2591
- mockConfirm(
2592
- {
2593
- text: "Would you like to use git to manage this Worker?",
2594
- result: false,
2595
- },
2596
- {
2597
- text: "No package.json found. Would you like to create one?",
2598
- result: true,
2599
- },
2600
- {
2601
- text: "Would you like to use TypeScript?",
2602
- result: true,
2603
- }
2604
- );
2605
-
2606
- await runWrangler(
2607
- "init isolinear-optical-chip --from-dash memory-crystal"
2608
- );
2609
-
2610
- expect(std.out).toContain("cd isolinear-optical-chip");
2611
-
2612
- checkFiles({
2613
- items: {
2614
- "isolinear-optical-chip/src/index.js": false,
2615
- "isolinear-optical-chip/src/index.ts": {
2616
- contents: mockDashboardScript,
2617
- },
2618
- "isolinear-optical-chip/package.json": {
2619
- contents: expect.objectContaining({
2620
- name: "isolinear-optical-chip",
2621
- }),
2622
- },
2623
- "isolinear-optical-chip/tsconfig.json": true,
2624
- "isolinear-optical-chip/wrangler.toml": wranglerToml({
2625
- ...mockConfigExpected,
2626
- }),
2627
- },
2628
- });
2629
- });
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
-
2669
- it("should download source script from dashboard w/ out positional <name>", async () => {
2670
- mockSupportingDashRequests({
2671
- expectedAccountId: "LCARS",
2672
- expectedScriptName: "isolinear-optical-chip",
2673
- expectedEnvironment: "test",
2674
- expectedCompatDate: "1987-9-27",
2675
- });
2676
- setMockFetchDashScript(mockDashboardScript);
2677
- mockConfirm(
2678
- {
2679
- text: "Would you like to use git to manage this Worker?",
2680
- result: false,
2681
- },
2682
- {
2683
- text: "No package.json found. Would you like to create one?",
2684
- result: true,
2685
- },
2686
- {
2687
- text: "Would you like to use TypeScript?",
2688
- result: true,
2689
- }
2690
- );
2691
-
2692
- await runWrangler("init --from-dash isolinear-optical-chip");
2693
-
2694
- expect(fs.readFileSync("./isolinear-optical-chip/wrangler.toml", "utf8"))
2695
- .toMatchInlineSnapshot(`
2696
- "name = \\"isolinear-optical-chip\\"
2697
- main = \\"src/index.ts\\"
2698
- compatibility_date = \\"1987-9-27\\"
2699
- route = \\"delta.quadrant\\"
2700
- usage_model = \\"bundled\\"
2701
-
2702
- [[migrations]]
2703
- tag = \\"some-migration-tag\\"
2704
- new_classes = [ \\"Durability\\" ]
2705
-
2706
- [triggers]
2707
- crons = [ \\"0 0 0 * * *\\" ]
2708
-
2709
- [env]
2710
- test = { }
2711
- staging = { }
2712
-
2713
- [[tail_consumers]]
2714
- service = \\"listener\\"
2715
-
2716
- [vars]
2717
- ANOTHER-NAME = \\"thing-TEXT\\"
2718
-
2719
- [[durable_objects.bindings]]
2720
- name = \\"DURABLE_TEST\\"
2721
- class_name = \\"Durability\\"
2722
- script_name = \\"another-durable-object-worker\\"
2723
- environment = \\"production\\"
2724
-
2725
- [[kv_namespaces]]
2726
- id = \\"some-namespace-id\\"
2727
- binding = \\"kv_testing\\"
2728
-
2729
- [[r2_buckets]]
2730
- binding = \\"test-bucket\\"
2731
- bucket_name = \\"test-bucket\\"
2732
-
2733
- [[services]]
2734
- binding = \\"website\\"
2735
- service = \\"website\\"
2736
- environment = \\"production\\"
2737
-
2738
- [[dispatch_namespaces]]
2739
- binding = \\"name-namespace-mock\\"
2740
- namespace = \\"namespace-mock\\"
2741
-
2742
- [logfwdr]
2743
- schema = \\"\\"
2744
-
2745
- [[logfwdr.bindings]]
2746
- name = \\"httplogs\\"
2747
- destination = \\"httplogs\\"
2748
-
2749
- [[logfwdr.bindings]]
2750
- name = \\"trace\\"
2751
- destination = \\"trace\\"
2752
-
2753
- [wasm_modules]
2754
- WASM_MODULE_ONE = \\"./some_wasm.wasm\\"
2755
- WASM_MODULE_TWO = \\"./more_wasm.wasm\\"
2756
-
2757
- [text_blobs]
2758
- TEXT_BLOB_ONE = \\"./my-entire-app-depends-on-this.cfg\\"
2759
- TEXT_BLOB_TWO = \\"./the-entirety-of-human-knowledge.txt\\"
2760
-
2761
- [data_blobs]
2762
- DATA_BLOB_ONE = \\"DATA_BLOB_ONE\\"
2763
- DATA_BLOB_TWO = \\"DATA_BLOB_TWO\\"
2764
-
2765
- [unsafe]
2766
- [[unsafe.bindings]]
2767
- type = \\"some unsafe thing\\"
2768
- name = \\"UNSAFE_BINDING_ONE\\"
2769
-
2770
- [unsafe.bindings.data.some]
2771
- unsafe = \\"thing\\"
2772
-
2773
- [[unsafe.bindings]]
2774
- type = \\"another unsafe thing\\"
2775
- name = \\"UNSAFE_BINDING_TWO\\"
2776
- data = 1_337
2777
- "
2778
- `);
2779
- expect(std.out).toContain("cd isolinear-optical-chip");
2780
-
2781
- checkFiles({
2782
- items: {
2783
- "isolinear-optical-chip/src/index.js": false,
2784
- "isolinear-optical-chip/src/index.ts": {
2785
- contents: mockDashboardScript,
2786
- },
2787
- "isolinear-optical-chip/package.json": {
2788
- contents: expect.objectContaining({
2789
- name: "isolinear-optical-chip",
2790
- }),
2791
- },
2792
- "isolinear-optical-chip/tsconfig.json": true,
2793
- "isolinear-optical-chip/wrangler.toml": wranglerToml({
2794
- ...mockConfigExpected,
2795
- name: "isolinear-optical-chip",
2796
- }),
2797
- },
2798
- });
2799
- });
2800
-
2801
- it("should download source script from dashboard as plain JavaScript", async () => {
2802
- mockSupportingDashRequests({
2803
- expectedAccountId: "LCARS",
2804
- expectedScriptName: "isolinear-optical-chip",
2805
- expectedEnvironment: "test",
2806
- expectedCompatDate: "1987-9-27",
2807
- });
2808
- setMockFetchDashScript(mockDashboardScript);
2809
- mockConfirm(
2810
- {
2811
- text: "Would you like to use git to manage this Worker?",
2812
- result: false,
2813
- },
2814
- {
2815
- text: "No package.json found. Would you like to create one?",
2816
- result: true,
2817
- },
2818
- {
2819
- text: "Would you like to use TypeScript?",
2820
- result: false,
2821
- }
2822
- );
2823
-
2824
- await runWrangler("init --from-dash isolinear-optical-chip");
2825
-
2826
- checkFiles({
2827
- items: {
2828
- "isolinear-optical-chip/src/index.js": {
2829
- contents: mockDashboardScript,
2830
- },
2831
- "isolinear-optical-chip/src/index.ts": false,
2832
- "isolinear-optical-chip/package.json": {
2833
- contents: expect.objectContaining({
2834
- name: "isolinear-optical-chip",
2835
- }),
2836
- },
2837
- "isolinear-optical-chip/tsconfig.json": false,
2838
- "isolinear-optical-chip/wrangler.toml": wranglerToml({
2839
- ...mockConfigExpected,
2840
- name: "isolinear-optical-chip",
2841
- main: "src/index.js",
2842
- }),
2843
- },
2844
- });
2845
- });
2846
-
2847
- it("should use fallback compatibility date if none is upstream", async () => {
2848
- const mockDate = "1988-08-07";
2849
- jest
2850
- .spyOn(Date.prototype, "toISOString")
2851
- .mockImplementation(() => `${mockDate}T00:00:00.000Z`);
2852
-
2853
- mockSupportingDashRequests({
2854
- expectedAccountId: "LCARS",
2855
- expectedScriptName: "isolinear-optical-chip",
2856
- expectedEnvironment: "test",
2857
- expectedCompatDate: undefined,
2858
- });
2859
- setMockFetchDashScript(mockDashboardScript);
2860
- mockConfirm(
2861
- {
2862
- text: "Would you like to use git to manage this Worker?",
2863
- result: false,
2864
- },
2865
- {
2866
- text: "No package.json found. Would you like to create one?",
2867
- result: true,
2868
- },
2869
- {
2870
- text: "Would you like to use TypeScript?",
2871
- result: true,
2872
- }
2873
- );
2874
-
2875
- await runWrangler("init --from-dash isolinear-optical-chip");
2876
-
2877
- mockConfigExpected.compatibility_date = "1988-08-07";
2878
- checkFiles({
2879
- items: {
2880
- "isolinear-optical-chip/src/index.ts": {
2881
- contents: mockDashboardScript,
2882
- },
2883
- "isolinear-optical-chip/package.json": {
2884
- contents: expect.objectContaining({
2885
- name: "isolinear-optical-chip",
2886
- }),
2887
- },
2888
- "isolinear-optical-chip/tsconfig.json": true,
2889
- "isolinear-optical-chip/wrangler.toml": wranglerToml({
2890
- ...mockConfigExpected,
2891
- name: "isolinear-optical-chip",
2892
- }),
2893
- },
2894
- });
2895
- });
2896
-
2897
- it("should throw an error to retry if a request fails", async () => {
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
- )
2921
- );
2922
-
2923
- setMockFetchDashScript(mockDashboardScript);
2924
- mockConfirm(
2925
- {
2926
- text: "Would you like to use git to manage this Worker?",
2927
- result: false,
2928
- },
2929
- {
2930
- text: "Would you like to use TypeScript?",
2931
- result: false,
2932
- }
2933
- );
2934
-
2935
- await expect(
2936
- runWrangler("init --from-dash isolinear-optical-chip")
2937
- ).rejects.toThrowError();
2938
- });
2939
-
2940
- it("should not include migrations in config file when none are necessary", async () => {
2941
- const mockDate = "1988-08-07";
2942
- jest
2943
- .spyOn(Date.prototype, "toISOString")
2944
- .mockImplementation(() => `${mockDate}T00:00:00.000Z`);
2945
- const mockData = {
2946
- id: "memory-crystal",
2947
- default_environment: {
2948
- environment: "test",
2949
- created_on: "1988-08-07",
2950
- modified_on: "1988-08-07",
2951
- script: {
2952
- id: "memory-crystal",
2953
- tag: "test-tag",
2954
- etag: "some-etag",
2955
- handlers: [],
2956
- modified_on: "1988-08-07",
2957
- created_on: "1988-08-07",
2958
- usage_model: "bundled",
2959
- compatibility_date: "1988-08-07",
2960
- tail_consumers: [{ service: "listener" }],
2961
- },
2962
- },
2963
- environments: [],
2964
- };
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
- )
3036
- );
3037
-
3038
- setMockFetchDashScript(mockDashboardScript);
3039
-
3040
- mockConfirm(
3041
- {
3042
- text: "Would you like to use git to manage this Worker?",
3043
- result: false,
3044
- },
3045
-
3046
- {
3047
- text: "No package.json found. Would you like to create one?",
3048
- result: true,
3049
- },
3050
- {
3051
- text: "Would you like to use TypeScript?",
3052
- result: true,
3053
- }
3054
- );
3055
-
3056
- await runWrangler("init --from-dash isolinear-optical-chip");
3057
-
3058
- checkFiles({
3059
- items: {
3060
- "isolinear-optical-chip/wrangler.toml": wranglerToml({
3061
- compatibility_date: "1988-08-07",
3062
- env: {},
3063
- main: "src/index.ts",
3064
- triggers: {
3065
- crons: [],
3066
- },
3067
- usage_model: "bundled",
3068
- name: "isolinear-optical-chip",
3069
- tail_consumers: [{ service: "listener" }],
3070
- }),
3071
- },
3072
- });
3073
- });
3074
-
3075
- it("should not continue if no worker name is provided", async () => {
3076
- await expect(
3077
- runWrangler("init --from-dash")
3078
- ).rejects.toMatchInlineSnapshot(
3079
- `[Error: Not enough arguments following: from-dash]`
3080
- );
3081
- checkFiles({
3082
- items: {
3083
- "isolinear-optical-chip/src/index.js": false,
3084
- "isolinear-optical-chip/src/index.ts": false,
3085
- "isolinear-optical-chip/package.json": false,
3086
- "isolinear-optical-chip/tsconfig.json": false,
3087
- "isolinear-optical-chip/wrangler.toml": false,
3088
- },
3089
- });
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
- });
3157
- });
3158
- });
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
-
3215
- /**
3216
- * Change the current working directory, ensuring that this exists.
3217
- */
3218
- function setWorkingDirectory(directory: string) {
3219
- fs.mkdirSync(directory, { recursive: true });
3220
- process.chdir(directory);
3221
- }
3222
-
3223
- /**
3224
- * Write the given folder/files to disk at the given `cwd`.
3225
- */
3226
- function writeFiles(folder: TestFolder, cwd = process.cwd()) {
3227
- for (const name in folder.items) {
3228
- const item = folder.items[name];
3229
- const itemPath = path.resolve(cwd, name);
3230
- if (typeof item !== "boolean") {
3231
- if ("contents" in item) {
3232
- fs.mkdirSync(path.dirname(itemPath), { recursive: true });
3233
- fs.writeFileSync(itemPath, stringify(name, item.contents));
3234
- } else {
3235
- fs.mkdirSync(itemPath, { recursive: true });
3236
- writeFiles(item, itemPath);
3237
- }
3238
- } else {
3239
- throw new Error("Cannot write boolean flags to disk: " + itemPath);
3240
- }
3241
- }
3242
- }
3243
-
3244
- /**
3245
- * Check that the given test folders/files match what is in on disk.
3246
- */
3247
- function checkFiles(folder: TestFolder, cwd = process.cwd()) {
3248
- for (const name in folder.items) {
3249
- const item = folder.items[name];
3250
- const itemPath = path.resolve(cwd, name);
3251
- if (typeof item === "boolean") {
3252
- if (fs.existsSync(itemPath) !== item) {
3253
- throw new Error(`Expected ${itemPath} ${item ? "" : "not "}to exist.`);
3254
- }
3255
- } else if ("contents" in item) {
3256
- const actualContents = parse(name, fs.readFileSync(itemPath, "utf-8"));
3257
- expect(actualContents).toEqual(item.contents);
3258
- } else if ("items" in item) {
3259
- checkFiles(item, itemPath);
3260
- } else {
3261
- throw new Error("Unexpected TestFile object.");
3262
- }
3263
- }
3264
- }
3265
-
3266
- function stringify(name: string, value: unknown) {
3267
- if (name.endsWith(".toml")) {
3268
- return TOML.stringify(value as TOML.JsonMap);
3269
- }
3270
- if (name.endsWith(".json")) {
3271
- return JSON.stringify(value);
3272
- }
3273
- return `${value}`;
3274
- }
3275
-
3276
- function parse(name: string, value: string): unknown {
3277
- if (name.endsWith(".toml")) {
3278
- return TOML.parse(value);
3279
- }
3280
- if (name.endsWith("tsconfig.json")) {
3281
- return parseConfigFileTextToJson(name, value);
3282
- }
3283
- if (name.endsWith(".json")) {
3284
- return JSON.parse(value);
3285
- }
3286
- return value;
3287
- }
3288
-
3289
- function wranglerToml(options: TOML.JsonMap = {}): TestFile {
3290
- return {
3291
- contents: options,
3292
- };
3293
- }
3294
-
3295
- interface TestFile {
3296
- contents: unknown;
3297
- }
3298
- interface TestFolder {
3299
- items: {
3300
- [id: string]: TestFile | TestFolder | boolean;
3301
- };
3302
- }