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