wrangler 0.0.0-e978986 → 0.0.0-ea7ee45
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 +7 -1
- package/bin/wrangler.js +111 -57
- package/kv-asset-handler.js +1 -0
- package/miniflare-dist/index.mjs +9 -2
- package/package.json +156 -152
- package/src/__tests__/config-cache.test.ts +24 -24
- package/src/__tests__/configuration.test.ts +3818 -3363
- package/src/__tests__/dev.test.tsx +1128 -949
- package/src/__tests__/guess-worker-format.test.ts +68 -68
- package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
- package/src/__tests__/helpers/faye-websocket.d.ts +4 -4
- package/src/__tests__/helpers/mock-account-id.ts +24 -24
- package/src/__tests__/helpers/mock-bin.ts +20 -20
- package/src/__tests__/helpers/mock-cfetch.ts +92 -92
- package/src/__tests__/helpers/mock-console.ts +49 -39
- package/src/__tests__/helpers/mock-dialogs.ts +94 -71
- package/src/__tests__/helpers/mock-http-server.ts +30 -30
- package/src/__tests__/helpers/mock-istty.ts +65 -18
- package/src/__tests__/helpers/mock-kv.ts +26 -26
- package/src/__tests__/helpers/mock-oauth-flow.ts +223 -228
- package/src/__tests__/helpers/mock-process.ts +39 -0
- package/src/__tests__/helpers/mock-stdin.ts +82 -77
- package/src/__tests__/helpers/mock-web-socket.ts +21 -21
- package/src/__tests__/helpers/run-in-tmp.ts +27 -27
- package/src/__tests__/helpers/run-wrangler.ts +8 -8
- package/src/__tests__/helpers/write-worker-source.ts +16 -16
- package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
- package/src/__tests__/https-options.test.ts +104 -104
- package/src/__tests__/index.test.ts +239 -233
- package/src/__tests__/init.test.ts +1605 -1180
- package/src/__tests__/jest.setup.ts +63 -33
- package/src/__tests__/kv.test.ts +1128 -990
- package/src/__tests__/logger.test.ts +100 -74
- package/src/__tests__/package-manager.test.ts +303 -303
- package/src/__tests__/pages.test.ts +1160 -563
- package/src/__tests__/parse.test.ts +252 -252
- package/src/__tests__/publish.test.ts +6344 -5299
- package/src/__tests__/pubsub.test.ts +276 -0
- package/src/__tests__/r2.test.ts +133 -133
- package/src/__tests__/route.test.ts +18 -18
- package/src/__tests__/secret.test.ts +382 -377
- package/src/__tests__/tail.test.ts +530 -530
- package/src/__tests__/user.test.ts +123 -111
- package/src/__tests__/whoami.test.tsx +198 -83
- package/src/__tests__/worker-namespace.test.ts +327 -0
- package/src/abort.d.ts +1 -1
- package/src/api/dev.ts +39 -0
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +29 -0
- package/src/bundle.ts +158 -146
- package/src/cfetch/index.ts +80 -80
- package/src/cfetch/internal.ts +92 -88
- package/src/cli.ts +21 -7
- package/src/config/config.ts +204 -195
- package/src/config/diagnostics.ts +61 -61
- package/src/config/environment.ts +367 -357
- package/src/config/index.ts +193 -193
- package/src/config/validation-helpers.ts +366 -357
- package/src/config/validation.ts +1521 -1367
- package/src/config-cache.ts +24 -25
- package/src/create-worker-preview.ts +206 -136
- package/src/create-worker-upload-form.ts +238 -238
- package/src/dev/dev-vars.ts +13 -13
- package/src/dev/dev.tsx +334 -336
- package/src/dev/local.tsx +304 -272
- package/src/dev/remote.tsx +351 -211
- package/src/dev/use-esbuild.ts +126 -94
- package/src/dev.tsx +526 -0
- package/src/dialogs.tsx +97 -97
- package/src/durable.ts +87 -87
- package/src/entry.ts +234 -228
- package/src/environment-variables.ts +23 -23
- package/src/errors.ts +6 -6
- package/src/generate.ts +33 -0
- package/src/git-client.ts +42 -0
- package/src/https-options.ts +79 -79
- package/src/index.tsx +1775 -2752
- package/src/init.ts +549 -0
- package/src/inspect.ts +593 -593
- package/src/intl-polyfill.d.ts +123 -123
- package/src/kv.ts +277 -277
- package/src/logger.ts +46 -39
- package/src/miniflare-cli/enum-keys.ts +8 -8
- package/src/miniflare-cli/index.ts +42 -31
- package/src/miniflare-cli/request-context.ts +18 -18
- package/src/module-collection.ts +212 -212
- package/src/open-in-browser.ts +4 -6
- package/src/package-manager.ts +123 -123
- package/src/pages/build.tsx +202 -0
- package/src/pages/constants.ts +7 -0
- package/src/pages/deployments.tsx +101 -0
- package/src/pages/dev.tsx +964 -0
- package/src/pages/functions/buildPlugin.ts +105 -0
- package/src/pages/functions/buildWorker.ts +151 -0
- package/{pages → src/pages}/functions/filepath-routing.test.ts +113 -113
- package/src/pages/functions/filepath-routing.ts +189 -0
- package/src/pages/functions/identifiers.ts +78 -0
- package/src/pages/functions/routes.ts +151 -0
- package/src/pages/index.tsx +84 -0
- package/src/pages/projects.tsx +157 -0
- package/src/pages/publish.tsx +335 -0
- package/src/pages/types.ts +40 -0
- package/src/pages/upload.tsx +384 -0
- package/src/pages/utils.ts +12 -0
- package/src/parse.ts +209 -125
- package/src/paths.ts +6 -6
- package/src/preview.ts +31 -0
- package/src/proxy.ts +400 -389
- package/src/publish.ts +688 -505
- package/src/pubsub/index.ts +286 -0
- package/src/pubsub/pubsub-commands.tsx +594 -0
- package/src/r2.ts +19 -19
- package/src/selfsigned.d.ts +23 -23
- package/src/sites.tsx +278 -201
- package/src/tail/filters.ts +108 -108
- package/src/tail/index.ts +217 -217
- package/src/tail/printing.ts +45 -45
- package/src/update-check.ts +11 -11
- package/src/user/choose-account.tsx +60 -0
- package/src/user/env-vars.ts +46 -0
- package/src/user/generate-auth-url.ts +33 -0
- package/src/user/generate-random-state.ts +16 -0
- package/src/user/index.ts +3 -0
- package/src/user/user.tsx +1130 -0
- package/src/whoami.tsx +61 -41
- package/src/worker-namespace.ts +190 -0
- package/src/worker.ts +104 -99
- package/src/zones.ts +76 -0
- package/templates/checked-fetch.js +17 -0
- package/templates/new-worker-scheduled.js +4 -4
- package/templates/new-worker-scheduled.ts +16 -16
- package/templates/new-worker.js +3 -3
- package/templates/new-worker.ts +15 -15
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-template-plugin.ts +155 -0
- package/templates/pages-template-worker.ts +161 -0
- package/templates/static-asset-facade.js +32 -36
- package/templates/tsconfig.json +95 -95
- package/wrangler-dist/cli.js +40620 -39223
- package/pages/functions/buildPlugin.ts +0 -105
- package/pages/functions/buildWorker.ts +0 -151
- package/pages/functions/filepath-routing.ts +0 -189
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -156
- package/pages/functions/template-plugin.ts +0 -147
- package/pages/functions/template-worker.ts +0 -143
- package/src/pages.tsx +0 -2027
- package/src/user.tsx +0 -1203
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
|
-
import * as fsp from "node:fs/promises";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
import * as TOML from "@iarna/toml";
|
|
5
4
|
import { execa, execaSync } from "execa";
|
|
@@ -8,47 +7,61 @@ import { version as wranglerVersion } from "../../package.json";
|
|
|
8
7
|
import { getPackageManager } from "../package-manager";
|
|
9
8
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
10
9
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
mockConfirm,
|
|
11
|
+
clearConfirmMocks,
|
|
12
|
+
mockSelect,
|
|
13
|
+
clearSelectMocks,
|
|
15
14
|
} from "./helpers/mock-dialogs";
|
|
16
15
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
17
16
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
18
17
|
import type { PackageManager } from "../package-manager";
|
|
19
18
|
|
|
19
|
+
/**
|
|
20
|
+
* An expectation matcher for the minimal generated wrangler.toml.
|
|
21
|
+
*/
|
|
22
|
+
const MINIMAL_WRANGLER_TOML = {
|
|
23
|
+
compatibility_date: expect.any(String),
|
|
24
|
+
name: expect.stringContaining("wrangler-tests"),
|
|
25
|
+
main: "src/index.ts",
|
|
26
|
+
};
|
|
27
|
+
|
|
20
28
|
describe("init", () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
29
|
+
let mockPackageManager: PackageManager;
|
|
30
|
+
runInTempDir();
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
mockPackageManager = {
|
|
34
|
+
cwd: process.cwd(),
|
|
35
|
+
// @ts-expect-error we're making a fake package manager here
|
|
36
|
+
type: "mockpm",
|
|
37
|
+
addDevDeps: jest.fn(),
|
|
38
|
+
install: jest.fn(),
|
|
39
|
+
};
|
|
40
|
+
(getPackageManager as jest.Mock).mockResolvedValue(mockPackageManager);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
clearConfirmMocks();
|
|
45
|
+
clearSelectMocks();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const std = mockConsoleMethods();
|
|
49
|
+
|
|
50
|
+
describe("options", () => {
|
|
51
|
+
it("should initialize with no interactive prompts if `--yes` is used", async () => {
|
|
52
|
+
await runWrangler("init --yes");
|
|
53
|
+
|
|
54
|
+
checkFiles({
|
|
55
|
+
items: {
|
|
56
|
+
"./src/index.js": false,
|
|
57
|
+
"./src/index.ts": true,
|
|
58
|
+
"./tsconfig.json": true,
|
|
59
|
+
"./package.json": true,
|
|
60
|
+
"./wrangler.toml": true,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
52
65
|
"✨ Created wrangler.toml
|
|
53
66
|
✨ Initialized git repository
|
|
54
67
|
✨ Created package.json
|
|
@@ -59,23 +72,27 @@ describe("init", () => {
|
|
|
59
72
|
To start developing your Worker, run \`npm start\`
|
|
60
73
|
To publish your Worker to the Internet, run \`npm run deploy\`"
|
|
61
74
|
`);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
76
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("should initialize with no interactive prompts if `--yes` is used (named worker)", async () => {
|
|
80
|
+
await runWrangler("init my-worker --yes");
|
|
81
|
+
|
|
82
|
+
checkFiles({
|
|
83
|
+
items: {
|
|
84
|
+
"./my-worker/src/index.js": false,
|
|
85
|
+
"./my-worker/src/index.ts": true,
|
|
86
|
+
"./my-worker/tsconfig.json": true,
|
|
87
|
+
"./my-worker/package.json": true,
|
|
88
|
+
"./my-worker/wrangler.toml": wranglerToml({
|
|
89
|
+
...MINIMAL_WRANGLER_TOML,
|
|
90
|
+
name: "my-worker",
|
|
91
|
+
}),
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
79
96
|
"✨ Created my-worker/wrangler.toml
|
|
80
97
|
✨ Initialized git repository at my-worker
|
|
81
98
|
✨ Created my-worker/package.json
|
|
@@ -86,19 +103,24 @@ describe("init", () => {
|
|
|
86
103
|
To start developing your Worker, run \`cd my-worker && npm start\`
|
|
87
104
|
To publish your Worker to the Internet, run \`npm run deploy\`"
|
|
88
105
|
`);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
106
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
107
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("should initialize with no interactive prompts if `-y` is used", async () => {
|
|
111
|
+
await runWrangler("init -y");
|
|
112
|
+
|
|
113
|
+
checkFiles({
|
|
114
|
+
items: {
|
|
115
|
+
"./src/index.js": false,
|
|
116
|
+
"./src/index.ts": true,
|
|
117
|
+
"./tsconfig.json": true,
|
|
118
|
+
"./package.json": true,
|
|
119
|
+
"./wrangler.toml": true,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
expect(std).toMatchInlineSnapshot(`
|
|
102
124
|
Object {
|
|
103
125
|
"debug": "",
|
|
104
126
|
"err": "",
|
|
@@ -114,35 +136,35 @@ describe("init", () => {
|
|
|
114
136
|
"warn": "",
|
|
115
137
|
}
|
|
116
138
|
`);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("should error if `--type javascript` is used", async () => {
|
|
142
|
+
await expect(
|
|
143
|
+
runWrangler("init --type javascript")
|
|
144
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
145
|
+
`"The --type option is no longer supported."`
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("should error if `--type rust` is used", async () => {
|
|
150
|
+
await expect(
|
|
151
|
+
runWrangler("init --type rust")
|
|
152
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
153
|
+
`"The --type option is no longer supported."`
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("should error if `--type webpack` is used", async () => {
|
|
158
|
+
await expect(runWrangler("init --type webpack")).rejects
|
|
159
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
138
160
|
"The --type option is no longer supported.
|
|
139
161
|
If you wish to use webpack then you will need to create a custom build."
|
|
140
162
|
`);
|
|
141
|
-
|
|
163
|
+
});
|
|
142
164
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
165
|
+
it("should error if `--site` is used", async () => {
|
|
166
|
+
await expect(runWrangler("init --site")).rejects
|
|
167
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
146
168
|
"The --site option is no longer supported.
|
|
147
169
|
If you wish to create a brand new Worker Sites project then clone the \`worker-sites-template\` starter repository:
|
|
148
170
|
|
|
@@ -154,28 +176,34 @@ describe("init", () => {
|
|
|
154
176
|
Find out more about how to create and maintain Sites projects at https://developers.cloudflare.com/workers/platform/sites.
|
|
155
177
|
Have you considered using Cloudflare Pages instead? See https://pages.cloudflare.com/."
|
|
156
178
|
`);
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe("wrangler.toml", () => {
|
|
183
|
+
it("should create a wrangler.toml", async () => {
|
|
184
|
+
mockConfirm(
|
|
185
|
+
{
|
|
186
|
+
text: "Would you like to use git to manage this Worker?",
|
|
187
|
+
result: false,
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
text: "No package.json found. Would you like to create one?",
|
|
191
|
+
result: false,
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
await runWrangler("init");
|
|
195
|
+
checkFiles({
|
|
196
|
+
items: {
|
|
197
|
+
"wrangler.toml": wranglerToml({
|
|
198
|
+
compatibility_date: expect.any(String),
|
|
199
|
+
name: expect.stringContaining("wrangler-tests"),
|
|
200
|
+
}),
|
|
201
|
+
"package.json": false,
|
|
202
|
+
"tsconfig.json": false,
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
expect(std).toMatchInlineSnapshot(`
|
|
179
207
|
Object {
|
|
180
208
|
"debug": "",
|
|
181
209
|
"err": "",
|
|
@@ -183,29 +211,33 @@ describe("init", () => {
|
|
|
183
211
|
"warn": "",
|
|
184
212
|
}
|
|
185
213
|
`);
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("should create a wrangler.toml and a directory for a named Worker ", async () => {
|
|
217
|
+
mockConfirm(
|
|
218
|
+
{
|
|
219
|
+
text: "Would you like to use git to manage this Worker?",
|
|
220
|
+
result: false,
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
text: "No package.json found. Would you like to create one?",
|
|
224
|
+
result: false,
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
await runWrangler("init my-worker");
|
|
228
|
+
|
|
229
|
+
checkFiles({
|
|
230
|
+
items: {
|
|
231
|
+
"my-worker/wrangler.toml": wranglerToml({
|
|
232
|
+
compatibility_date: expect.any(String),
|
|
233
|
+
name: "my-worker",
|
|
234
|
+
}),
|
|
235
|
+
"my-worker/package.json": false,
|
|
236
|
+
"my-worker/tsconfig.json": false,
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
expect(std).toMatchInlineSnapshot(`
|
|
209
241
|
Object {
|
|
210
242
|
"debug": "",
|
|
211
243
|
"err": "",
|
|
@@ -213,24 +245,37 @@ describe("init", () => {
|
|
|
213
245
|
"warn": "",
|
|
214
246
|
}
|
|
215
247
|
`);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("should display warning when wrangler.toml already exists, and exit if user does not want to carry on", async () => {
|
|
251
|
+
writeFiles({
|
|
252
|
+
items: {
|
|
253
|
+
"wrangler.toml": wranglerToml({
|
|
254
|
+
// use a fake value to make sure the file is not overwritten
|
|
255
|
+
compatibility_date: "something-else",
|
|
256
|
+
}),
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
mockConfirm({
|
|
261
|
+
text: "Do you want to continue initializing this project?",
|
|
262
|
+
result: false,
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
await runWrangler("init");
|
|
266
|
+
expect(std.warn).toContain("wrangler.toml already exists!");
|
|
267
|
+
|
|
268
|
+
checkFiles({
|
|
269
|
+
items: {
|
|
270
|
+
"wrangler.toml": wranglerToml({
|
|
271
|
+
compatibility_date: "something-else",
|
|
272
|
+
}),
|
|
273
|
+
"package.json": false,
|
|
274
|
+
"tsconfig.json": false,
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
expect(std).toMatchInlineSnapshot(`
|
|
234
279
|
Object {
|
|
235
280
|
"debug": "",
|
|
236
281
|
"err": "",
|
|
@@ -240,26 +285,34 @@ describe("init", () => {
|
|
|
240
285
|
",
|
|
241
286
|
}
|
|
242
287
|
`);
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("should display warning when wrangler.toml already exists in the target directory, and exit if user does not want to carry on", async () => {
|
|
291
|
+
writeFiles({
|
|
292
|
+
items: {
|
|
293
|
+
"path/to/worker/wrangler.toml": wranglerToml({
|
|
294
|
+
compatibility_date: "something-else",
|
|
295
|
+
}),
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
mockConfirm({
|
|
299
|
+
text: "Do you want to continue initializing this project?",
|
|
300
|
+
result: false,
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
await runWrangler("init path/to/worker");
|
|
304
|
+
|
|
305
|
+
expect(std.warn).toContain("wrangler.toml already exists!");
|
|
306
|
+
checkFiles({
|
|
307
|
+
items: {
|
|
308
|
+
"path/to/worker/wrangler.toml": wranglerToml({
|
|
309
|
+
compatibility_date: "something-else",
|
|
310
|
+
}),
|
|
311
|
+
"package.json": false,
|
|
312
|
+
"tsconfig.json": false,
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
expect(std).toMatchInlineSnapshot(`
|
|
263
316
|
Object {
|
|
264
317
|
"debug": "",
|
|
265
318
|
"err": "",
|
|
@@ -269,69 +322,85 @@ describe("init", () => {
|
|
|
269
322
|
",
|
|
270
323
|
}
|
|
271
324
|
`);
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it("should not overwrite an existing wrangler.toml, after agreeing to other prompts", async () => {
|
|
328
|
+
writeFiles({
|
|
329
|
+
items: {
|
|
330
|
+
"wrangler.toml": wranglerToml({
|
|
331
|
+
compatibility_date: "something-else",
|
|
332
|
+
}),
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
mockConfirm(
|
|
336
|
+
{
|
|
337
|
+
text: "Would you like to use git to manage this Worker?",
|
|
338
|
+
result: true,
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
text: "Do you want to continue initializing this project?",
|
|
342
|
+
result: true,
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
text: "No package.json found. Would you like to create one?",
|
|
346
|
+
result: true,
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
text: "Would you like to use TypeScript?",
|
|
350
|
+
result: true,
|
|
351
|
+
}
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
mockSelect({
|
|
355
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
356
|
+
result: "fetch",
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
await runWrangler("init");
|
|
360
|
+
|
|
361
|
+
checkFiles({
|
|
362
|
+
items: {
|
|
363
|
+
"wrangler.toml": wranglerToml({
|
|
364
|
+
compatibility_date: "something-else",
|
|
365
|
+
}),
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it("should display warning when wrangler.toml already exists, but continue if user does want to carry on", async () => {
|
|
371
|
+
writeFiles({
|
|
372
|
+
items: {
|
|
373
|
+
"wrangler.toml": wranglerToml({
|
|
374
|
+
compatibility_date: "something-else",
|
|
375
|
+
}),
|
|
376
|
+
},
|
|
377
|
+
});
|
|
378
|
+
mockConfirm(
|
|
379
|
+
{
|
|
380
|
+
text: "Do you want to continue initializing this project?",
|
|
381
|
+
result: true,
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
text: "Would you like to use git to manage this Worker?",
|
|
385
|
+
result: false,
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
text: "No package.json found. Would you like to create one?",
|
|
389
|
+
result: false,
|
|
390
|
+
}
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
await runWrangler("init");
|
|
394
|
+
|
|
395
|
+
expect(std.warn).toContain("wrangler.toml already exists!");
|
|
396
|
+
checkFiles({
|
|
397
|
+
items: {
|
|
398
|
+
"wrangler.toml": wranglerToml({
|
|
399
|
+
compatibility_date: "something-else",
|
|
400
|
+
}),
|
|
401
|
+
},
|
|
402
|
+
});
|
|
403
|
+
expect(std).toMatchInlineSnapshot(`
|
|
335
404
|
Object {
|
|
336
405
|
"debug": "",
|
|
337
406
|
"err": "",
|
|
@@ -341,23 +410,109 @@ describe("init", () => {
|
|
|
341
410
|
",
|
|
342
411
|
}
|
|
343
412
|
`);
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it("should not add a Cron Trigger to wrangler.toml when creating a Scheduled Worker if wrangler.toml already exists", async () => {
|
|
416
|
+
writeFiles({
|
|
417
|
+
items: {
|
|
418
|
+
"wrangler.toml": wranglerToml({
|
|
419
|
+
compatibility_date: "something-else",
|
|
420
|
+
}),
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
mockConfirm(
|
|
424
|
+
{
|
|
425
|
+
text: "Would you like to use git to manage this Worker?",
|
|
426
|
+
result: true,
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
text: "Do you want to continue initializing this project?",
|
|
430
|
+
result: true,
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
text: "No package.json found. Would you like to create one?",
|
|
434
|
+
result: true,
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
text: "Would you like to use TypeScript?",
|
|
438
|
+
result: true,
|
|
439
|
+
}
|
|
440
|
+
);
|
|
441
|
+
mockSelect({
|
|
442
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
443
|
+
result: "scheduled",
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
await runWrangler("init");
|
|
447
|
+
|
|
448
|
+
checkFiles({
|
|
449
|
+
items: {
|
|
450
|
+
"wrangler.toml": wranglerToml({
|
|
451
|
+
compatibility_date: "something-else",
|
|
452
|
+
}),
|
|
453
|
+
},
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
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 () => {
|
|
458
|
+
mockConfirm(
|
|
459
|
+
{
|
|
460
|
+
text: "Would you like to use git to manage this Worker?",
|
|
461
|
+
result: true,
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
text: "No package.json found. Would you like to create one?",
|
|
465
|
+
result: true,
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
text: "Would you like to use TypeScript?",
|
|
469
|
+
result: true,
|
|
470
|
+
}
|
|
471
|
+
);
|
|
472
|
+
mockSelect({
|
|
473
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
474
|
+
result: "scheduled",
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
await runWrangler("init");
|
|
478
|
+
|
|
479
|
+
checkFiles({
|
|
480
|
+
items: {
|
|
481
|
+
"wrangler.toml": wranglerToml({
|
|
482
|
+
...MINIMAL_WRANGLER_TOML,
|
|
483
|
+
triggers: { crons: ["1 * * * *"] },
|
|
484
|
+
}),
|
|
485
|
+
},
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
describe("git init", () => {
|
|
491
|
+
it("should offer to initialize a git repository", async () => {
|
|
492
|
+
mockConfirm(
|
|
493
|
+
{
|
|
494
|
+
text: "Would you like to use git to manage this Worker?",
|
|
495
|
+
result: true,
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
text: "No package.json found. Would you like to create one?",
|
|
499
|
+
result: false,
|
|
500
|
+
}
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
await runWrangler("init");
|
|
504
|
+
|
|
505
|
+
checkFiles({
|
|
506
|
+
items: {
|
|
507
|
+
"wrangler.toml": wranglerToml({
|
|
508
|
+
compatibility_date: expect.any(String),
|
|
509
|
+
name: expect.stringContaining("wrangler-tests"),
|
|
510
|
+
}),
|
|
511
|
+
".git": { items: {} },
|
|
512
|
+
".gitignore": true,
|
|
513
|
+
},
|
|
514
|
+
});
|
|
515
|
+
expect(std).toMatchInlineSnapshot(`
|
|
361
516
|
Object {
|
|
362
517
|
"debug": "",
|
|
363
518
|
"err": "",
|
|
@@ -366,18 +521,30 @@ describe("init", () => {
|
|
|
366
521
|
"warn": "",
|
|
367
522
|
}
|
|
368
523
|
`);
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
524
|
+
expect((await execa("git", ["branch", "--show-current"])).stdout).toEqual(
|
|
525
|
+
"main"
|
|
526
|
+
);
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
it("should not offer to initialize a git repo if it's already inside one", async () => {
|
|
530
|
+
await execa("git", ["init"]);
|
|
531
|
+
setWorkingDirectory("some-folder");
|
|
532
|
+
|
|
533
|
+
await runWrangler("init -y");
|
|
534
|
+
|
|
535
|
+
checkFiles({
|
|
536
|
+
items: {
|
|
537
|
+
"wrangler.toml": wranglerToml({
|
|
538
|
+
...MINIMAL_WRANGLER_TOML,
|
|
539
|
+
name: "some-folder",
|
|
540
|
+
}),
|
|
541
|
+
".git": { items: {} },
|
|
542
|
+
".gitignore": false,
|
|
543
|
+
},
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
// Note the lack of "✨ Initialized git repository" in the log
|
|
547
|
+
expect(std).toMatchInlineSnapshot(`
|
|
381
548
|
Object {
|
|
382
549
|
"debug": "",
|
|
383
550
|
"err": "",
|
|
@@ -392,17 +559,17 @@ describe("init", () => {
|
|
|
392
559
|
"warn": "",
|
|
393
560
|
}
|
|
394
561
|
`);
|
|
395
|
-
|
|
562
|
+
});
|
|
396
563
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
564
|
+
it("should not offer to initialize a git repo if it's already inside one (when using a path as name)", async () => {
|
|
565
|
+
fs.mkdirSync("path/to/worker", { recursive: true });
|
|
566
|
+
await execa("git", ["init"], { cwd: "path/to/worker" });
|
|
567
|
+
expect(fs.lstatSync("path/to/worker/.git").isDirectory()).toBe(true);
|
|
401
568
|
|
|
402
|
-
|
|
569
|
+
await runWrangler("init path/to/worker/my-worker -y");
|
|
403
570
|
|
|
404
|
-
|
|
405
|
-
|
|
571
|
+
// Note the lack of "✨ Initialized git repository" in the log
|
|
572
|
+
expect(std).toMatchInlineSnapshot(`
|
|
406
573
|
Object {
|
|
407
574
|
"debug": "",
|
|
408
575
|
"err": "",
|
|
@@ -417,26 +584,26 @@ describe("init", () => {
|
|
|
417
584
|
"warn": "",
|
|
418
585
|
}
|
|
419
586
|
`);
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
// I... don't know how to test this lol
|
|
590
|
+
it.todo(
|
|
591
|
+
"should not offer to initialize a git repo if git is not installed"
|
|
592
|
+
);
|
|
593
|
+
|
|
594
|
+
it("should initialize git repo with `main` default branch", async () => {
|
|
595
|
+
mockConfirm(
|
|
596
|
+
{
|
|
597
|
+
text: "Would you like to use git to manage this Worker?",
|
|
598
|
+
result: true,
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
text: "No package.json found. Would you like to create one?",
|
|
602
|
+
result: false,
|
|
603
|
+
}
|
|
604
|
+
);
|
|
605
|
+
await runWrangler("init");
|
|
606
|
+
expect(std).toMatchInlineSnapshot(`
|
|
440
607
|
Object {
|
|
441
608
|
"debug": "",
|
|
442
609
|
"err": "",
|
|
@@ -446,45 +613,51 @@ describe("init", () => {
|
|
|
446
613
|
}
|
|
447
614
|
`);
|
|
448
615
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
616
|
+
expect(execaSync("git", ["symbolic-ref", "HEAD"]).stdout).toEqual(
|
|
617
|
+
"refs/heads/main"
|
|
618
|
+
);
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
describe("package.json", () => {
|
|
623
|
+
it("should create a package.json if none is found and user confirms", async () => {
|
|
624
|
+
mockConfirm(
|
|
625
|
+
{
|
|
626
|
+
text: "Would you like to use git to manage this Worker?",
|
|
627
|
+
result: false,
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
text: "No package.json found. Would you like to create one?",
|
|
631
|
+
result: true,
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
text: "Would you like to use TypeScript?",
|
|
635
|
+
result: false,
|
|
636
|
+
}
|
|
637
|
+
);
|
|
638
|
+
mockSelect({
|
|
639
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
640
|
+
result: "none",
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
await runWrangler("init");
|
|
644
|
+
|
|
645
|
+
checkFiles({
|
|
646
|
+
items: {
|
|
647
|
+
"package.json": {
|
|
648
|
+
contents: expect.objectContaining({
|
|
649
|
+
name: expect.stringContaining("wrangler-tests"),
|
|
650
|
+
version: "0.0.0",
|
|
651
|
+
devDependencies: {
|
|
652
|
+
wrangler: expect.any(String),
|
|
653
|
+
},
|
|
654
|
+
}),
|
|
655
|
+
},
|
|
656
|
+
"tsconfig.json": false,
|
|
657
|
+
},
|
|
658
|
+
});
|
|
659
|
+
expect(mockPackageManager.install).toHaveBeenCalled();
|
|
660
|
+
expect(std).toMatchInlineSnapshot(`
|
|
488
661
|
Object {
|
|
489
662
|
"debug": "",
|
|
490
663
|
"err": "",
|
|
@@ -493,33 +666,45 @@ describe("init", () => {
|
|
|
493
666
|
"warn": "",
|
|
494
667
|
}
|
|
495
668
|
`);
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
it("should create a package.json, with the specified name, if none is found and user confirms", async () => {
|
|
672
|
+
mockConfirm(
|
|
673
|
+
{
|
|
674
|
+
text: "Would you like to use git to manage this Worker?",
|
|
675
|
+
result: false,
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
text: "No package.json found. Would you like to create one?",
|
|
679
|
+
result: true,
|
|
680
|
+
},
|
|
681
|
+
{
|
|
682
|
+
text: "Would you like to use TypeScript?",
|
|
683
|
+
result: false,
|
|
684
|
+
}
|
|
685
|
+
);
|
|
686
|
+
mockSelect({
|
|
687
|
+
text: "Would you like to create a Worker at my-worker/src/index.js?",
|
|
688
|
+
result: "none",
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
await runWrangler("init my-worker");
|
|
692
|
+
|
|
693
|
+
checkFiles({
|
|
694
|
+
items: {
|
|
695
|
+
"my-worker/package.json": {
|
|
696
|
+
contents: expect.objectContaining({
|
|
697
|
+
name: "my-worker",
|
|
698
|
+
version: "0.0.0",
|
|
699
|
+
devDependencies: {
|
|
700
|
+
wrangler: expect.any(String),
|
|
701
|
+
},
|
|
702
|
+
}),
|
|
703
|
+
},
|
|
704
|
+
"my-worker/tsconfig.json": false,
|
|
705
|
+
},
|
|
706
|
+
});
|
|
707
|
+
expect(std).toMatchInlineSnapshot(`
|
|
523
708
|
Object {
|
|
524
709
|
"debug": "",
|
|
525
710
|
"err": "",
|
|
@@ -528,41 +713,41 @@ describe("init", () => {
|
|
|
528
713
|
"warn": "",
|
|
529
714
|
}
|
|
530
715
|
`);
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
it("should not touch an existing package.json in the same directory", async () => {
|
|
719
|
+
mockConfirm(
|
|
720
|
+
{
|
|
721
|
+
text: "Would you like to use git to manage this Worker?",
|
|
722
|
+
result: false,
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
text: "Would you like to install wrangler into package.json?",
|
|
726
|
+
result: false,
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
text: "Would you like to use TypeScript?",
|
|
730
|
+
result: false,
|
|
731
|
+
}
|
|
732
|
+
);
|
|
733
|
+
mockSelect({
|
|
734
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
735
|
+
result: "none",
|
|
736
|
+
});
|
|
737
|
+
writeFiles({
|
|
738
|
+
items: {
|
|
739
|
+
"package.json": { contents: { name: "test", version: "1.0.0" } },
|
|
740
|
+
},
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
await runWrangler("init");
|
|
744
|
+
|
|
745
|
+
checkFiles({
|
|
746
|
+
items: {
|
|
747
|
+
"package.json": { contents: { name: "test", version: "1.0.0" } },
|
|
748
|
+
},
|
|
749
|
+
});
|
|
750
|
+
expect(std).toMatchInlineSnapshot(`
|
|
566
751
|
Object {
|
|
567
752
|
"debug": "",
|
|
568
753
|
"err": "",
|
|
@@ -570,89 +755,99 @@ describe("init", () => {
|
|
|
570
755
|
"warn": "",
|
|
571
756
|
}
|
|
572
757
|
`);
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
it("should not touch an existing package.json in an ancestor directory, when a name is passed", async () => {
|
|
761
|
+
mockConfirm(
|
|
762
|
+
{
|
|
763
|
+
text: "Would you like to use git to manage this Worker?",
|
|
764
|
+
result: false,
|
|
765
|
+
},
|
|
766
|
+
{
|
|
767
|
+
text: "No package.json found. Would you like to create one?",
|
|
768
|
+
result: true,
|
|
769
|
+
},
|
|
770
|
+
{
|
|
771
|
+
text: "Would you like to install wrangler into path/to/worker/my-worker/package.json?",
|
|
772
|
+
result: false,
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
text: "Would you like to use TypeScript?",
|
|
776
|
+
result: false,
|
|
777
|
+
}
|
|
778
|
+
);
|
|
779
|
+
mockSelect({
|
|
780
|
+
text: "Would you like to create a Worker at path/to/worker/my-worker/src/index.js?",
|
|
781
|
+
result: "none",
|
|
782
|
+
});
|
|
783
|
+
writeFiles({
|
|
784
|
+
items: {
|
|
785
|
+
"path/to/worker/package.json": {
|
|
786
|
+
contents: { name: "test", version: "1.0.0" },
|
|
787
|
+
},
|
|
788
|
+
},
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
await runWrangler("init path/to/worker/my-worker");
|
|
792
|
+
|
|
793
|
+
checkFiles({
|
|
794
|
+
items: {
|
|
795
|
+
"path/to/worker/package.json": {
|
|
796
|
+
contents: { name: "test", version: "1.0.0" },
|
|
797
|
+
},
|
|
798
|
+
},
|
|
799
|
+
});
|
|
800
|
+
expect(std).toMatchInlineSnapshot(`
|
|
610
801
|
Object {
|
|
611
802
|
"debug": "",
|
|
612
803
|
"err": "",
|
|
613
|
-
"out": "✨ Created path/to/worker/my-worker/wrangler.toml
|
|
804
|
+
"out": "✨ Created path/to/worker/my-worker/wrangler.toml
|
|
805
|
+
✨ Created path/to/worker/my-worker/package.json",
|
|
614
806
|
"warn": "",
|
|
615
807
|
}
|
|
616
808
|
`);
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
it("should offer to install wrangler into an existing package.json", async () => {
|
|
812
|
+
mockConfirm(
|
|
813
|
+
{
|
|
814
|
+
text: "Would you like to use git to manage this Worker?",
|
|
815
|
+
result: false,
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
text: "Would you like to install wrangler into package.json?",
|
|
819
|
+
result: true,
|
|
820
|
+
},
|
|
821
|
+
{
|
|
822
|
+
text: "Would you like to use TypeScript?",
|
|
823
|
+
result: false,
|
|
824
|
+
}
|
|
825
|
+
);
|
|
826
|
+
mockSelect({
|
|
827
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
828
|
+
result: "none",
|
|
829
|
+
});
|
|
830
|
+
writeFiles({
|
|
831
|
+
items: {
|
|
832
|
+
"package.json": {
|
|
833
|
+
contents: { name: "test", version: "1.0.0" },
|
|
834
|
+
},
|
|
835
|
+
},
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
await runWrangler("init");
|
|
839
|
+
|
|
840
|
+
checkFiles({
|
|
841
|
+
items: {
|
|
842
|
+
"package.json": {
|
|
843
|
+
contents: { name: "test", version: "1.0.0" },
|
|
844
|
+
},
|
|
845
|
+
},
|
|
846
|
+
});
|
|
847
|
+
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
848
|
+
`wrangler@${wranglerVersion}`
|
|
849
|
+
);
|
|
850
|
+
expect(std).toMatchInlineSnapshot(`
|
|
656
851
|
Object {
|
|
657
852
|
"debug": "",
|
|
658
853
|
"err": "",
|
|
@@ -661,101 +856,101 @@ describe("init", () => {
|
|
|
661
856
|
"warn": "",
|
|
662
857
|
}
|
|
663
858
|
`);
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
it("should offer to install wrangler into a package.json relative to the target directory, if no name is provided", async () => {
|
|
862
|
+
mockConfirm(
|
|
863
|
+
{
|
|
864
|
+
text: "Would you like to use git to manage this Worker?",
|
|
865
|
+
result: false,
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
text: "Would you like to install wrangler into ../package.json?",
|
|
869
|
+
result: true,
|
|
870
|
+
},
|
|
871
|
+
{
|
|
872
|
+
text: "Would you like to use TypeScript?",
|
|
873
|
+
result: false,
|
|
874
|
+
}
|
|
875
|
+
);
|
|
876
|
+
mockSelect({
|
|
877
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
878
|
+
result: "none",
|
|
879
|
+
});
|
|
880
|
+
writeFiles({
|
|
881
|
+
items: {
|
|
882
|
+
"path/to/worker/package.json": {
|
|
883
|
+
contents: { name: "test", version: "1.0.0" },
|
|
884
|
+
},
|
|
885
|
+
},
|
|
886
|
+
});
|
|
887
|
+
setWorkingDirectory("path/to/worker/my-worker");
|
|
888
|
+
|
|
889
|
+
await runWrangler("init");
|
|
890
|
+
|
|
891
|
+
setWorkingDirectory("../../../..");
|
|
892
|
+
checkFiles({
|
|
893
|
+
items: {
|
|
894
|
+
"path/to/worker/package.json": {
|
|
895
|
+
contents: { name: "test", version: "1.0.0" },
|
|
896
|
+
},
|
|
897
|
+
"path/to/worker/my-worker/package.json": false,
|
|
898
|
+
},
|
|
899
|
+
});
|
|
900
|
+
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
901
|
+
`wrangler@${wranglerVersion}`
|
|
902
|
+
);
|
|
903
|
+
expect(mockPackageManager.cwd).toBe(process.cwd());
|
|
904
|
+
expect(std).toMatchInlineSnapshot(`
|
|
705
905
|
Object {
|
|
706
906
|
"debug": "",
|
|
707
907
|
"err": "",
|
|
708
|
-
"out": "✨ Created
|
|
908
|
+
"out": "✨ Created wrangler.toml
|
|
709
909
|
✨ Installed wrangler into devDependencies",
|
|
710
910
|
"warn": "",
|
|
711
911
|
}
|
|
712
912
|
`);
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
"name": "test",
|
|
755
|
-
"version": "1.0.0",
|
|
756
|
-
}
|
|
757
|
-
`);
|
|
758
|
-
expect(std).toMatchInlineSnapshot(`
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
it("should not touch an existing package.json in an ancestor directory", async () => {
|
|
916
|
+
mockConfirm(
|
|
917
|
+
{
|
|
918
|
+
text: "Would you like to use git to manage this Worker?",
|
|
919
|
+
result: false,
|
|
920
|
+
},
|
|
921
|
+
{
|
|
922
|
+
text: "Would you like to install wrangler into ../../package.json?",
|
|
923
|
+
result: false,
|
|
924
|
+
},
|
|
925
|
+
{
|
|
926
|
+
text: "Would you like to use TypeScript?",
|
|
927
|
+
result: false,
|
|
928
|
+
}
|
|
929
|
+
);
|
|
930
|
+
mockSelect({
|
|
931
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
932
|
+
result: "none",
|
|
933
|
+
});
|
|
934
|
+
writeFiles({
|
|
935
|
+
items: {
|
|
936
|
+
"package.json": {
|
|
937
|
+
contents: { name: "test", version: "1.0.0" },
|
|
938
|
+
},
|
|
939
|
+
},
|
|
940
|
+
});
|
|
941
|
+
setWorkingDirectory("./sub-1/sub-2");
|
|
942
|
+
|
|
943
|
+
await runWrangler("init");
|
|
944
|
+
|
|
945
|
+
checkFiles({
|
|
946
|
+
items: {
|
|
947
|
+
"package.json": false,
|
|
948
|
+
"../../package.json": {
|
|
949
|
+
contents: { name: "test", version: "1.0.0" },
|
|
950
|
+
},
|
|
951
|
+
},
|
|
952
|
+
});
|
|
953
|
+
expect(std).toMatchInlineSnapshot(`
|
|
759
954
|
Object {
|
|
760
955
|
"debug": "",
|
|
761
956
|
"err": "",
|
|
@@ -763,41 +958,50 @@ describe("init", () => {
|
|
|
763
958
|
"warn": "",
|
|
764
959
|
}
|
|
765
960
|
`);
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
961
|
+
});
|
|
962
|
+
});
|
|
963
|
+
|
|
964
|
+
describe("typescript", () => {
|
|
965
|
+
it("should offer to create a worker in a non-typescript project", async () => {
|
|
966
|
+
mockConfirm(
|
|
967
|
+
{
|
|
968
|
+
text: "Would you like to use git to manage this Worker?",
|
|
969
|
+
result: false,
|
|
970
|
+
},
|
|
971
|
+
{
|
|
972
|
+
text: "Would you like to install wrangler into package.json?",
|
|
973
|
+
result: false,
|
|
974
|
+
},
|
|
975
|
+
{
|
|
976
|
+
text: "Would you like to use TypeScript?",
|
|
977
|
+
result: false,
|
|
978
|
+
}
|
|
979
|
+
);
|
|
980
|
+
mockSelect({
|
|
981
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
982
|
+
result: "fetch",
|
|
983
|
+
});
|
|
984
|
+
writeFiles({
|
|
985
|
+
items: {
|
|
986
|
+
"package.json": {
|
|
987
|
+
contents: { name: "test", version: "1.0.0" },
|
|
988
|
+
},
|
|
989
|
+
},
|
|
990
|
+
});
|
|
991
|
+
|
|
992
|
+
await runWrangler("init");
|
|
993
|
+
|
|
994
|
+
checkFiles({
|
|
995
|
+
items: {
|
|
996
|
+
"wrangler.toml": wranglerToml({
|
|
997
|
+
...MINIMAL_WRANGLER_TOML,
|
|
998
|
+
main: "src/index.js",
|
|
999
|
+
}),
|
|
1000
|
+
"src/index.js": true,
|
|
1001
|
+
"src/index.ts": false,
|
|
1002
|
+
},
|
|
1003
|
+
});
|
|
1004
|
+
expect(std).toMatchInlineSnapshot(`
|
|
801
1005
|
Object {
|
|
802
1006
|
"debug": "",
|
|
803
1007
|
"err": "",
|
|
@@ -809,39 +1013,44 @@ describe("init", () => {
|
|
|
809
1013
|
"warn": "",
|
|
810
1014
|
}
|
|
811
1015
|
`);
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
1016
|
+
});
|
|
1017
|
+
|
|
1018
|
+
it("should offer to create a worker in a typescript project", async () => {
|
|
1019
|
+
mockConfirm(
|
|
1020
|
+
{
|
|
1021
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1022
|
+
result: false,
|
|
1023
|
+
},
|
|
1024
|
+
{
|
|
1025
|
+
text: "Would you like to install wrangler into package.json?",
|
|
1026
|
+
result: false,
|
|
1027
|
+
},
|
|
1028
|
+
{
|
|
1029
|
+
text: "Would you like to use TypeScript?",
|
|
1030
|
+
result: true,
|
|
1031
|
+
}
|
|
1032
|
+
);
|
|
1033
|
+
mockSelect({
|
|
1034
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
1035
|
+
result: "fetch",
|
|
1036
|
+
});
|
|
1037
|
+
writeFiles({
|
|
1038
|
+
items: {
|
|
1039
|
+
"package.json": {
|
|
1040
|
+
contents: { name: "test", version: "1.0.0" },
|
|
1041
|
+
},
|
|
1042
|
+
},
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1045
|
+
await runWrangler("init");
|
|
1046
|
+
|
|
1047
|
+
checkFiles({
|
|
1048
|
+
items: {
|
|
1049
|
+
"src/index.js": false,
|
|
1050
|
+
"src/index.ts": true,
|
|
1051
|
+
},
|
|
1052
|
+
});
|
|
1053
|
+
expect(std).toMatchInlineSnapshot(`
|
|
845
1054
|
Object {
|
|
846
1055
|
"debug": "",
|
|
847
1056
|
"err": "",
|
|
@@ -855,46 +1064,51 @@ describe("init", () => {
|
|
|
855
1064
|
"warn": "",
|
|
856
1065
|
}
|
|
857
1066
|
`);
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
1067
|
+
});
|
|
1068
|
+
|
|
1069
|
+
it("should add scripts for a typescript project with .ts extension", async () => {
|
|
1070
|
+
mockConfirm(
|
|
1071
|
+
{
|
|
1072
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1073
|
+
result: false,
|
|
1074
|
+
},
|
|
1075
|
+
{
|
|
1076
|
+
text: "No package.json found. Would you like to create one?",
|
|
1077
|
+
result: true,
|
|
1078
|
+
},
|
|
1079
|
+
{
|
|
1080
|
+
text: "Would you like to install wrangler into package.json?",
|
|
1081
|
+
result: false,
|
|
1082
|
+
},
|
|
1083
|
+
{
|
|
1084
|
+
text: "Would you like to use TypeScript?",
|
|
1085
|
+
result: true,
|
|
1086
|
+
}
|
|
1087
|
+
);
|
|
1088
|
+
mockSelect({
|
|
1089
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
1090
|
+
result: "fetch",
|
|
1091
|
+
});
|
|
1092
|
+
|
|
1093
|
+
await runWrangler("init");
|
|
1094
|
+
|
|
1095
|
+
checkFiles({
|
|
1096
|
+
items: {
|
|
1097
|
+
"package.json": {
|
|
1098
|
+
contents: expect.objectContaining({
|
|
1099
|
+
name: expect.stringContaining("wrangler-tests"),
|
|
1100
|
+
version: "0.0.0",
|
|
1101
|
+
scripts: {
|
|
1102
|
+
start: "wrangler dev",
|
|
1103
|
+
deploy: "wrangler publish",
|
|
1104
|
+
},
|
|
1105
|
+
}),
|
|
1106
|
+
},
|
|
1107
|
+
"src/index.js": false,
|
|
1108
|
+
"src/index.ts": true,
|
|
1109
|
+
},
|
|
1110
|
+
});
|
|
1111
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
898
1112
|
"✨ Created wrangler.toml
|
|
899
1113
|
✨ Created package.json
|
|
900
1114
|
✨ Created tsconfig.json
|
|
@@ -904,47 +1118,57 @@ describe("init", () => {
|
|
|
904
1118
|
To start developing your Worker, run \`npm start\`
|
|
905
1119
|
To publish your Worker to the Internet, run \`npm run deploy\`"
|
|
906
1120
|
`);
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
1121
|
+
});
|
|
1122
|
+
|
|
1123
|
+
it("should not overwrite package.json scripts for a typescript project", async () => {
|
|
1124
|
+
mockConfirm(
|
|
1125
|
+
{
|
|
1126
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1127
|
+
result: false,
|
|
1128
|
+
},
|
|
1129
|
+
{
|
|
1130
|
+
text: "Would you like to install wrangler into package.json?",
|
|
1131
|
+
result: false,
|
|
1132
|
+
},
|
|
1133
|
+
{
|
|
1134
|
+
text: "Would you like to use TypeScript?",
|
|
1135
|
+
result: true,
|
|
1136
|
+
}
|
|
1137
|
+
);
|
|
1138
|
+
mockSelect({
|
|
1139
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
1140
|
+
result: "fetch",
|
|
1141
|
+
});
|
|
1142
|
+
writeFiles({
|
|
1143
|
+
items: {
|
|
1144
|
+
"package.json": {
|
|
1145
|
+
contents: {
|
|
1146
|
+
scripts: {
|
|
1147
|
+
start: "test-start",
|
|
1148
|
+
deploy: "test-publish",
|
|
1149
|
+
},
|
|
1150
|
+
},
|
|
1151
|
+
},
|
|
1152
|
+
},
|
|
1153
|
+
});
|
|
1154
|
+
|
|
1155
|
+
await runWrangler("init");
|
|
1156
|
+
|
|
1157
|
+
checkFiles({
|
|
1158
|
+
items: {
|
|
1159
|
+
"package.json": {
|
|
1160
|
+
contents: {
|
|
1161
|
+
scripts: {
|
|
1162
|
+
start: "test-start",
|
|
1163
|
+
deploy: "test-publish",
|
|
1164
|
+
},
|
|
1165
|
+
},
|
|
1166
|
+
},
|
|
1167
|
+
"src/index.js": false,
|
|
1168
|
+
"src/index.ts": true,
|
|
1169
|
+
},
|
|
1170
|
+
});
|
|
1171
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
948
1172
|
"✨ Created wrangler.toml
|
|
949
1173
|
✨ Created tsconfig.json
|
|
950
1174
|
✨ Created src/index.ts
|
|
@@ -953,37 +1177,40 @@ describe("init", () => {
|
|
|
953
1177
|
To start developing your Worker, run \`npx wrangler dev\`
|
|
954
1178
|
To publish your Worker to the Internet, run \`npx wrangler publish\`"
|
|
955
1179
|
`);
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
1180
|
+
});
|
|
1181
|
+
|
|
1182
|
+
it("should not offer to create a worker in a ts project if a file already exists at the location", async () => {
|
|
1183
|
+
mockConfirm(
|
|
1184
|
+
{
|
|
1185
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1186
|
+
result: false,
|
|
1187
|
+
},
|
|
1188
|
+
{
|
|
1189
|
+
text: "Would you like to install wrangler into package.json?",
|
|
1190
|
+
result: false,
|
|
1191
|
+
},
|
|
1192
|
+
{
|
|
1193
|
+
text: "Would you like to use TypeScript?",
|
|
1194
|
+
result: true,
|
|
1195
|
+
}
|
|
1196
|
+
);
|
|
1197
|
+
const PLACEHOLDER = "/* placeholder text */";
|
|
1198
|
+
writeFiles({
|
|
1199
|
+
items: {
|
|
1200
|
+
"package.json": { contents: { name: "test", version: "1.0.0" } },
|
|
1201
|
+
"src/index.ts": { contents: PLACEHOLDER },
|
|
1202
|
+
},
|
|
1203
|
+
});
|
|
1204
|
+
|
|
1205
|
+
await runWrangler("init");
|
|
1206
|
+
|
|
1207
|
+
checkFiles({
|
|
1208
|
+
items: {
|
|
1209
|
+
"src/index.js": false,
|
|
1210
|
+
"src/index.ts": { contents: PLACEHOLDER },
|
|
1211
|
+
},
|
|
1212
|
+
});
|
|
1213
|
+
expect(std).toMatchInlineSnapshot(`
|
|
987
1214
|
Object {
|
|
988
1215
|
"debug": "",
|
|
989
1216
|
"err": "",
|
|
@@ -993,85 +1220,97 @@ describe("init", () => {
|
|
|
993
1220
|
"warn": "",
|
|
994
1221
|
}
|
|
995
1222
|
`);
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1223
|
+
});
|
|
1224
|
+
|
|
1225
|
+
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 () => {
|
|
1226
|
+
mockConfirm(
|
|
1227
|
+
{
|
|
1228
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1229
|
+
result: false,
|
|
1230
|
+
},
|
|
1231
|
+
{
|
|
1232
|
+
text: "No package.json found. Would you like to create one?",
|
|
1233
|
+
result: true,
|
|
1234
|
+
},
|
|
1235
|
+
{
|
|
1236
|
+
text: "Would you like to install wrangler into package.json?",
|
|
1237
|
+
result: false,
|
|
1238
|
+
},
|
|
1239
|
+
{
|
|
1240
|
+
text: "Would you like to use TypeScript?",
|
|
1241
|
+
result: true,
|
|
1242
|
+
}
|
|
1243
|
+
);
|
|
1244
|
+
const PLACEHOLDER = "/* placeholder text */";
|
|
1245
|
+
writeFiles({
|
|
1246
|
+
items: {
|
|
1247
|
+
"package.json": { contents: { name: "test", version: "1.0.0" } },
|
|
1248
|
+
"my-worker/src/index.ts": { contents: PLACEHOLDER },
|
|
1249
|
+
},
|
|
1250
|
+
});
|
|
1251
|
+
|
|
1252
|
+
await runWrangler("init my-worker");
|
|
1253
|
+
|
|
1254
|
+
checkFiles({
|
|
1255
|
+
items: {
|
|
1256
|
+
"my-worker/src/index.js": false,
|
|
1257
|
+
"my-worker/src/index.ts": { contents: PLACEHOLDER },
|
|
1258
|
+
},
|
|
1259
|
+
});
|
|
1260
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1029
1261
|
Object {
|
|
1030
1262
|
"debug": "",
|
|
1031
1263
|
"err": "",
|
|
1032
1264
|
"out": "✨ Created my-worker/wrangler.toml
|
|
1265
|
+
✨ Created my-worker/package.json
|
|
1033
1266
|
✨ Created my-worker/tsconfig.json
|
|
1034
1267
|
✨ Installed @cloudflare/workers-types and typescript into devDependencies",
|
|
1035
1268
|
"warn": "",
|
|
1036
1269
|
}
|
|
1037
1270
|
`);
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1271
|
+
});
|
|
1272
|
+
|
|
1273
|
+
it("should create a tsconfig.json and install `workers-types` if none is found and user confirms", async () => {
|
|
1274
|
+
mockConfirm(
|
|
1275
|
+
{
|
|
1276
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1277
|
+
result: false,
|
|
1278
|
+
},
|
|
1279
|
+
{
|
|
1280
|
+
text: "No package.json found. Would you like to create one?",
|
|
1281
|
+
result: true,
|
|
1282
|
+
},
|
|
1283
|
+
{
|
|
1284
|
+
text: "Would you like to use TypeScript?",
|
|
1285
|
+
result: true,
|
|
1286
|
+
}
|
|
1287
|
+
);
|
|
1288
|
+
mockSelect({
|
|
1289
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
1290
|
+
result: "none",
|
|
1291
|
+
});
|
|
1292
|
+
|
|
1293
|
+
await runWrangler("init");
|
|
1294
|
+
|
|
1295
|
+
checkFiles({
|
|
1296
|
+
items: {
|
|
1297
|
+
"tsconfig.json": {
|
|
1298
|
+
contents: {
|
|
1299
|
+
config: {
|
|
1300
|
+
compilerOptions: expect.objectContaining({
|
|
1301
|
+
types: ["@cloudflare/workers-types"],
|
|
1302
|
+
}),
|
|
1303
|
+
},
|
|
1304
|
+
error: undefined,
|
|
1305
|
+
},
|
|
1306
|
+
},
|
|
1307
|
+
},
|
|
1308
|
+
});
|
|
1309
|
+
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
1310
|
+
"@cloudflare/workers-types",
|
|
1311
|
+
"typescript"
|
|
1312
|
+
);
|
|
1313
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1075
1314
|
Object {
|
|
1076
1315
|
"debug": "",
|
|
1077
1316
|
"err": "",
|
|
@@ -1082,43 +1321,43 @@ describe("init", () => {
|
|
|
1082
1321
|
"warn": "",
|
|
1083
1322
|
}
|
|
1084
1323
|
`);
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1324
|
+
});
|
|
1325
|
+
|
|
1326
|
+
it("should not touch an existing tsconfig.json in the same directory", async () => {
|
|
1327
|
+
mockConfirm({
|
|
1328
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1329
|
+
result: false,
|
|
1330
|
+
});
|
|
1331
|
+
mockSelect({
|
|
1332
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
1333
|
+
result: "fetch",
|
|
1334
|
+
});
|
|
1335
|
+
writeFiles({
|
|
1336
|
+
items: {
|
|
1337
|
+
"package.json": {
|
|
1338
|
+
contents: {
|
|
1339
|
+
name: "test",
|
|
1340
|
+
version: "1.0.0",
|
|
1341
|
+
devDependencies: {
|
|
1342
|
+
wrangler: "0.0.0",
|
|
1343
|
+
"@cloudflare/workers-types": "0.0.0",
|
|
1344
|
+
},
|
|
1345
|
+
},
|
|
1346
|
+
},
|
|
1347
|
+
"tsconfig.json": { contents: { compilerOptions: {} } },
|
|
1348
|
+
},
|
|
1349
|
+
});
|
|
1350
|
+
|
|
1351
|
+
await runWrangler("init");
|
|
1352
|
+
|
|
1353
|
+
checkFiles({
|
|
1354
|
+
items: {
|
|
1355
|
+
"tsconfig.json": {
|
|
1356
|
+
contents: { config: { compilerOptions: {} }, error: undefined },
|
|
1357
|
+
},
|
|
1358
|
+
},
|
|
1359
|
+
});
|
|
1360
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1122
1361
|
Object {
|
|
1123
1362
|
"debug": "",
|
|
1124
1363
|
"err": "",
|
|
@@ -1130,100 +1369,112 @@ describe("init", () => {
|
|
|
1130
1369
|
"warn": "",
|
|
1131
1370
|
}
|
|
1132
1371
|
`);
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1372
|
+
});
|
|
1373
|
+
|
|
1374
|
+
it("should not touch an existing tsconfig.json in the ancestor of a target directory, if a name is passed", async () => {
|
|
1375
|
+
mockConfirm(
|
|
1376
|
+
{
|
|
1377
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1378
|
+
result: false,
|
|
1379
|
+
},
|
|
1380
|
+
{
|
|
1381
|
+
text: "No package.json found. Would you like to create one?",
|
|
1382
|
+
result: true,
|
|
1383
|
+
},
|
|
1384
|
+
{
|
|
1385
|
+
text: "Would you like to use TypeScript?",
|
|
1386
|
+
result: true,
|
|
1387
|
+
}
|
|
1388
|
+
);
|
|
1389
|
+
mockSelect({
|
|
1390
|
+
text: "Would you like to create a Worker at path/to/worker/my-worker/src/index.ts?",
|
|
1391
|
+
result: "fetch",
|
|
1392
|
+
});
|
|
1393
|
+
writeFiles({
|
|
1394
|
+
items: {
|
|
1395
|
+
"path/to/worker/package.json": {
|
|
1396
|
+
contents: {
|
|
1397
|
+
name: "test",
|
|
1398
|
+
version: "1.0.0",
|
|
1399
|
+
devDependencies: {
|
|
1400
|
+
wrangler: "0.0.0",
|
|
1401
|
+
"@cloudflare/workers-types": "0.0.0",
|
|
1402
|
+
},
|
|
1403
|
+
},
|
|
1404
|
+
},
|
|
1405
|
+
"path/to/worker/tsconfig.json": { contents: { compilerOptions: {} } },
|
|
1406
|
+
},
|
|
1407
|
+
});
|
|
1408
|
+
|
|
1409
|
+
await runWrangler("init path/to/worker/my-worker");
|
|
1410
|
+
|
|
1411
|
+
checkFiles({
|
|
1412
|
+
items: {
|
|
1413
|
+
"path/to/worker/tsconfig.json": {
|
|
1414
|
+
contents: { config: { compilerOptions: {}, error: undefined } },
|
|
1415
|
+
},
|
|
1416
|
+
},
|
|
1417
|
+
});
|
|
1418
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1171
1419
|
Object {
|
|
1172
1420
|
"debug": "",
|
|
1173
1421
|
"err": "",
|
|
1174
1422
|
"out": "✨ Created path/to/worker/my-worker/wrangler.toml
|
|
1423
|
+
✨ Created path/to/worker/my-worker/package.json
|
|
1424
|
+
✨ Created path/to/worker/my-worker/tsconfig.json
|
|
1175
1425
|
✨ Created path/to/worker/my-worker/src/index.ts
|
|
1426
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
1176
1427
|
|
|
1177
|
-
To start developing your Worker, run \`
|
|
1178
|
-
To publish your Worker to the Internet, run \`
|
|
1428
|
+
To start developing your Worker, run \`cd path/to/worker/my-worker && npm start\`
|
|
1429
|
+
To publish your Worker to the Internet, run \`npm run deploy\`",
|
|
1179
1430
|
"warn": "",
|
|
1180
1431
|
}
|
|
1181
1432
|
`);
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1433
|
+
});
|
|
1434
|
+
|
|
1435
|
+
it("should offer to install type definitions in an existing typescript project", async () => {
|
|
1436
|
+
mockConfirm(
|
|
1437
|
+
{
|
|
1438
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1439
|
+
result: false,
|
|
1440
|
+
},
|
|
1441
|
+
{
|
|
1442
|
+
text: "Would you like to install wrangler into package.json?",
|
|
1443
|
+
result: false,
|
|
1444
|
+
},
|
|
1445
|
+
{
|
|
1446
|
+
text: "Would you like to install the type definitions for Workers into your package.json?",
|
|
1447
|
+
result: true,
|
|
1448
|
+
}
|
|
1449
|
+
);
|
|
1450
|
+
mockSelect({
|
|
1451
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
1452
|
+
result: "none",
|
|
1453
|
+
});
|
|
1454
|
+
writeFiles({
|
|
1455
|
+
items: {
|
|
1456
|
+
"./package.json": {
|
|
1457
|
+
contents: {
|
|
1458
|
+
name: "test",
|
|
1459
|
+
version: "1.0.0",
|
|
1460
|
+
},
|
|
1461
|
+
},
|
|
1462
|
+
"./tsconfig.json": { contents: { compilerOptions: {} } },
|
|
1463
|
+
},
|
|
1464
|
+
});
|
|
1465
|
+
|
|
1466
|
+
await runWrangler("init");
|
|
1467
|
+
|
|
1468
|
+
checkFiles({
|
|
1469
|
+
items: {
|
|
1470
|
+
// unchanged tsconfig
|
|
1471
|
+
"tsconfig.json": { contents: { config: { compilerOptions: {} } } },
|
|
1472
|
+
},
|
|
1473
|
+
});
|
|
1474
|
+
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
1475
|
+
"@cloudflare/workers-types"
|
|
1476
|
+
);
|
|
1477
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1227
1478
|
Object {
|
|
1228
1479
|
"debug": "",
|
|
1229
1480
|
"err": "",
|
|
@@ -1233,50 +1484,45 @@ describe("init", () => {
|
|
|
1233
1484
|
"warn": "",
|
|
1234
1485
|
}
|
|
1235
1486
|
`);
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
fs.readFileSync("../../tsconfig.json", "utf-8")
|
|
1276
|
-
);
|
|
1277
|
-
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
1278
|
-
|
|
1279
|
-
expect(std).toMatchInlineSnapshot(`
|
|
1487
|
+
});
|
|
1488
|
+
|
|
1489
|
+
it("should not touch an existing tsconfig.json in an ancestor directory", async () => {
|
|
1490
|
+
mockConfirm({
|
|
1491
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1492
|
+
result: false,
|
|
1493
|
+
});
|
|
1494
|
+
mockSelect({
|
|
1495
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
1496
|
+
result: "fetch",
|
|
1497
|
+
});
|
|
1498
|
+
writeFiles({
|
|
1499
|
+
items: {
|
|
1500
|
+
"package.json": {
|
|
1501
|
+
contents: {
|
|
1502
|
+
name: "test",
|
|
1503
|
+
version: "1.0.0",
|
|
1504
|
+
devDependencies: {
|
|
1505
|
+
wrangler: "0.0.0",
|
|
1506
|
+
"@cloudflare/workers-types": "0.0.0",
|
|
1507
|
+
},
|
|
1508
|
+
},
|
|
1509
|
+
},
|
|
1510
|
+
"tsconfig.json": { contents: { compilerOptions: {} } },
|
|
1511
|
+
},
|
|
1512
|
+
});
|
|
1513
|
+
setWorkingDirectory("./sub-1/sub-2");
|
|
1514
|
+
|
|
1515
|
+
await runWrangler("init");
|
|
1516
|
+
|
|
1517
|
+
checkFiles({
|
|
1518
|
+
items: {
|
|
1519
|
+
"tsconfig.json": false,
|
|
1520
|
+
"../../tsconfig.json": {
|
|
1521
|
+
contents: { config: { compilerOptions: {} } },
|
|
1522
|
+
},
|
|
1523
|
+
},
|
|
1524
|
+
});
|
|
1525
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1280
1526
|
Object {
|
|
1281
1527
|
"debug": "",
|
|
1282
1528
|
"err": "",
|
|
@@ -1288,48 +1534,53 @@ describe("init", () => {
|
|
|
1288
1534
|
"warn": "",
|
|
1289
1535
|
}
|
|
1290
1536
|
`);
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1537
|
+
});
|
|
1538
|
+
});
|
|
1539
|
+
|
|
1540
|
+
describe("javascript", () => {
|
|
1541
|
+
it("should add missing scripts for a non-ts project with .js extension", async () => {
|
|
1542
|
+
mockConfirm(
|
|
1543
|
+
{
|
|
1544
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1545
|
+
result: false,
|
|
1546
|
+
},
|
|
1547
|
+
{
|
|
1548
|
+
text: "No package.json found. Would you like to create one?",
|
|
1549
|
+
result: true,
|
|
1550
|
+
},
|
|
1551
|
+
{
|
|
1552
|
+
text: "Would you like to install wrangler into package.json?",
|
|
1553
|
+
result: false,
|
|
1554
|
+
},
|
|
1555
|
+
{
|
|
1556
|
+
text: "Would you like to use TypeScript?",
|
|
1557
|
+
result: false,
|
|
1558
|
+
}
|
|
1559
|
+
);
|
|
1560
|
+
mockSelect({
|
|
1561
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
1562
|
+
result: "fetch",
|
|
1563
|
+
});
|
|
1564
|
+
|
|
1565
|
+
await runWrangler("init");
|
|
1566
|
+
|
|
1567
|
+
checkFiles({
|
|
1568
|
+
items: {
|
|
1569
|
+
"src/index.js": true,
|
|
1570
|
+
"src/index.ts": false,
|
|
1571
|
+
"package.json": {
|
|
1572
|
+
contents: expect.objectContaining({
|
|
1573
|
+
name: expect.stringContaining("wrangler-tests"),
|
|
1574
|
+
version: "0.0.0",
|
|
1575
|
+
scripts: {
|
|
1576
|
+
start: "wrangler dev",
|
|
1577
|
+
deploy: "wrangler publish",
|
|
1578
|
+
},
|
|
1579
|
+
}),
|
|
1580
|
+
},
|
|
1581
|
+
},
|
|
1582
|
+
});
|
|
1583
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1333
1584
|
"✨ Created wrangler.toml
|
|
1334
1585
|
✨ Created package.json
|
|
1335
1586
|
✨ Created src/index.js
|
|
@@ -1337,84 +1588,97 @@ describe("init", () => {
|
|
|
1337
1588
|
To start developing your Worker, run \`npm start\`
|
|
1338
1589
|
To publish your Worker to the Internet, run \`npm run deploy\`"
|
|
1339
1590
|
`);
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1591
|
+
});
|
|
1592
|
+
|
|
1593
|
+
it("should not overwrite package.json scripts for a non-ts project with .js extension", async () => {
|
|
1594
|
+
mockConfirm(
|
|
1595
|
+
{
|
|
1596
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1597
|
+
result: false,
|
|
1598
|
+
},
|
|
1599
|
+
{
|
|
1600
|
+
text: "Would you like to install wrangler into package.json?",
|
|
1601
|
+
result: false,
|
|
1602
|
+
},
|
|
1603
|
+
{
|
|
1604
|
+
text: "Would you like to use TypeScript?",
|
|
1605
|
+
result: false,
|
|
1606
|
+
}
|
|
1607
|
+
);
|
|
1608
|
+
mockSelect({
|
|
1609
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
1610
|
+
result: "fetch",
|
|
1611
|
+
});
|
|
1612
|
+
writeFiles({
|
|
1613
|
+
items: {
|
|
1614
|
+
"package.json": {
|
|
1615
|
+
contents: {
|
|
1616
|
+
scripts: {
|
|
1617
|
+
start: "test-start",
|
|
1618
|
+
deploy: "test-publish",
|
|
1619
|
+
},
|
|
1620
|
+
},
|
|
1621
|
+
},
|
|
1622
|
+
},
|
|
1623
|
+
});
|
|
1624
|
+
|
|
1625
|
+
await runWrangler("init");
|
|
1626
|
+
|
|
1627
|
+
checkFiles({
|
|
1628
|
+
items: {
|
|
1629
|
+
"src/index.js": true,
|
|
1630
|
+
"src/index.ts": false,
|
|
1631
|
+
"package.json": {
|
|
1632
|
+
contents: expect.objectContaining({
|
|
1633
|
+
scripts: {
|
|
1634
|
+
start: "test-start",
|
|
1635
|
+
deploy: "test-publish",
|
|
1636
|
+
},
|
|
1637
|
+
}),
|
|
1638
|
+
},
|
|
1639
|
+
},
|
|
1640
|
+
});
|
|
1641
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1381
1642
|
"✨ Created wrangler.toml
|
|
1382
1643
|
✨ Created src/index.js
|
|
1383
1644
|
|
|
1384
1645
|
To start developing your Worker, run \`npx wrangler dev\`
|
|
1385
1646
|
To publish your Worker to the Internet, run \`npx wrangler publish\`"
|
|
1386
1647
|
`);
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1648
|
+
});
|
|
1649
|
+
|
|
1650
|
+
it("should not offer to create a worker in a non-ts project if a file already exists at the location", async () => {
|
|
1651
|
+
mockConfirm(
|
|
1652
|
+
{
|
|
1653
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1654
|
+
result: false,
|
|
1655
|
+
},
|
|
1656
|
+
{
|
|
1657
|
+
text: "Would you like to install wrangler into package.json?",
|
|
1658
|
+
result: false,
|
|
1659
|
+
},
|
|
1660
|
+
{
|
|
1661
|
+
text: "Would you like to use TypeScript?",
|
|
1662
|
+
result: false,
|
|
1663
|
+
}
|
|
1664
|
+
);
|
|
1665
|
+
const PLACEHOLDER = "/* placeholder text */";
|
|
1666
|
+
writeFiles({
|
|
1667
|
+
items: {
|
|
1668
|
+
"package.json": { contents: { name: "test", version: "1.0.0" } },
|
|
1669
|
+
"src/index.js": { contents: PLACEHOLDER },
|
|
1670
|
+
},
|
|
1671
|
+
});
|
|
1672
|
+
|
|
1673
|
+
await runWrangler("init");
|
|
1674
|
+
|
|
1675
|
+
checkFiles({
|
|
1676
|
+
items: {
|
|
1677
|
+
"src/index.js": { contents: PLACEHOLDER },
|
|
1678
|
+
"src/index.ts": false,
|
|
1679
|
+
},
|
|
1680
|
+
});
|
|
1681
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1418
1682
|
Object {
|
|
1419
1683
|
"debug": "",
|
|
1420
1684
|
"err": "",
|
|
@@ -1422,39 +1686,42 @@ describe("init", () => {
|
|
|
1422
1686
|
"warn": "",
|
|
1423
1687
|
}
|
|
1424
1688
|
`);
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1689
|
+
});
|
|
1690
|
+
|
|
1691
|
+
it("should not offer to create a worker in a non-ts named worker project if a file already exists at the location", async () => {
|
|
1692
|
+
mockConfirm(
|
|
1693
|
+
{
|
|
1694
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1695
|
+
result: false,
|
|
1696
|
+
},
|
|
1697
|
+
{
|
|
1698
|
+
text: "Would you like to install wrangler into my-worker/package.json?",
|
|
1699
|
+
result: false,
|
|
1700
|
+
},
|
|
1701
|
+
{
|
|
1702
|
+
text: "Would you like to use TypeScript?",
|
|
1703
|
+
result: false,
|
|
1704
|
+
}
|
|
1705
|
+
);
|
|
1706
|
+
const PLACEHOLDER = "/* placeholder text */";
|
|
1707
|
+
writeFiles({
|
|
1708
|
+
items: {
|
|
1709
|
+
"my-worker/package.json": {
|
|
1710
|
+
contents: { name: "test", version: "1.0.0" },
|
|
1711
|
+
},
|
|
1712
|
+
"my-worker/src/index.js": { contents: PLACEHOLDER },
|
|
1713
|
+
},
|
|
1714
|
+
});
|
|
1715
|
+
|
|
1716
|
+
await runWrangler("init my-worker");
|
|
1717
|
+
|
|
1718
|
+
checkFiles({
|
|
1719
|
+
items: {
|
|
1720
|
+
"my-worker/src/index.js": { contents: PLACEHOLDER },
|
|
1721
|
+
"my-worker/src/index.ts": false,
|
|
1722
|
+
},
|
|
1723
|
+
});
|
|
1724
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1458
1725
|
Object {
|
|
1459
1726
|
"debug": "",
|
|
1460
1727
|
"err": "",
|
|
@@ -1462,31 +1729,36 @@ describe("init", () => {
|
|
|
1462
1729
|
"warn": "",
|
|
1463
1730
|
}
|
|
1464
1731
|
`);
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1732
|
+
});
|
|
1733
|
+
});
|
|
1734
|
+
|
|
1735
|
+
describe("worker names", () => {
|
|
1736
|
+
it("should create a worker with a given name", async () => {
|
|
1737
|
+
await runWrangler("init my-worker -y");
|
|
1738
|
+
|
|
1739
|
+
checkFiles({
|
|
1740
|
+
items: {
|
|
1741
|
+
"my-worker/wrangler.toml": wranglerToml({
|
|
1742
|
+
...MINIMAL_WRANGLER_TOML,
|
|
1743
|
+
name: "my-worker",
|
|
1744
|
+
}),
|
|
1745
|
+
},
|
|
1746
|
+
});
|
|
1747
|
+
});
|
|
1748
|
+
|
|
1749
|
+
it('should create a worker with the name of the current directory if "name" is .', async () => {
|
|
1750
|
+
await runWrangler("init . -y");
|
|
1751
|
+
|
|
1752
|
+
const workerName = path.basename(process.cwd()).toLowerCase();
|
|
1753
|
+
checkFiles({
|
|
1754
|
+
items: {
|
|
1755
|
+
"wrangler.toml": wranglerToml({
|
|
1756
|
+
...MINIMAL_WRANGLER_TOML,
|
|
1757
|
+
name: workerName,
|
|
1758
|
+
}),
|
|
1759
|
+
},
|
|
1760
|
+
});
|
|
1761
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1490
1762
|
Object {
|
|
1491
1763
|
"debug": "",
|
|
1492
1764
|
"err": "",
|
|
@@ -1502,20 +1774,20 @@ describe("init", () => {
|
|
|
1502
1774
|
"warn": "",
|
|
1503
1775
|
}
|
|
1504
1776
|
`);
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1777
|
+
});
|
|
1778
|
+
|
|
1779
|
+
it('should create a worker in a nested directory if "name" is path/to/worker', async () => {
|
|
1780
|
+
await runWrangler("init path/to/worker -y");
|
|
1781
|
+
|
|
1782
|
+
checkFiles({
|
|
1783
|
+
items: {
|
|
1784
|
+
"path/to/worker/wrangler.toml": wranglerToml({
|
|
1785
|
+
...MINIMAL_WRANGLER_TOML,
|
|
1786
|
+
name: "worker",
|
|
1787
|
+
}),
|
|
1788
|
+
},
|
|
1789
|
+
});
|
|
1790
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1519
1791
|
Object {
|
|
1520
1792
|
"debug": "",
|
|
1521
1793
|
"err": "",
|
|
@@ -1531,22 +1803,20 @@ describe("init", () => {
|
|
|
1531
1803
|
"warn": "",
|
|
1532
1804
|
}
|
|
1533
1805
|
`);
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
expect(fs.existsSync("./my-worker/tsconfig.json")).toBe(false);
|
|
1549
|
-
expect(std).toMatchInlineSnapshot(`
|
|
1806
|
+
});
|
|
1807
|
+
|
|
1808
|
+
it("should normalize characters that aren't lowercase alphanumeric, underscores, or dashes", async () => {
|
|
1809
|
+
await runWrangler("init WEIRD_w0rkr_N4m3.js.tsx.tar.gz -y");
|
|
1810
|
+
|
|
1811
|
+
checkFiles({
|
|
1812
|
+
items: {
|
|
1813
|
+
"WEIRD_w0rkr_N4m3.js.tsx.tar.gz/wrangler.toml": wranglerToml({
|
|
1814
|
+
...MINIMAL_WRANGLER_TOML,
|
|
1815
|
+
name: "weird_w0rkr_n4m3-js-tsx-tar-gz",
|
|
1816
|
+
}),
|
|
1817
|
+
},
|
|
1818
|
+
});
|
|
1819
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1550
1820
|
Object {
|
|
1551
1821
|
"debug": "",
|
|
1552
1822
|
"err": "",
|
|
@@ -1562,6 +1832,161 @@ describe("init", () => {
|
|
|
1562
1832
|
"warn": "",
|
|
1563
1833
|
}
|
|
1564
1834
|
`);
|
|
1565
|
-
|
|
1566
|
-
|
|
1835
|
+
});
|
|
1836
|
+
|
|
1837
|
+
it("should ignore ancestor files (such as wrangler.toml, package.json and tsconfig.json) if a name/path is given", async () => {
|
|
1838
|
+
mockConfirm(
|
|
1839
|
+
{
|
|
1840
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1841
|
+
result: false,
|
|
1842
|
+
},
|
|
1843
|
+
{
|
|
1844
|
+
text: "Would you like to use TypeScript?",
|
|
1845
|
+
result: true,
|
|
1846
|
+
},
|
|
1847
|
+
{
|
|
1848
|
+
text: "No package.json found. Would you like to create one?",
|
|
1849
|
+
result: true,
|
|
1850
|
+
},
|
|
1851
|
+
{
|
|
1852
|
+
text: "Would you like to install the type definitions for Workers into your package.json?",
|
|
1853
|
+
result: true,
|
|
1854
|
+
}
|
|
1855
|
+
);
|
|
1856
|
+
mockSelect({
|
|
1857
|
+
text: "Would you like to create a Worker at sub/folder/worker/src/index.ts?",
|
|
1858
|
+
result: "fetch",
|
|
1859
|
+
});
|
|
1860
|
+
writeFiles({
|
|
1861
|
+
items: {
|
|
1862
|
+
"package.json": { contents: { name: "top-level" } },
|
|
1863
|
+
"tsconfig.json": { contents: { compilerOptions: {} } },
|
|
1864
|
+
"wrangler.toml": wranglerToml({
|
|
1865
|
+
name: "top-level",
|
|
1866
|
+
compatibility_date: "some-date",
|
|
1867
|
+
}),
|
|
1868
|
+
},
|
|
1869
|
+
});
|
|
1870
|
+
|
|
1871
|
+
await runWrangler("init sub/folder/worker");
|
|
1872
|
+
|
|
1873
|
+
// Ancestor files are untouched.
|
|
1874
|
+
checkFiles({
|
|
1875
|
+
items: {
|
|
1876
|
+
"package.json": { contents: { name: "top-level" } },
|
|
1877
|
+
"tsconfig.json": {
|
|
1878
|
+
contents: { config: { compilerOptions: {} }, error: undefined },
|
|
1879
|
+
},
|
|
1880
|
+
"wrangler.toml": wranglerToml({
|
|
1881
|
+
name: "top-level",
|
|
1882
|
+
compatibility_date: "some-date",
|
|
1883
|
+
}),
|
|
1884
|
+
},
|
|
1885
|
+
});
|
|
1886
|
+
// New initialized Worker has its own files.
|
|
1887
|
+
checkFiles({
|
|
1888
|
+
items: {
|
|
1889
|
+
"sub/folder/worker/package.json": {
|
|
1890
|
+
contents: expect.objectContaining({
|
|
1891
|
+
name: "worker",
|
|
1892
|
+
}),
|
|
1893
|
+
},
|
|
1894
|
+
"sub/folder/worker/tsconfig.json": true,
|
|
1895
|
+
"sub/folder/worker/wrangler.toml": wranglerToml({
|
|
1896
|
+
...MINIMAL_WRANGLER_TOML,
|
|
1897
|
+
name: "worker",
|
|
1898
|
+
}),
|
|
1899
|
+
},
|
|
1900
|
+
});
|
|
1901
|
+
});
|
|
1902
|
+
});
|
|
1567
1903
|
});
|
|
1904
|
+
|
|
1905
|
+
/**
|
|
1906
|
+
* Change the current working directory, ensuring that this exists.
|
|
1907
|
+
*/
|
|
1908
|
+
function setWorkingDirectory(directory: string) {
|
|
1909
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
1910
|
+
process.chdir(directory);
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
/**
|
|
1914
|
+
* Write the given folder/files to disk at the given `cwd`.
|
|
1915
|
+
*/
|
|
1916
|
+
function writeFiles(folder: TestFolder, cwd = process.cwd()) {
|
|
1917
|
+
for (const name in folder.items) {
|
|
1918
|
+
const item = folder.items[name];
|
|
1919
|
+
const itemPath = path.resolve(cwd, name);
|
|
1920
|
+
if (typeof item !== "boolean") {
|
|
1921
|
+
if ("contents" in item) {
|
|
1922
|
+
fs.mkdirSync(path.dirname(itemPath), { recursive: true });
|
|
1923
|
+
fs.writeFileSync(itemPath, stringify(name, item.contents));
|
|
1924
|
+
} else {
|
|
1925
|
+
fs.mkdirSync(itemPath, { recursive: true });
|
|
1926
|
+
writeFiles(item, itemPath);
|
|
1927
|
+
}
|
|
1928
|
+
} else {
|
|
1929
|
+
throw new Error("Cannot write boolean flags to disk: " + itemPath);
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
/**
|
|
1935
|
+
* Check that the given test folders/files match what is in on disk.
|
|
1936
|
+
*/
|
|
1937
|
+
function checkFiles(folder: TestFolder, cwd = process.cwd()) {
|
|
1938
|
+
for (const name in folder.items) {
|
|
1939
|
+
const item = folder.items[name];
|
|
1940
|
+
const itemPath = path.resolve(cwd, name);
|
|
1941
|
+
if (typeof item === "boolean") {
|
|
1942
|
+
if (fs.existsSync(itemPath) !== item) {
|
|
1943
|
+
throw new Error(`Expected ${itemPath} ${item ? "" : "not "}to exist.`);
|
|
1944
|
+
}
|
|
1945
|
+
} else if ("contents" in item) {
|
|
1946
|
+
const actualContents = parse(name, fs.readFileSync(itemPath, "utf-8"));
|
|
1947
|
+
expect(actualContents).toEqual(item.contents);
|
|
1948
|
+
} else if ("items" in item) {
|
|
1949
|
+
checkFiles(item, itemPath);
|
|
1950
|
+
} else {
|
|
1951
|
+
throw new Error("Unexpected TestFile object.");
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
function stringify(name: string, value: unknown) {
|
|
1957
|
+
if (name.endsWith(".toml")) {
|
|
1958
|
+
return TOML.stringify(value as TOML.JsonMap);
|
|
1959
|
+
}
|
|
1960
|
+
if (name.endsWith(".json")) {
|
|
1961
|
+
return JSON.stringify(value);
|
|
1962
|
+
}
|
|
1963
|
+
return `${value}`;
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
function parse(name: string, value: string): unknown {
|
|
1967
|
+
if (name.endsWith(".toml")) {
|
|
1968
|
+
return TOML.parse(value);
|
|
1969
|
+
}
|
|
1970
|
+
if (name.endsWith("tsconfig.json")) {
|
|
1971
|
+
return parseConfigFileTextToJson(name, value);
|
|
1972
|
+
}
|
|
1973
|
+
if (name.endsWith(".json")) {
|
|
1974
|
+
return JSON.parse(value);
|
|
1975
|
+
}
|
|
1976
|
+
return value;
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
function wranglerToml(options: TOML.JsonMap = {}): TestFile {
|
|
1980
|
+
return {
|
|
1981
|
+
contents: options,
|
|
1982
|
+
};
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
interface TestFile {
|
|
1986
|
+
contents: unknown;
|
|
1987
|
+
}
|
|
1988
|
+
interface TestFolder {
|
|
1989
|
+
items: {
|
|
1990
|
+
[id: string]: TestFile | TestFolder | boolean;
|
|
1991
|
+
};
|
|
1992
|
+
}
|