wrangler 0.0.0-fb0eae7 → 0.0.0-fb43821
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/package.json +7 -8
- package/src/__tests__/index.test.ts +356 -87
- package/src/__tests__/mock-cfetch.js +11 -15
- package/src/api/inspect.ts +0 -11
- package/src/dev.tsx +66 -13
- package/src/dialogs.tsx +1 -9
- package/src/index.tsx +69 -40
- package/src/pages.tsx +554 -80
- package/src/publish.ts +4 -3
- package/src/user.tsx +1 -1
- package/wrangler-dist/cli.js +53687 -66219
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/fixtures/init/.gitkeep +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-fb43821",
|
|
4
4
|
"author": "wrangler@cloudflare.com",
|
|
5
5
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
6
6
|
"bin": {
|
|
@@ -38,30 +38,26 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@cloudflare/pages-functions-compiler": "0.3.8",
|
|
40
40
|
"esbuild": "0.14.1",
|
|
41
|
-
"miniflare": "2.0.0-rc.
|
|
42
|
-
"semiver": "^1.1.0"
|
|
43
|
-
"serve": "^13.0.2"
|
|
41
|
+
"miniflare": "2.0.0-rc.4",
|
|
42
|
+
"semiver": "^1.1.0"
|
|
44
43
|
},
|
|
45
44
|
"optionalDependencies": {
|
|
46
45
|
"fsevents": "~2.3.2"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"@iarna/toml": "^2.2.5",
|
|
50
|
-
"@types/cloudflare": "^2.7.6",
|
|
51
|
-
"@types/express": "^4.17.13",
|
|
52
49
|
"@types/react": "^17.0.37",
|
|
53
50
|
"@types/signal-exit": "^3.0.1",
|
|
54
51
|
"@types/ws": "^8.2.1",
|
|
55
52
|
"@types/yargs": "^17.0.7",
|
|
53
|
+
"chokidar": "^3.5.2",
|
|
56
54
|
"clipboardy": "^3.0.0",
|
|
57
55
|
"command-exists": "^1.2.9",
|
|
58
56
|
"execa": "^6.0.0",
|
|
59
|
-
"express": "^4.17.1",
|
|
60
57
|
"finalhandler": "^1.1.2",
|
|
61
58
|
"find-up": "^6.2.0",
|
|
62
59
|
"formdata-node": "^4.3.1",
|
|
63
60
|
"http-proxy": "^1.18.1",
|
|
64
|
-
"http-proxy-middleware": "^2.0.1",
|
|
65
61
|
"ink": "^3.2.0",
|
|
66
62
|
"ink-select-input": "^4.2.1",
|
|
67
63
|
"ink-table": "^3.0.0",
|
|
@@ -70,9 +66,11 @@
|
|
|
70
66
|
"open": "^8.4.0",
|
|
71
67
|
"path-to-regexp": "^6.2.0",
|
|
72
68
|
"react": "^17.0.2",
|
|
69
|
+
"react-error-boundary": "^3.1.4",
|
|
73
70
|
"serve-static": "^1.14.1",
|
|
74
71
|
"signal-exit": "^3.0.6",
|
|
75
72
|
"tmp-promise": "^3.0.3",
|
|
73
|
+
"undici": "^4.11.1",
|
|
76
74
|
"ws": "^8.3.0",
|
|
77
75
|
"yargs": "^17.3.0"
|
|
78
76
|
},
|
|
@@ -96,6 +94,7 @@
|
|
|
96
94
|
"node": ">=16.7.0"
|
|
97
95
|
},
|
|
98
96
|
"jest": {
|
|
97
|
+
"restoreMocks": true,
|
|
99
98
|
"testRegex": ".*.(test|spec)\\.[jt]sx?$",
|
|
100
99
|
"transformIgnorePatterns": [
|
|
101
100
|
"node_modules/(?!node-fetch|fetch-blob|find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|data-uri-to-buffer|formdata-polyfill|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream)"
|
|
@@ -1,153 +1,422 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as fsp from "node:fs/promises";
|
|
3
|
+
import * as os from "node:os";
|
|
3
4
|
import * as path from "node:path";
|
|
4
5
|
import * as TOML from "@iarna/toml";
|
|
5
6
|
import { main } from "../index";
|
|
6
|
-
|
|
7
|
-
import {
|
|
7
|
+
import { setMock, unsetAllMocks } from "./mock-cfetch";
|
|
8
|
+
import { confirm } from "../dialogs";
|
|
8
9
|
|
|
9
|
-
jest.mock("../cfetch", () =>
|
|
10
|
-
return jest.requireActual("./mock-cfetch");
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
async function w(cmd: void | string, options?: { tap: boolean }) {
|
|
14
|
-
const tapped = options?.tap ? tap() : undefined;
|
|
15
|
-
await main([...(cmd ? cmd.split(" ") : [])]);
|
|
16
|
-
tapped?.off();
|
|
17
|
-
return { stdout: tapped?.out, stderr: tapped?.err };
|
|
18
|
-
}
|
|
10
|
+
jest.mock("../cfetch", () => jest.requireActual("./mock-cfetch"));
|
|
19
11
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
err: "",
|
|
12
|
+
jest.mock("../dialogs", () => {
|
|
13
|
+
return {
|
|
14
|
+
...jest.requireActual<object>("../dialogs"),
|
|
15
|
+
confirm: jest
|
|
16
|
+
.fn()
|
|
17
|
+
.mockName("confirmMock")
|
|
18
|
+
.mockImplementation(() => {
|
|
19
|
+
// By default (if not configured by mockConfirm()) calls to `confirm()` should throw.
|
|
20
|
+
throw new Error("Unexpected call to `confirm()`.");
|
|
21
|
+
}),
|
|
31
22
|
};
|
|
23
|
+
});
|
|
32
24
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Mock the implementation of `confirm()` that will respond with configured results
|
|
27
|
+
* for configured confirmation text messages.
|
|
28
|
+
*
|
|
29
|
+
* If there is a call to `confirm()` that does not match any of the expectations
|
|
30
|
+
* then an error is thrown.
|
|
31
|
+
*/
|
|
32
|
+
function mockConfirm(...expectations: { text: string; result: boolean }[]) {
|
|
33
|
+
(confirm as jest.Mock).mockImplementation((text: string) => {
|
|
34
|
+
for (const { text: expectedText, result } of expectations) {
|
|
35
|
+
if (text === expectedText) {
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`Unexpected confirmation message: ${text}`);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
async function w(cmd?: string) {
|
|
44
|
+
const logSpy = jest.spyOn(console, "log").mockImplementation();
|
|
45
|
+
const errorSpy = jest.spyOn(console, "error").mockImplementation();
|
|
46
|
+
const warnSpy = jest.spyOn(console, "warn").mockImplementation();
|
|
47
|
+
try {
|
|
48
|
+
await main(cmd?.split(" ") ?? []);
|
|
49
|
+
return {
|
|
50
|
+
stdout: logSpy.mock.calls.flat(2).join("\n"),
|
|
51
|
+
stderr: errorSpy.mock.calls.flat(2).join("\n"),
|
|
52
|
+
warnings: warnSpy.mock.calls.flat(2).join("\n"),
|
|
53
|
+
};
|
|
54
|
+
} finally {
|
|
55
|
+
logSpy.mockRestore();
|
|
56
|
+
errorSpy.mockRestore();
|
|
57
|
+
warnSpy.mockRestore();
|
|
58
|
+
}
|
|
44
59
|
}
|
|
45
60
|
|
|
46
61
|
describe("wrangler", () => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
describe("no command", () => {
|
|
63
|
+
it("should display a list of available commands", async () => {
|
|
64
|
+
const { stdout, stderr } = await w();
|
|
65
|
+
|
|
66
|
+
expect(stdout).toMatchInlineSnapshot(`
|
|
67
|
+
"wrangler
|
|
68
|
+
|
|
69
|
+
Commands:
|
|
70
|
+
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
71
|
+
wrangler dev <filename> 👂 Start a local server for developing your worker
|
|
72
|
+
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
73
|
+
wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
|
|
74
|
+
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
|
|
75
|
+
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
|
|
76
|
+
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
|
|
77
|
+
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
78
|
+
wrangler pages ⚡️ Configure Cloudflare Pages
|
|
79
|
+
|
|
80
|
+
Flags:
|
|
81
|
+
-c, --config Path to .toml configuration file [string]
|
|
82
|
+
-h, --help Show help [boolean]
|
|
83
|
+
-v, --version Show version number [boolean]
|
|
84
|
+
|
|
85
|
+
Options:
|
|
86
|
+
-l, --local Run on my machine [boolean] [default: false]"
|
|
87
|
+
`);
|
|
88
|
+
|
|
89
|
+
expect(stderr).toMatchInlineSnapshot(`""`);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe("invalid command", () => {
|
|
94
|
+
it("should display an error", async () => {
|
|
95
|
+
const { stdout, stderr } = await w("invalid-command");
|
|
96
|
+
|
|
97
|
+
expect(stdout).toMatchInlineSnapshot(`
|
|
98
|
+
"wrangler
|
|
99
|
+
|
|
100
|
+
Commands:
|
|
101
|
+
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
102
|
+
wrangler dev <filename> 👂 Start a local server for developing your worker
|
|
103
|
+
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
104
|
+
wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
|
|
105
|
+
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
|
|
106
|
+
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
|
|
107
|
+
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
|
|
108
|
+
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
109
|
+
wrangler pages ⚡️ Configure Cloudflare Pages
|
|
110
|
+
|
|
111
|
+
Flags:
|
|
112
|
+
-c, --config Path to .toml configuration file [string]
|
|
113
|
+
-h, --help Show help [boolean]
|
|
114
|
+
-v, --version Show version number [boolean]
|
|
115
|
+
|
|
116
|
+
Options:
|
|
117
|
+
-l, --local Run on my machine [boolean] [default: false]"
|
|
118
|
+
`);
|
|
119
|
+
|
|
120
|
+
expect(stderr).toMatchInlineSnapshot(`
|
|
121
|
+
"
|
|
122
|
+
Unknown command: invalid-command."
|
|
123
|
+
`);
|
|
124
|
+
});
|
|
72
125
|
});
|
|
73
126
|
|
|
74
127
|
describe("init", () => {
|
|
75
128
|
const ogcwd = process.cwd();
|
|
129
|
+
let tmpDir: string;
|
|
76
130
|
|
|
77
|
-
beforeEach(() => {
|
|
78
|
-
|
|
131
|
+
beforeEach(async () => {
|
|
132
|
+
tmpDir = await fsp.mkdtemp(path.join(os.tmpdir(), "init-"));
|
|
133
|
+
process.chdir(tmpDir);
|
|
79
134
|
});
|
|
80
135
|
|
|
81
136
|
afterEach(async () => {
|
|
82
|
-
await fsp.rm("./wrangler.toml");
|
|
83
137
|
process.chdir(ogcwd);
|
|
138
|
+
await fsp.rm(tmpDir, { recursive: true });
|
|
84
139
|
});
|
|
85
140
|
|
|
86
141
|
it("should create a wrangler.toml", async () => {
|
|
142
|
+
mockConfirm({
|
|
143
|
+
text: "No package.json found. Would you like to create one?",
|
|
144
|
+
result: false,
|
|
145
|
+
});
|
|
87
146
|
await w("init");
|
|
88
147
|
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
89
148
|
expect(typeof parsed.compatibility_date).toBe("string");
|
|
149
|
+
expect(fs.existsSync("./package.json")).toBe(false);
|
|
150
|
+
expect(fs.existsSync("./tsconfig.json")).toBe(false);
|
|
90
151
|
});
|
|
91
152
|
|
|
92
|
-
it("should
|
|
153
|
+
it("should display warning when wrangler.toml already exists, and exit if user does not want to carry on", async () => {
|
|
93
154
|
fs.closeSync(fs.openSync("./wrangler.toml", "w"));
|
|
94
|
-
|
|
95
|
-
|
|
155
|
+
mockConfirm({
|
|
156
|
+
text: "Do you want to continue initializing this project?",
|
|
157
|
+
result: false,
|
|
158
|
+
});
|
|
159
|
+
const { stderr } = await w("init");
|
|
160
|
+
expect(stderr).toContain("wrangler.toml file already exists!");
|
|
161
|
+
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
162
|
+
expect(typeof parsed.compatibility_date).toBe("undefined");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("should display warning when wrangler.toml already exists, but continue if user does want to carry on", async () => {
|
|
166
|
+
fs.closeSync(fs.openSync("./wrangler.toml", "w"));
|
|
167
|
+
mockConfirm(
|
|
168
|
+
{
|
|
169
|
+
text: "Do you want to continue initializing this project?",
|
|
170
|
+
result: true,
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
text: "No package.json found. Would you like to create one?",
|
|
174
|
+
result: false,
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
const { stderr } = await w("init");
|
|
178
|
+
expect(stderr).toContain("wrangler.toml file already exists!");
|
|
179
|
+
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
180
|
+
expect(typeof parsed.compatibility_date).toBe("string");
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("should create a package.json if none is found and user confirms", async () => {
|
|
184
|
+
mockConfirm(
|
|
185
|
+
{
|
|
186
|
+
text: "No package.json found. Would you like to create one?",
|
|
187
|
+
result: true,
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
text: "Would you like to use typescript?",
|
|
191
|
+
result: false,
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
await w("init");
|
|
195
|
+
expect(fs.existsSync("./package.json")).toBe(true);
|
|
196
|
+
const packageJson = JSON.parse(
|
|
197
|
+
fs.readFileSync("./package.json", "utf-8")
|
|
198
|
+
);
|
|
199
|
+
expect(packageJson.name).toEqual("worker"); // TODO: should we infer the name from the directory?
|
|
200
|
+
expect(packageJson.version).toEqual("0.0.1");
|
|
201
|
+
expect(fs.existsSync("./tsconfig.json")).toBe(false);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("should not touch an existing package.json in the same directory", async () => {
|
|
205
|
+
mockConfirm({
|
|
206
|
+
text: "Would you like to use typescript?",
|
|
207
|
+
result: false,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
fs.writeFileSync(
|
|
211
|
+
"./package.json",
|
|
212
|
+
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
213
|
+
"utf-8"
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
await w("init");
|
|
217
|
+
const packageJson = JSON.parse(
|
|
218
|
+
fs.readFileSync("./package.json", "utf-8")
|
|
219
|
+
);
|
|
220
|
+
expect(packageJson.name).toEqual("test");
|
|
221
|
+
expect(packageJson.version).toEqual("1.0.0");
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("should not touch an existing package.json in an ancestor directory", async () => {
|
|
225
|
+
mockConfirm({
|
|
226
|
+
text: "Would you like to use typescript?",
|
|
227
|
+
result: false,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
fs.writeFileSync(
|
|
231
|
+
"./package.json",
|
|
232
|
+
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
233
|
+
"utf-8"
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
fs.mkdirSync("./sub-1/sub-2", { recursive: true });
|
|
237
|
+
process.chdir("./sub-1/sub-2");
|
|
238
|
+
|
|
239
|
+
await w("init");
|
|
240
|
+
expect(fs.existsSync("./package.json")).toBe(false);
|
|
241
|
+
expect(fs.existsSync("../../package.json")).toBe(true);
|
|
242
|
+
|
|
243
|
+
const packageJson = JSON.parse(
|
|
244
|
+
fs.readFileSync("../../package.json", "utf-8")
|
|
245
|
+
);
|
|
246
|
+
expect(packageJson.name).toEqual("test");
|
|
247
|
+
expect(packageJson.version).toEqual("1.0.0");
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("should create a tsconfig.json and install `workers-types` if none is found and user confirms", async () => {
|
|
251
|
+
mockConfirm(
|
|
252
|
+
{
|
|
253
|
+
text: "No package.json found. Would you like to create one?",
|
|
254
|
+
result: true,
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
text: "Would you like to use typescript?",
|
|
258
|
+
result: true,
|
|
259
|
+
}
|
|
260
|
+
);
|
|
261
|
+
await w("init");
|
|
262
|
+
expect(fs.existsSync("./tsconfig.json")).toBe(true);
|
|
263
|
+
const tsconfigJson = JSON.parse(
|
|
264
|
+
fs.readFileSync("./tsconfig.json", "utf-8")
|
|
265
|
+
);
|
|
266
|
+
expect(tsconfigJson.compilerOptions.types).toEqual([
|
|
267
|
+
"@cloudflare/workers-types",
|
|
268
|
+
]);
|
|
269
|
+
const packageJson = JSON.parse(
|
|
270
|
+
fs.readFileSync("./package.json", "utf-8")
|
|
271
|
+
);
|
|
272
|
+
expect(packageJson.devDependencies).toEqual({
|
|
273
|
+
"@cloudflare/workers-types": expect.any(String),
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it("should not touch an existing tsconfig.json in the same directory", async () => {
|
|
278
|
+
fs.writeFileSync(
|
|
279
|
+
"./package.json",
|
|
280
|
+
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
281
|
+
"utf-8"
|
|
282
|
+
);
|
|
283
|
+
fs.writeFileSync(
|
|
284
|
+
"./tsconfig.json",
|
|
285
|
+
JSON.stringify({ compilerOptions: {} }),
|
|
286
|
+
"utf-8"
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
await w("init");
|
|
290
|
+
const tsconfigJson = JSON.parse(
|
|
291
|
+
fs.readFileSync("./tsconfig.json", "utf-8")
|
|
292
|
+
);
|
|
293
|
+
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("should not touch an existing package.json in an ancestor directory", async () => {
|
|
297
|
+
fs.writeFileSync(
|
|
298
|
+
"./package.json",
|
|
299
|
+
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
300
|
+
"utf-8"
|
|
301
|
+
);
|
|
302
|
+
fs.writeFileSync(
|
|
303
|
+
"./tsconfig.json",
|
|
304
|
+
JSON.stringify({ compilerOptions: {} }),
|
|
305
|
+
"utf-8"
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
fs.mkdirSync("./sub-1/sub-2", { recursive: true });
|
|
309
|
+
process.chdir("./sub-1/sub-2");
|
|
310
|
+
|
|
311
|
+
await w("init");
|
|
312
|
+
expect(fs.existsSync("./tsconfig.json")).toBe(false);
|
|
313
|
+
expect(fs.existsSync("../../tsconfig.json")).toBe(true);
|
|
314
|
+
|
|
315
|
+
const tsconfigJson = JSON.parse(
|
|
316
|
+
fs.readFileSync("../../tsconfig.json", "utf-8")
|
|
317
|
+
);
|
|
318
|
+
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("should error if `--type` is used", async () => {
|
|
322
|
+
const noValue = await w("init --type");
|
|
323
|
+
expect(noValue.stderr).toMatchInlineSnapshot(
|
|
324
|
+
`"The --type option is no longer supported."`
|
|
325
|
+
);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("should error if `--type javascript` is used", async () => {
|
|
329
|
+
const javascriptValue = await w("init --type javascript");
|
|
330
|
+
expect(javascriptValue.stderr).toMatchInlineSnapshot(
|
|
331
|
+
`"The --type option is no longer supported."`
|
|
332
|
+
);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it("should error if `--type rust` is used", async () => {
|
|
336
|
+
const rustValue = await w("init --type rust");
|
|
337
|
+
expect(rustValue.stderr).toMatchInlineSnapshot(
|
|
338
|
+
`"The --type option is no longer supported."`
|
|
339
|
+
);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it("should error if `--type webpack` is used", async () => {
|
|
343
|
+
const webpackValue = await w("init --type webpack");
|
|
344
|
+
expect(webpackValue.stderr).toMatchInlineSnapshot(`
|
|
345
|
+
"The --type option is no longer supported.
|
|
346
|
+
If you wish to use webpack then you will need to create a custom build."
|
|
347
|
+
`);
|
|
96
348
|
});
|
|
97
349
|
});
|
|
98
350
|
|
|
99
351
|
describe("kv:namespace", () => {
|
|
100
|
-
|
|
352
|
+
afterEach(() => {
|
|
101
353
|
unsetAllMocks();
|
|
102
354
|
});
|
|
103
|
-
|
|
355
|
+
|
|
104
356
|
it("can create a namespace", async () => {
|
|
357
|
+
const KVNamespaces: { title: string; id: string }[] = [];
|
|
105
358
|
setMock("/accounts/:accountId/storage/kv/namespaces", (uri, init) => {
|
|
106
359
|
expect(init.method === "POST");
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
360
|
+
expect(uri[0]).toEqual(
|
|
361
|
+
"/accounts/some-account-id/storage/kv/namespaces"
|
|
362
|
+
);
|
|
363
|
+
const { title } = JSON.parse(init.body);
|
|
364
|
+
expect(title).toEqual("worker-UnitTestNamespace");
|
|
365
|
+
KVNamespaces.push({ title, id: "some-namespace-id" });
|
|
110
366
|
return { id: "some-namespace-id" };
|
|
111
367
|
});
|
|
112
368
|
|
|
113
369
|
await w("kv:namespace create UnitTestNamespace");
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
370
|
+
|
|
371
|
+
expect(KVNamespaces).toEqual([
|
|
372
|
+
{
|
|
373
|
+
title: "worker-UnitTestNamespace",
|
|
374
|
+
id: "some-namespace-id",
|
|
375
|
+
},
|
|
376
|
+
]);
|
|
117
377
|
});
|
|
118
378
|
|
|
119
|
-
let createdNamespace: { id: string; title: string };
|
|
120
379
|
it("can list namespaces", async () => {
|
|
380
|
+
const KVNamespaces: { title: string; id: string }[] = [
|
|
381
|
+
{ title: "title-1", id: "id-1" },
|
|
382
|
+
{ title: "title-2", id: "id-2" },
|
|
383
|
+
];
|
|
121
384
|
setMock(
|
|
122
385
|
"/accounts/:accountId/storage/kv/namespaces\\?:qs",
|
|
123
386
|
(uri, init) => {
|
|
387
|
+
expect(uri[0]).toContain(
|
|
388
|
+
"/accounts/some-account-id/storage/kv/namespaces"
|
|
389
|
+
);
|
|
390
|
+
expect(uri[2]).toContain("per_page=100");
|
|
391
|
+
expect(uri[2]).toContain("order=title");
|
|
392
|
+
expect(uri[2]).toContain("direction=asc");
|
|
393
|
+
expect(uri[2]).toContain("page=1");
|
|
124
394
|
expect(init).toBe(undefined);
|
|
125
395
|
return KVNamespaces;
|
|
126
396
|
}
|
|
127
397
|
);
|
|
128
|
-
const { stdout } = await w("kv:namespace list"
|
|
129
|
-
const namespaces = JSON.parse(stdout);
|
|
130
|
-
|
|
131
|
-
(ns) => ns.title === "worker-UnitTestNamespace"
|
|
132
|
-
);
|
|
133
|
-
expect(createdNamespace.title).toBe("worker-UnitTestNamespace");
|
|
398
|
+
const { stdout } = await w("kv:namespace list");
|
|
399
|
+
const namespaces = JSON.parse(stdout) as { id: string; title: string }[];
|
|
400
|
+
expect(namespaces).toEqual(KVNamespaces);
|
|
134
401
|
});
|
|
135
402
|
|
|
136
403
|
it("can delete a namespace", async () => {
|
|
137
|
-
|
|
404
|
+
let accountId = "";
|
|
405
|
+
let namespaceId = "";
|
|
138
406
|
setMock(
|
|
139
407
|
"/accounts/:accountId/storage/kv/namespaces/:namespaceId",
|
|
140
408
|
(uri, init) => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
409
|
+
accountId = uri[1];
|
|
410
|
+
namespaceId = uri[2];
|
|
411
|
+
expect(uri[0]).toEqual(
|
|
412
|
+
"/accounts/some-account-id/storage/kv/namespaces/some-namespace-id"
|
|
144
413
|
);
|
|
414
|
+
expect(init.method).toBe("DELETE");
|
|
145
415
|
}
|
|
146
416
|
);
|
|
147
|
-
await w(`kv:namespace delete --namespace-id
|
|
148
|
-
expect(
|
|
149
|
-
|
|
150
|
-
);
|
|
417
|
+
await w(`kv:namespace delete --namespace-id some-namespace-id`);
|
|
418
|
+
expect(accountId).toEqual("some-account-id");
|
|
419
|
+
expect(namespaceId).toEqual("some-namespace-id");
|
|
151
420
|
});
|
|
152
421
|
});
|
|
153
422
|
});
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
// This file mocks ../cfetch.ts
|
|
2
2
|
// so we can insert whatever responses we want from it
|
|
3
3
|
|
|
4
|
-
const pathToRegexp = require("path-to-regexp");
|
|
4
|
+
const { pathToRegexp } = require("path-to-regexp");
|
|
5
5
|
// TODO: add jsdoc style types here
|
|
6
6
|
|
|
7
7
|
// type MockHandler = (resource: string, init?: RequestInit) => any; // TODO: use a generic here
|
|
8
8
|
|
|
9
9
|
let mocks = [];
|
|
10
10
|
|
|
11
|
-
function mockCfetch(resource, init) {
|
|
11
|
+
export function mockCfetch(resource, init) {
|
|
12
12
|
for (const { regexp, handler } of mocks) {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
// The `resource` regular expression will extract the labelled groups from the URL.
|
|
14
|
+
// Let's pass these through to the handler, to allow it to do additional checks or behaviour.
|
|
15
|
+
const uri = regexp.exec(resource);
|
|
16
|
+
if (uri !== null) {
|
|
17
|
+
return handler(uri, init); // TODO: should we have some kind of fallthrough system? we'll see.
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
throw new Error(`no mocks found for ${resource}`);
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
function setMock(resource, handler) {
|
|
23
|
+
export function setMock(resource, handler) {
|
|
21
24
|
const mock = {
|
|
22
25
|
resource,
|
|
23
26
|
handler,
|
|
@@ -29,18 +32,11 @@ function setMock(resource, handler) {
|
|
|
29
32
|
};
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
function unsetAllMocks() {
|
|
35
|
+
export function unsetAllMocks() {
|
|
33
36
|
mocks = [];
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
const CF_API_BASE_URL =
|
|
39
|
+
export const CF_API_BASE_URL =
|
|
37
40
|
process.env.CF_API_BASE_URL || "https://api.cloudflare.com/client/v4";
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
__esModule: true,
|
|
41
|
-
default: mockCfetch,
|
|
42
|
-
mockCfetch,
|
|
43
|
-
setMock,
|
|
44
|
-
unsetAllMocks,
|
|
45
|
-
CF_API_BASE_URL,
|
|
46
|
-
});
|
|
42
|
+
export default mockCfetch;
|
package/src/api/inspect.ts
CHANGED
|
@@ -140,17 +140,6 @@ export type DtEvent = DtLogEvent | DtExceptionEvent;
|
|
|
140
140
|
*/
|
|
141
141
|
export type DtListener = (event: DtEvent) => void;
|
|
142
142
|
|
|
143
|
-
interface DtProtocolRequest<T> {
|
|
144
|
-
id: number;
|
|
145
|
-
method: string;
|
|
146
|
-
params?: T;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
interface DtProtocolResponse<T> {
|
|
150
|
-
id: number;
|
|
151
|
-
result: T;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
143
|
/**
|
|
155
144
|
* A DevTools inspector that listens to logs and debug events from a Worker.
|
|
156
145
|
*
|