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