wrangler 0.0.0-e178d6fb → 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 +16 -2
- package/bin/wrangler.js +31 -11
- package/miniflare-dist/index.mjs +1340 -330
- package/package.json +40 -13
- 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__/configuration.test.ts +683 -470
- 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 +453 -70
- 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__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-cfetch.ts +92 -26
- package/src/__tests__/helpers/mock-console.ts +11 -2
- package/src/__tests__/helpers/mock-dialogs.ts +1 -1
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
- package/src/__tests__/helpers/mock-known-routes.ts +7 -0
- package/src/__tests__/helpers/mock-kv.ts +1 -1
- package/src/__tests__/helpers/mock-oauth-flow.ts +74 -53
- package/src/__tests__/helpers/mock-process.ts +8 -13
- 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/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__/index.test.ts +103 -97
- package/src/__tests__/init.test.ts +1484 -382
- package/src/__tests__/jest.setup.ts +88 -5
- package/src/__tests__/kv.test.ts +655 -540
- package/src/__tests__/logout.test.ts +47 -0
- package/src/__tests__/metrics.test.ts +95 -45
- package/src/__tests__/middleware.scheduled.test.ts +145 -0
- package/src/__tests__/middleware.test.ts +750 -0
- package/src/__tests__/pages-deployment-tail.test.ts +884 -0
- package/src/__tests__/pages.test.ts +1301 -119
- package/src/__tests__/paths.test.ts +39 -0
- package/src/__tests__/publish.test.ts +2266 -1180
- package/src/__tests__/pubsub.test.ts +211 -88
- package/src/__tests__/queues.test.ts +522 -0
- package/src/__tests__/r2.test.ts +363 -203
- package/src/__tests__/secret.test.ts +261 -59
- package/src/__tests__/tail.test.ts +352 -151
- package/src/__tests__/test-old-node-version.js +3 -3
- 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 +59 -73
- package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
- package/src/__tests__/validate-dev-props.test.ts +56 -0
- package/src/__tests__/whoami.test.tsx +114 -66
- package/src/__tests__/worker-namespace.test.ts +154 -155
- package/src/api/dev.ts +170 -38
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +41 -2
- package/src/bundle.ts +668 -81
- package/src/cfetch/index.ts +40 -3
- package/src/cfetch/internal.ts +144 -32
- package/src/cli.ts +4 -3
- package/src/config/config.ts +27 -3
- package/src/config/environment.ts +131 -7
- package/src/config/index.ts +128 -8
- package/src/config/validation-helpers.ts +19 -6
- package/src/config/validation.ts +411 -14
- package/src/config-cache.ts +3 -2
- package/src/create-worker-preview.ts +31 -6
- package/src/create-worker-upload-form.ts +84 -22
- 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 +11 -8
- package/src/dev/dev.tsx +220 -58
- package/src/dev/get-local-persistence-path.tsx +31 -0
- package/src/dev/local.tsx +740 -181
- package/src/dev/remote.tsx +340 -123
- package/src/dev/start-server.ts +543 -0
- package/src/dev/use-esbuild.ts +61 -7
- package/src/dev/validate-dev-props.ts +31 -0
- package/src/dev-registry.tsx +201 -0
- package/src/dev.tsx +614 -258
- package/src/dialogs.tsx +41 -8
- package/src/{worker-namespace.ts → dispatch-namespace.ts} +23 -22
- package/src/docs/index.ts +97 -0
- package/src/entry.ts +3 -2
- package/src/environment-variables/factory.ts +88 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/generate/index.ts +300 -0
- package/src/git-client.ts +100 -7
- package/src/index.tsx +249 -1560
- package/src/init.ts +626 -150
- package/src/inspect.ts +137 -32
- package/src/{metrics/is-ci.ts → is-ci.ts} +0 -0
- package/src/is-interactive.ts +4 -0
- package/src/jest.d.ts +4 -0
- package/src/{kv.ts → kv/helpers.ts} +3 -3
- package/src/kv/index.ts +596 -0
- package/src/logger.ts +27 -8
- package/src/metrics/index.ts +1 -0
- package/src/metrics/metrics-config.ts +4 -4
- package/src/metrics/metrics-dispatcher.ts +1 -0
- package/src/metrics/metrics-usage-headers.ts +24 -0
- package/src/metrics/send-event.ts +13 -8
- package/src/miniflare-cli/assets.ts +172 -465
- package/src/miniflare-cli/index.ts +149 -24
- 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 +12 -3
- package/src/pages/build.tsx +108 -42
- package/src/pages/constants.ts +11 -0
- package/src/pages/deployment-tails.tsx +284 -0
- package/src/pages/deployments.tsx +9 -31
- package/src/pages/dev.tsx +417 -108
- package/src/pages/errors.ts +66 -0
- package/src/pages/functions/buildPlugin.ts +86 -84
- package/src/pages/functions/buildWorker.ts +121 -106
- 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/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 +73 -55
- package/src/pages/projects.tsx +9 -3
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +183 -60
- package/src/pages/types.ts +1 -0
- package/src/pages/upload.tsx +107 -56
- package/src/pages/utils.ts +13 -2
- package/src/paths.ts +49 -4
- package/src/proxy.ts +375 -157
- package/src/publish/index.ts +270 -0
- package/src/{publish.ts → publish/publish.ts} +431 -188
- package/src/pubsub/pubsub-commands.tsx +4 -3
- 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/sites.tsx +3 -3
- package/src/tail/createTail.ts +379 -0
- package/src/tail/filters.ts +4 -6
- package/src/tail/index.ts +199 -284
- package/src/tail/printing.ts +43 -3
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +181 -0
- package/src/user/access.ts +68 -0
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +1 -1
- package/src/user/index.ts +0 -1
- package/src/user/user.tsx +116 -49
- package/src/utils/collectKeyValues.ts +14 -0
- package/src/whoami.tsx +80 -2
- package/src/worker.ts +69 -9
- package/src/yargs-types.ts +24 -0
- package/src/zones.ts +124 -9
- 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/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.js +1 -1
- package/templates/pages-dev-pipeline.ts +31 -0
- package/templates/pages-dev-util.ts +52 -0
- package/templates/pages-shim.ts +4 -1
- package/templates/pages-template-plugin.ts +21 -5
- package/templates/pages-template-worker.ts +37 -9
- package/templates/{static-asset-facade.js → serve-static-assets.ts} +23 -7
- 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 +5 -102
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +621 -42
- package/wrangler-dist/cli.js +144441 -102606
- package/src/environment-variables.ts +0 -35
- package/src/faye-websocket.d.ts +0 -6
- package/src/generate.ts +0 -33
- package/src/miniflare-cli/enum-keys.ts +0 -17
- package/src/preview.ts +0 -31
- package/src/r2.ts +0 -50
- package/src/user/env-vars.ts +0 -46
|
@@ -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";
|
|
@@ -41,8 +41,8 @@ describe("init", () => {
|
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
afterEach(() => {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
msw.resetHandlers();
|
|
45
|
+
msw.restoreHandlers();
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
const std = mockConsoleMethods();
|
|
@@ -62,16 +62,17 @@ describe("init", () => {
|
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
expect(std.out).toMatchInlineSnapshot(`
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
+
`);
|
|
75
76
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
76
77
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
77
78
|
});
|
|
@@ -93,16 +94,17 @@ describe("init", () => {
|
|
|
93
94
|
});
|
|
94
95
|
|
|
95
96
|
expect(std.out).toMatchInlineSnapshot(`
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
+
`);
|
|
106
108
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
107
109
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
108
110
|
});
|
|
@@ -121,21 +123,22 @@ describe("init", () => {
|
|
|
121
123
|
});
|
|
122
124
|
|
|
123
125
|
expect(std).toMatchInlineSnapshot(`
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
+
`);
|
|
139
142
|
});
|
|
140
143
|
|
|
141
144
|
it("should error if `--type javascript` is used", async () => {
|
|
@@ -204,13 +207,13 @@ describe("init", () => {
|
|
|
204
207
|
});
|
|
205
208
|
|
|
206
209
|
expect(std).toMatchInlineSnapshot(`
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
210
|
+
Object {
|
|
211
|
+
"debug": "",
|
|
212
|
+
"err": "",
|
|
213
|
+
"out": "✨ Created wrangler.toml",
|
|
214
|
+
"warn": "",
|
|
215
|
+
}
|
|
216
|
+
`);
|
|
214
217
|
});
|
|
215
218
|
|
|
216
219
|
it("should create a wrangler.toml and a directory for a named Worker ", async () => {
|
|
@@ -238,13 +241,13 @@ describe("init", () => {
|
|
|
238
241
|
});
|
|
239
242
|
|
|
240
243
|
expect(std).toMatchInlineSnapshot(`
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
244
|
+
Object {
|
|
245
|
+
"debug": "",
|
|
246
|
+
"err": "",
|
|
247
|
+
"out": "✨ Created my-worker/wrangler.toml",
|
|
248
|
+
"warn": "",
|
|
249
|
+
}
|
|
250
|
+
`);
|
|
248
251
|
});
|
|
249
252
|
|
|
250
253
|
it("should display warning when wrangler.toml already exists, and exit if user does not want to carry on", async () => {
|
|
@@ -276,15 +279,15 @@ describe("init", () => {
|
|
|
276
279
|
});
|
|
277
280
|
|
|
278
281
|
expect(std).toMatchInlineSnapshot(`
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
+
`);
|
|
288
291
|
});
|
|
289
292
|
|
|
290
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 () => {
|
|
@@ -313,15 +316,15 @@ describe("init", () => {
|
|
|
313
316
|
},
|
|
314
317
|
});
|
|
315
318
|
expect(std).toMatchInlineSnapshot(`
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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
|
+
`);
|
|
325
328
|
});
|
|
326
329
|
|
|
327
330
|
it("should not overwrite an existing wrangler.toml, after agreeing to other prompts", async () => {
|
|
@@ -348,6 +351,10 @@ describe("init", () => {
|
|
|
348
351
|
{
|
|
349
352
|
text: "Would you like to use TypeScript?",
|
|
350
353
|
result: true,
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
text: "Would you like us to write your first test with Vitest?",
|
|
357
|
+
result: true,
|
|
351
358
|
}
|
|
352
359
|
);
|
|
353
360
|
|
|
@@ -401,15 +408,15 @@ describe("init", () => {
|
|
|
401
408
|
},
|
|
402
409
|
});
|
|
403
410
|
expect(std).toMatchInlineSnapshot(`
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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
|
+
`);
|
|
413
420
|
});
|
|
414
421
|
|
|
415
422
|
it("should not add a Cron Trigger to wrangler.toml when creating a Scheduled Worker if wrangler.toml already exists", async () => {
|
|
@@ -436,6 +443,10 @@ describe("init", () => {
|
|
|
436
443
|
{
|
|
437
444
|
text: "Would you like to use TypeScript?",
|
|
438
445
|
result: true,
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
text: "Would you like us to write your first test with Vitest?",
|
|
449
|
+
result: true,
|
|
439
450
|
}
|
|
440
451
|
);
|
|
441
452
|
mockSelect({
|
|
@@ -467,6 +478,10 @@ describe("init", () => {
|
|
|
467
478
|
{
|
|
468
479
|
text: "Would you like to use TypeScript?",
|
|
469
480
|
result: true,
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
text: "Would you like us to write your first test with Vitest?",
|
|
484
|
+
result: true,
|
|
470
485
|
}
|
|
471
486
|
);
|
|
472
487
|
mockSelect({
|
|
@@ -513,16 +528,16 @@ describe("init", () => {
|
|
|
513
528
|
},
|
|
514
529
|
});
|
|
515
530
|
expect(std).toMatchInlineSnapshot(`
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
531
|
+
Object {
|
|
532
|
+
"debug": "",
|
|
533
|
+
"err": "",
|
|
534
|
+
"out": "✨ Created wrangler.toml
|
|
535
|
+
✨ Initialized git repository",
|
|
536
|
+
"warn": "",
|
|
537
|
+
}
|
|
538
|
+
`);
|
|
524
539
|
expect((await execa("git", ["branch", "--show-current"])).stdout).toEqual(
|
|
525
|
-
|
|
540
|
+
getDefaultBranchName()
|
|
526
541
|
);
|
|
527
542
|
});
|
|
528
543
|
|
|
@@ -545,20 +560,21 @@ describe("init", () => {
|
|
|
545
560
|
|
|
546
561
|
// Note the lack of "✨ Initialized git repository" in the log
|
|
547
562
|
expect(std).toMatchInlineSnapshot(`
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
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
|
+
`);
|
|
562
578
|
});
|
|
563
579
|
|
|
564
580
|
it("should not offer to initialize a git repo if it's already inside one (when using a path as name)", async () => {
|
|
@@ -570,20 +586,21 @@ describe("init", () => {
|
|
|
570
586
|
|
|
571
587
|
// Note the lack of "✨ Initialized git repository" in the log
|
|
572
588
|
expect(std).toMatchInlineSnapshot(`
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
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
|
+
`);
|
|
587
604
|
});
|
|
588
605
|
|
|
589
606
|
// I... don't know how to test this lol
|
|
@@ -591,7 +608,7 @@ describe("init", () => {
|
|
|
591
608
|
"should not offer to initialize a git repo if git is not installed"
|
|
592
609
|
);
|
|
593
610
|
|
|
594
|
-
it("should initialize git repo with
|
|
611
|
+
it("should initialize git repo with the user's default branch", async () => {
|
|
595
612
|
mockConfirm(
|
|
596
613
|
{
|
|
597
614
|
text: "Would you like to use git to manage this Worker?",
|
|
@@ -604,17 +621,17 @@ describe("init", () => {
|
|
|
604
621
|
);
|
|
605
622
|
await runWrangler("init");
|
|
606
623
|
expect(std).toMatchInlineSnapshot(`
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
624
|
+
Object {
|
|
625
|
+
"debug": "",
|
|
626
|
+
"err": "",
|
|
627
|
+
"out": "✨ Created wrangler.toml
|
|
628
|
+
✨ Initialized git repository",
|
|
629
|
+
"warn": "",
|
|
630
|
+
}
|
|
631
|
+
`);
|
|
615
632
|
|
|
616
633
|
expect(execaSync("git", ["symbolic-ref", "HEAD"]).stdout).toEqual(
|
|
617
|
-
|
|
634
|
+
`refs/heads/${getDefaultBranchName()}`
|
|
618
635
|
);
|
|
619
636
|
});
|
|
620
637
|
});
|
|
@@ -658,14 +675,14 @@ describe("init", () => {
|
|
|
658
675
|
});
|
|
659
676
|
expect(mockPackageManager.install).toHaveBeenCalled();
|
|
660
677
|
expect(std).toMatchInlineSnapshot(`
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
678
|
+
Object {
|
|
679
|
+
"debug": "",
|
|
680
|
+
"err": "",
|
|
681
|
+
"out": "✨ Created wrangler.toml
|
|
682
|
+
✨ Created package.json",
|
|
683
|
+
"warn": "",
|
|
684
|
+
}
|
|
685
|
+
`);
|
|
669
686
|
});
|
|
670
687
|
|
|
671
688
|
it("should create a package.json, with the specified name, if none is found and user confirms", async () => {
|
|
@@ -705,14 +722,14 @@ describe("init", () => {
|
|
|
705
722
|
},
|
|
706
723
|
});
|
|
707
724
|
expect(std).toMatchInlineSnapshot(`
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
725
|
+
Object {
|
|
726
|
+
"debug": "",
|
|
727
|
+
"err": "",
|
|
728
|
+
"out": "✨ Created my-worker/wrangler.toml
|
|
729
|
+
✨ Created my-worker/package.json",
|
|
730
|
+
"warn": "",
|
|
731
|
+
}
|
|
732
|
+
`);
|
|
716
733
|
});
|
|
717
734
|
|
|
718
735
|
it("should not touch an existing package.json in the same directory", async () => {
|
|
@@ -748,13 +765,13 @@ describe("init", () => {
|
|
|
748
765
|
},
|
|
749
766
|
});
|
|
750
767
|
expect(std).toMatchInlineSnapshot(`
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
768
|
+
Object {
|
|
769
|
+
"debug": "",
|
|
770
|
+
"err": "",
|
|
771
|
+
"out": "✨ Created wrangler.toml",
|
|
772
|
+
"warn": "",
|
|
773
|
+
}
|
|
774
|
+
`);
|
|
758
775
|
});
|
|
759
776
|
|
|
760
777
|
it("should not touch an existing package.json in an ancestor directory, when a name is passed", async () => {
|
|
@@ -798,14 +815,14 @@ describe("init", () => {
|
|
|
798
815
|
},
|
|
799
816
|
});
|
|
800
817
|
expect(std).toMatchInlineSnapshot(`
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
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
|
+
`);
|
|
809
826
|
});
|
|
810
827
|
|
|
811
828
|
it("should offer to install wrangler into an existing package.json", async () => {
|
|
@@ -848,14 +865,14 @@ describe("init", () => {
|
|
|
848
865
|
`wrangler@${wranglerVersion}`
|
|
849
866
|
);
|
|
850
867
|
expect(std).toMatchInlineSnapshot(`
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
868
|
+
Object {
|
|
869
|
+
"debug": "",
|
|
870
|
+
"err": "",
|
|
871
|
+
"out": "✨ Created wrangler.toml
|
|
872
|
+
✨ Installed wrangler into devDependencies",
|
|
873
|
+
"warn": "",
|
|
874
|
+
}
|
|
875
|
+
`);
|
|
859
876
|
});
|
|
860
877
|
|
|
861
878
|
it("should offer to install wrangler into a package.json relative to the target directory, if no name is provided", async () => {
|
|
@@ -902,14 +919,14 @@ describe("init", () => {
|
|
|
902
919
|
);
|
|
903
920
|
expect(mockPackageManager.cwd).toBe(process.cwd());
|
|
904
921
|
expect(std).toMatchInlineSnapshot(`
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
922
|
+
Object {
|
|
923
|
+
"debug": "",
|
|
924
|
+
"err": "",
|
|
925
|
+
"out": "✨ Created wrangler.toml
|
|
926
|
+
✨ Installed wrangler into devDependencies",
|
|
927
|
+
"warn": "",
|
|
928
|
+
}
|
|
929
|
+
`);
|
|
913
930
|
});
|
|
914
931
|
|
|
915
932
|
it("should not touch an existing package.json in an ancestor directory", async () => {
|
|
@@ -951,13 +968,13 @@ describe("init", () => {
|
|
|
951
968
|
},
|
|
952
969
|
});
|
|
953
970
|
expect(std).toMatchInlineSnapshot(`
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
971
|
+
Object {
|
|
972
|
+
"debug": "",
|
|
973
|
+
"err": "",
|
|
974
|
+
"out": "✨ Created wrangler.toml",
|
|
975
|
+
"warn": "",
|
|
976
|
+
}
|
|
977
|
+
`);
|
|
961
978
|
});
|
|
962
979
|
});
|
|
963
980
|
|
|
@@ -975,7 +992,8 @@ describe("init", () => {
|
|
|
975
992
|
{
|
|
976
993
|
text: "Would you like to use TypeScript?",
|
|
977
994
|
result: false,
|
|
978
|
-
}
|
|
995
|
+
},
|
|
996
|
+
{ text: "Would you like us to write your first test?", result: false }
|
|
979
997
|
);
|
|
980
998
|
mockSelect({
|
|
981
999
|
text: "Would you like to create a Worker at src/index.js?",
|
|
@@ -1002,17 +1020,17 @@ describe("init", () => {
|
|
|
1002
1020
|
},
|
|
1003
1021
|
});
|
|
1004
1022
|
expect(std).toMatchInlineSnapshot(`
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
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
|
+
`);
|
|
1016
1034
|
});
|
|
1017
1035
|
|
|
1018
1036
|
it("should offer to create a worker in a typescript project", async () => {
|
|
@@ -1028,6 +1046,10 @@ describe("init", () => {
|
|
|
1028
1046
|
{
|
|
1029
1047
|
text: "Would you like to use TypeScript?",
|
|
1030
1048
|
result: true,
|
|
1049
|
+
},
|
|
1050
|
+
{
|
|
1051
|
+
text: "Would you like us to write your first test with Vitest?",
|
|
1052
|
+
result: true,
|
|
1031
1053
|
}
|
|
1032
1054
|
);
|
|
1033
1055
|
mockSelect({
|
|
@@ -1051,19 +1073,20 @@ describe("init", () => {
|
|
|
1051
1073
|
},
|
|
1052
1074
|
});
|
|
1053
1075
|
expect(std).toMatchInlineSnapshot(`
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
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
|
+
`);
|
|
1067
1090
|
});
|
|
1068
1091
|
|
|
1069
1092
|
it("should add scripts for a typescript project with .ts extension", async () => {
|
|
@@ -1083,6 +1106,10 @@ describe("init", () => {
|
|
|
1083
1106
|
{
|
|
1084
1107
|
text: "Would you like to use TypeScript?",
|
|
1085
1108
|
result: true,
|
|
1109
|
+
},
|
|
1110
|
+
{
|
|
1111
|
+
text: "Would you like us to write your first test with Vitest?",
|
|
1112
|
+
result: true,
|
|
1086
1113
|
}
|
|
1087
1114
|
);
|
|
1088
1115
|
mockSelect({
|
|
@@ -1109,15 +1136,16 @@ describe("init", () => {
|
|
|
1109
1136
|
},
|
|
1110
1137
|
});
|
|
1111
1138
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
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
|
+
`);
|
|
1121
1149
|
});
|
|
1122
1150
|
|
|
1123
1151
|
it("should not overwrite package.json scripts for a typescript project", async () => {
|
|
@@ -1133,6 +1161,10 @@ describe("init", () => {
|
|
|
1133
1161
|
{
|
|
1134
1162
|
text: "Would you like to use TypeScript?",
|
|
1135
1163
|
result: true,
|
|
1164
|
+
},
|
|
1165
|
+
{
|
|
1166
|
+
text: "Would you like us to write your first test with Vitest?",
|
|
1167
|
+
result: true,
|
|
1136
1168
|
}
|
|
1137
1169
|
);
|
|
1138
1170
|
mockSelect({
|
|
@@ -1169,14 +1201,15 @@ describe("init", () => {
|
|
|
1169
1201
|
},
|
|
1170
1202
|
});
|
|
1171
1203
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
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
|
+
`);
|
|
1180
1213
|
});
|
|
1181
1214
|
|
|
1182
1215
|
it("should not offer to create a worker in a ts project if a file already exists at the location", async () => {
|
|
@@ -1211,15 +1244,15 @@ describe("init", () => {
|
|
|
1211
1244
|
},
|
|
1212
1245
|
});
|
|
1213
1246
|
expect(std).toMatchInlineSnapshot(`
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
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
|
+
`);
|
|
1223
1256
|
});
|
|
1224
1257
|
|
|
1225
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 () => {
|
|
@@ -1258,16 +1291,16 @@ describe("init", () => {
|
|
|
1258
1291
|
},
|
|
1259
1292
|
});
|
|
1260
1293
|
expect(std).toMatchInlineSnapshot(`
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
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
|
+
`);
|
|
1271
1304
|
});
|
|
1272
1305
|
|
|
1273
1306
|
it("should create a tsconfig.json and install `workers-types` if none is found and user confirms", async () => {
|
|
@@ -1298,7 +1331,7 @@ describe("init", () => {
|
|
|
1298
1331
|
contents: {
|
|
1299
1332
|
config: {
|
|
1300
1333
|
compilerOptions: expect.objectContaining({
|
|
1301
|
-
types: ["@cloudflare/workers-types"],
|
|
1334
|
+
types: ["@cloudflare/workers-types", "jest"],
|
|
1302
1335
|
}),
|
|
1303
1336
|
},
|
|
1304
1337
|
error: undefined,
|
|
@@ -1311,23 +1344,29 @@ describe("init", () => {
|
|
|
1311
1344
|
"typescript"
|
|
1312
1345
|
);
|
|
1313
1346
|
expect(std).toMatchInlineSnapshot(`
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
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
|
+
`);
|
|
1324
1357
|
});
|
|
1325
1358
|
|
|
1326
1359
|
it("should not touch an existing tsconfig.json in the same directory", async () => {
|
|
1327
|
-
mockConfirm(
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
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
|
+
);
|
|
1331
1370
|
mockSelect({
|
|
1332
1371
|
text: "Would you like to create a Worker at src/index.ts?",
|
|
1333
1372
|
result: "fetch",
|
|
@@ -1358,17 +1397,19 @@ describe("init", () => {
|
|
|
1358
1397
|
},
|
|
1359
1398
|
});
|
|
1360
1399
|
expect(std).toMatchInlineSnapshot(`
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
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
|
+
`);
|
|
1372
1413
|
});
|
|
1373
1414
|
|
|
1374
1415
|
it("should not touch an existing tsconfig.json in the ancestor of a target directory, if a name is passed", async () => {
|
|
@@ -1384,6 +1425,10 @@ describe("init", () => {
|
|
|
1384
1425
|
{
|
|
1385
1426
|
text: "Would you like to use TypeScript?",
|
|
1386
1427
|
result: true,
|
|
1428
|
+
},
|
|
1429
|
+
{
|
|
1430
|
+
text: "Would you like us to write your first test with Vitest?",
|
|
1431
|
+
result: true,
|
|
1387
1432
|
}
|
|
1388
1433
|
);
|
|
1389
1434
|
mockSelect({
|
|
@@ -1416,20 +1461,21 @@ describe("init", () => {
|
|
|
1416
1461
|
},
|
|
1417
1462
|
});
|
|
1418
1463
|
expect(std).toMatchInlineSnapshot(`
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
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
|
+
`);
|
|
1433
1479
|
});
|
|
1434
1480
|
|
|
1435
1481
|
it("should offer to install type definitions in an existing typescript project", async () => {
|
|
@@ -1475,22 +1521,28 @@ describe("init", () => {
|
|
|
1475
1521
|
"@cloudflare/workers-types"
|
|
1476
1522
|
);
|
|
1477
1523
|
expect(std).toMatchInlineSnapshot(`
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
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
|
+
`);
|
|
1487
1533
|
});
|
|
1488
1534
|
|
|
1489
1535
|
it("should not touch an existing tsconfig.json in an ancestor directory", async () => {
|
|
1490
|
-
mockConfirm(
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
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
|
+
);
|
|
1494
1546
|
mockSelect({
|
|
1495
1547
|
text: "Would you like to create a Worker at src/index.ts?",
|
|
1496
1548
|
result: "fetch",
|
|
@@ -1523,17 +1575,19 @@ describe("init", () => {
|
|
|
1523
1575
|
},
|
|
1524
1576
|
});
|
|
1525
1577
|
expect(std).toMatchInlineSnapshot(`
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
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
|
+
`);
|
|
1537
1591
|
});
|
|
1538
1592
|
});
|
|
1539
1593
|
|
|
@@ -1555,7 +1609,8 @@ describe("init", () => {
|
|
|
1555
1609
|
{
|
|
1556
1610
|
text: "Would you like to use TypeScript?",
|
|
1557
1611
|
result: false,
|
|
1558
|
-
}
|
|
1612
|
+
},
|
|
1613
|
+
{ text: "Would you like us to write your first test?", result: false }
|
|
1559
1614
|
);
|
|
1560
1615
|
mockSelect({
|
|
1561
1616
|
text: "Would you like to create a Worker at src/index.js?",
|
|
@@ -1581,13 +1636,134 @@ describe("init", () => {
|
|
|
1581
1636
|
},
|
|
1582
1637
|
});
|
|
1583
1638
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1639
|
+
"✨ Created wrangler.toml
|
|
1640
|
+
✨ Created package.json
|
|
1641
|
+
✨ Created src/index.js
|
|
1587
1642
|
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
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
|
+
`);
|
|
1591
1767
|
});
|
|
1592
1768
|
|
|
1593
1769
|
it("should not overwrite package.json scripts for a non-ts project with .js extension", async () => {
|
|
@@ -1603,7 +1779,8 @@ describe("init", () => {
|
|
|
1603
1779
|
{
|
|
1604
1780
|
text: "Would you like to use TypeScript?",
|
|
1605
1781
|
result: false,
|
|
1606
|
-
}
|
|
1782
|
+
},
|
|
1783
|
+
{ text: "Would you like us to write your first test?", result: false }
|
|
1607
1784
|
);
|
|
1608
1785
|
mockSelect({
|
|
1609
1786
|
text: "Would you like to create a Worker at src/index.js?",
|
|
@@ -1639,12 +1816,12 @@ describe("init", () => {
|
|
|
1639
1816
|
},
|
|
1640
1817
|
});
|
|
1641
1818
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1642
|
-
|
|
1643
|
-
|
|
1819
|
+
"✨ Created wrangler.toml
|
|
1820
|
+
✨ Created src/index.js
|
|
1644
1821
|
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1822
|
+
To start developing your Worker, run \`npx wrangler dev\`
|
|
1823
|
+
To publish your Worker to the Internet, run \`npx wrangler publish\`"
|
|
1824
|
+
`);
|
|
1648
1825
|
});
|
|
1649
1826
|
|
|
1650
1827
|
it("should not offer to create a worker in a non-ts project if a file already exists at the location", async () => {
|
|
@@ -1679,13 +1856,13 @@ describe("init", () => {
|
|
|
1679
1856
|
},
|
|
1680
1857
|
});
|
|
1681
1858
|
expect(std).toMatchInlineSnapshot(`
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1859
|
+
Object {
|
|
1860
|
+
"debug": "",
|
|
1861
|
+
"err": "",
|
|
1862
|
+
"out": "✨ Created wrangler.toml",
|
|
1863
|
+
"warn": "",
|
|
1864
|
+
}
|
|
1865
|
+
`);
|
|
1689
1866
|
});
|
|
1690
1867
|
|
|
1691
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 () => {
|
|
@@ -1722,13 +1899,13 @@ describe("init", () => {
|
|
|
1722
1899
|
},
|
|
1723
1900
|
});
|
|
1724
1901
|
expect(std).toMatchInlineSnapshot(`
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1902
|
+
Object {
|
|
1903
|
+
"debug": "",
|
|
1904
|
+
"err": "",
|
|
1905
|
+
"out": "✨ Created my-worker/wrangler.toml",
|
|
1906
|
+
"warn": "",
|
|
1907
|
+
}
|
|
1908
|
+
`);
|
|
1732
1909
|
});
|
|
1733
1910
|
});
|
|
1734
1911
|
|
|
@@ -1759,21 +1936,22 @@ describe("init", () => {
|
|
|
1759
1936
|
},
|
|
1760
1937
|
});
|
|
1761
1938
|
expect(std).toMatchInlineSnapshot(`
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
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
|
+
`);
|
|
1777
1955
|
});
|
|
1778
1956
|
|
|
1779
1957
|
it('should create a worker in a nested directory if "name" is path/to/worker', async () => {
|
|
@@ -1788,21 +1966,22 @@ describe("init", () => {
|
|
|
1788
1966
|
},
|
|
1789
1967
|
});
|
|
1790
1968
|
expect(std).toMatchInlineSnapshot(`
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
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
|
+
`);
|
|
1806
1985
|
});
|
|
1807
1986
|
|
|
1808
1987
|
it("should normalize characters that aren't lowercase alphanumeric, underscores, or dashes", async () => {
|
|
@@ -1817,21 +1996,22 @@ describe("init", () => {
|
|
|
1817
1996
|
},
|
|
1818
1997
|
});
|
|
1819
1998
|
expect(std).toMatchInlineSnapshot(`
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
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
|
+
`);
|
|
1835
2015
|
});
|
|
1836
2016
|
|
|
1837
2017
|
it("should ignore ancestor files (such as wrangler.toml, package.json and tsconfig.json) if a name/path is given", async () => {
|
|
@@ -1851,6 +2031,10 @@ describe("init", () => {
|
|
|
1851
2031
|
{
|
|
1852
2032
|
text: "Would you like to install the type definitions for Workers into your package.json?",
|
|
1853
2033
|
result: true,
|
|
2034
|
+
},
|
|
2035
|
+
{
|
|
2036
|
+
text: "Would you like us to write your first test with Vitest?",
|
|
2037
|
+
result: true,
|
|
1854
2038
|
}
|
|
1855
2039
|
);
|
|
1856
2040
|
mockSelect({
|
|
@@ -1900,8 +2084,926 @@ describe("init", () => {
|
|
|
1900
2084
|
});
|
|
1901
2085
|
});
|
|
1902
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
|
*/
|