wrangler 2.0.2 → 2.0.3
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/Cloudflare_CA.pem +18 -0
- package/bin/wrangler.js +21 -1
- package/package.json +4 -2
- package/pages/functions/buildWorker.ts +1 -1
- package/pages/functions/template-plugin.ts +3 -2
- package/src/__tests__/configuration.test.ts +1 -1
- package/src/__tests__/dev.test.tsx +77 -10
- package/src/__tests__/index.test.ts +51 -58
- package/src/__tests__/jest.setup.ts +8 -0
- package/src/__tests__/kv.test.ts +69 -48
- package/src/__tests__/pages.test.ts +6 -8
- package/src/__tests__/publish.test.ts +56 -7
- package/src/__tests__/r2.test.ts +12 -16
- package/src/config/config.ts +1 -1
- package/src/config/validation.ts +1 -1
- package/src/dev/dev.tsx +5 -2
- package/src/entry.ts +64 -9
- package/src/index.tsx +55 -21
- package/src/kv.ts +3 -1
- package/src/pages.tsx +8 -1
- package/src/user.tsx +11 -1
- package/wrangler-dist/cli.js +971 -749
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
|
2
|
+
MIIC6zCCAkygAwIBAgIUI7b68p0pPrCBoW4ptlyvVcPItscwCgYIKoZIzj0EAwQw
|
|
3
|
+
gY0xCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T
|
|
4
|
+
YW4gRnJhbmNpc2NvMRgwFgYDVQQKEw9DbG91ZGZsYXJlLCBJbmMxNzA1BgNVBAMT
|
|
5
|
+
LkNsb3VkZmxhcmUgZm9yIFRlYW1zIEVDQyBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkw
|
|
6
|
+
HhcNMjAwMjA0MTYwNTAwWhcNMjUwMjAyMTYwNTAwWjCBjTELMAkGA1UEBhMCVVMx
|
|
7
|
+
EzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xGDAW
|
|
8
|
+
BgNVBAoTD0Nsb3VkZmxhcmUsIEluYzE3MDUGA1UEAxMuQ2xvdWRmbGFyZSBmb3Ig
|
|
9
|
+
VGVhbXMgRUNDIENlcnRpZmljYXRlIEF1dGhvcml0eTCBmzAQBgcqhkjOPQIBBgUr
|
|
10
|
+
gQQAIwOBhgAEAVdXsX8tpA9NAQeEQalvUIcVaFNDvGsR69ysZxOraRWNGHLfq1mi
|
|
11
|
+
P6o3wtmtx/C2OXG01Cw7UFJbKl5MEDxnT2KoAdFSynSJOF2NDoe5LoZHbUW+yR3X
|
|
12
|
+
FDl+MF6JzZ590VLGo6dPBf06UsXbH7PvHH2XKtFt8bBXVNMa5a21RdmpD0Pho0Uw
|
|
13
|
+
QzAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBAjAdBgNVHQ4EFgQU
|
|
14
|
+
YBcQng1AEMMNteuRDAMG0/vgFe0wCgYIKoZIzj0EAwQDgYwAMIGIAkIBQU5OTA2h
|
|
15
|
+
YqmFk8paan5ezHVLcmcucsfYw4L/wmeEjCkczRmCVNm6L86LjhWU0v0wER0e+lHO
|
|
16
|
+
3efvjbsu8gIGSagCQgEBnyYMP9gwg8l96QnQ1khFA1ljFlnqc2XgJHDSaAJC0gdz
|
|
17
|
+
+NV3JMeWaD2Rb32jc9r6/a7xY0u0ByqxBQ1OQ0dt7A==
|
|
18
|
+
-----END CERTIFICATE-----
|
package/bin/wrangler.js
CHANGED
|
@@ -20,6 +20,20 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
|
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
let pathToCACerts = process.env.NODE_EXTRA_CA_CERTS;
|
|
24
|
+
if (pathToCACerts) {
|
|
25
|
+
// TODO:
|
|
26
|
+
// - should we log a warning here?
|
|
27
|
+
// - maybe we can generate a certificate that concatenates with ours?
|
|
28
|
+
// - is there a security concern/should we cleanup after we exit?
|
|
29
|
+
//
|
|
30
|
+
// I do think it'll be rare that someone wants to add a cert AND
|
|
31
|
+
// use cloudflare WARP, but let's wait till the situation actually
|
|
32
|
+
// arises before we do anything about it
|
|
33
|
+
} else {
|
|
34
|
+
pathToCACerts = join(__dirname, "../Cloudflare_CA.pem");
|
|
35
|
+
}
|
|
36
|
+
|
|
23
37
|
wranglerProcess = spawn(
|
|
24
38
|
process.execPath,
|
|
25
39
|
[
|
|
@@ -32,7 +46,13 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
|
|
|
32
46
|
join(__dirname, "../wrangler-dist/cli.js"),
|
|
33
47
|
...process.argv.slice(2),
|
|
34
48
|
],
|
|
35
|
-
{
|
|
49
|
+
{
|
|
50
|
+
stdio: "inherit",
|
|
51
|
+
env: {
|
|
52
|
+
...process.env,
|
|
53
|
+
NODE_EXTRA_CA_CERTS: pathToCACerts,
|
|
54
|
+
},
|
|
55
|
+
}
|
|
36
56
|
).on("exit", (code) =>
|
|
37
57
|
process.exit(code === undefined || code === null ? 0 : code)
|
|
38
58
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"author": "wrangler@cloudflare.com",
|
|
5
5
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
6
6
|
"bin": {
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"@types/supports-color": "^8.1.1",
|
|
63
63
|
"@types/ws": "^8.5.3",
|
|
64
64
|
"@types/yargs": "^17.0.10",
|
|
65
|
+
"@webcontainer/env": "^1.0.1",
|
|
65
66
|
"chokidar": "^3.5.3",
|
|
66
67
|
"clipboardy": "^3.0.0",
|
|
67
68
|
"cmd-shim": "^4.1.0",
|
|
@@ -109,7 +110,8 @@
|
|
|
109
110
|
"wrangler-dist",
|
|
110
111
|
"templates",
|
|
111
112
|
"vendor",
|
|
112
|
-
"import_meta_url.js"
|
|
113
|
+
"import_meta_url.js",
|
|
114
|
+
"Cloudflare_CA.pem"
|
|
113
115
|
],
|
|
114
116
|
"scripts": {
|
|
115
117
|
"clean": "rm -rf wrangler-dist miniflare-dist",
|
|
@@ -122,7 +122,7 @@ export function buildWorker({
|
|
|
122
122
|
// TODO: Watch args.path for changes and re-copy when updated
|
|
123
123
|
contents: `export const onRequest = ({ request, env, functionPath }) => {
|
|
124
124
|
const url = new URL(request.url)
|
|
125
|
-
const relativePathname = url.pathname.split(functionPath)[1] ||
|
|
125
|
+
const relativePathname = \`/\${url.pathname.split(functionPath)[1] || ''}\`.replace(/^\\/\\//, '/');
|
|
126
126
|
url.pathname = '/cdn-cgi/pages-plugins/${identifier}' + relativePathname
|
|
127
127
|
request = new Request(url.toString(), request)
|
|
128
128
|
return env.ASSETS.fetch(request)
|
|
@@ -103,8 +103,9 @@ export default function (pluginArgs) {
|
|
|
103
103
|
const { env, next, data } = workerContext;
|
|
104
104
|
|
|
105
105
|
const url = new URL(request.url);
|
|
106
|
-
const relativePathname =
|
|
107
|
-
url.pathname.split(workerContext.functionPath)[1] || "
|
|
106
|
+
const relativePathname = `/${
|
|
107
|
+
url.pathname.split(workerContext.functionPath)[1] || ""
|
|
108
|
+
}`.replace(/^\/\//, "/");
|
|
108
109
|
|
|
109
110
|
const handlerIterator = executeRequest(request, relativePathname);
|
|
110
111
|
const pluginNext = async (input?: RequestInfo, init?: RequestInit) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
|
+
import getPort from "get-port";
|
|
2
3
|
import patchConsole from "patch-console";
|
|
3
4
|
import dedent from "ts-dedent";
|
|
4
5
|
import Dev from "../dev/dev";
|
|
@@ -432,18 +433,20 @@ describe("wrangler dev", () => {
|
|
|
432
433
|
},
|
|
433
434
|
});
|
|
434
435
|
|
|
435
|
-
await expect(
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
436
|
+
await expect(runWrangler("dev")).rejects
|
|
437
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
438
|
+
"The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
|
|
439
|
+
The \`main\` property in wrangler.toml should point to the file generated by the custom build."
|
|
440
|
+
`);
|
|
440
441
|
expect(std.out).toMatchInlineSnapshot(`
|
|
441
442
|
"Running custom build: node -e \\"console.log('custom build');\\"
|
|
442
443
|
|
|
443
444
|
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
444
445
|
`);
|
|
445
446
|
expect(std.err).toMatchInlineSnapshot(`
|
|
446
|
-
"[31mX [41;31m[[41;97mERROR[41;31m][0m [
|
|
447
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThe expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".[0m
|
|
448
|
+
|
|
449
|
+
The \`main\` property in wrangler.toml should point to the file generated by the custom build.
|
|
447
450
|
|
|
448
451
|
"
|
|
449
452
|
`);
|
|
@@ -580,6 +583,71 @@ describe("wrangler dev", () => {
|
|
|
580
583
|
});
|
|
581
584
|
});
|
|
582
585
|
|
|
586
|
+
describe("port", () => {
|
|
587
|
+
it("should default port to 8787 if it is not in use", async () => {
|
|
588
|
+
writeWranglerToml({
|
|
589
|
+
main: "index.js",
|
|
590
|
+
});
|
|
591
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
592
|
+
await runWrangler("dev");
|
|
593
|
+
expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(8787);
|
|
594
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
595
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
596
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
it("should use to `port` from `wrangler.toml`, if available", async () => {
|
|
600
|
+
writeWranglerToml({
|
|
601
|
+
main: "index.js",
|
|
602
|
+
dev: {
|
|
603
|
+
port: 8888,
|
|
604
|
+
},
|
|
605
|
+
});
|
|
606
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
607
|
+
// Mock `getPort()` to resolve to a completely different port.
|
|
608
|
+
(getPort as jest.Mock).mockResolvedValue(98765);
|
|
609
|
+
|
|
610
|
+
await runWrangler("dev");
|
|
611
|
+
expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(8888);
|
|
612
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
613
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
614
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
it("should use --port command line arg, if provided", async () => {
|
|
618
|
+
writeWranglerToml({
|
|
619
|
+
main: "index.js",
|
|
620
|
+
dev: {
|
|
621
|
+
port: 8888,
|
|
622
|
+
},
|
|
623
|
+
});
|
|
624
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
625
|
+
// Mock `getPort()` to resolve to a completely different port.
|
|
626
|
+
(getPort as jest.Mock).mockResolvedValue(98765);
|
|
627
|
+
|
|
628
|
+
await runWrangler("dev --port=9999");
|
|
629
|
+
expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(9999);
|
|
630
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
631
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
632
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
it("should use a different port to the default if it is in use", async () => {
|
|
636
|
+
writeWranglerToml({
|
|
637
|
+
main: "index.js",
|
|
638
|
+
});
|
|
639
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
640
|
+
// Mock `getPort()` to resolve to a completely different port.
|
|
641
|
+
(getPort as jest.Mock).mockResolvedValue(98765);
|
|
642
|
+
|
|
643
|
+
await runWrangler("dev");
|
|
644
|
+
expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(98765);
|
|
645
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
646
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
647
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
|
|
583
651
|
describe("durable_objects", () => {
|
|
584
652
|
it("should warn if there is one or more remote Durable Object", async () => {
|
|
585
653
|
writeWranglerToml({
|
|
@@ -688,10 +756,9 @@ describe("wrangler dev", () => {
|
|
|
688
756
|
script The path to an entry point for your worker [string]
|
|
689
757
|
|
|
690
758
|
Flags:
|
|
691
|
-
-c, --config
|
|
692
|
-
-h, --help
|
|
693
|
-
-v, --version
|
|
694
|
-
--legacy-env Use legacy environments [boolean]
|
|
759
|
+
-c, --config Path to .toml configuration file [string]
|
|
760
|
+
-h, --help Show help [boolean]
|
|
761
|
+
-v, --version Show version number [boolean]
|
|
695
762
|
|
|
696
763
|
Options:
|
|
697
764
|
--name Name of the worker [string]
|
|
@@ -44,10 +44,9 @@ describe("wrangler", () => {
|
|
|
44
44
|
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
45
45
|
|
|
46
46
|
Flags:
|
|
47
|
-
-c, --config
|
|
48
|
-
-h, --help
|
|
49
|
-
-v, --version
|
|
50
|
-
--legacy-env Use legacy environments [boolean]"
|
|
47
|
+
-c, --config Path to .toml configuration file [string]
|
|
48
|
+
-h, --help Show help [boolean]
|
|
49
|
+
-v, --version Show version number [boolean]"
|
|
51
50
|
`);
|
|
52
51
|
|
|
53
52
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
@@ -85,10 +84,9 @@ describe("wrangler", () => {
|
|
|
85
84
|
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
86
85
|
|
|
87
86
|
Flags:
|
|
88
|
-
-c, --config
|
|
89
|
-
-h, --help
|
|
90
|
-
-v, --version
|
|
91
|
-
--legacy-env Use legacy environments [boolean]
|
|
87
|
+
-c, --config Path to .toml configuration file [string]
|
|
88
|
+
-h, --help Show help [boolean]
|
|
89
|
+
-v, --version Show version number [boolean]
|
|
92
90
|
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mUnknown argument: invalid-command[0m
|
|
93
91
|
|
|
94
92
|
"
|
|
@@ -133,10 +131,9 @@ describe("wrangler", () => {
|
|
|
133
131
|
wrangler secret list List all secrets for a script
|
|
134
132
|
|
|
135
133
|
Flags:
|
|
136
|
-
-c, --config
|
|
137
|
-
-h, --help
|
|
138
|
-
-v, --version
|
|
139
|
-
--legacy-env Use legacy environments [boolean]"
|
|
134
|
+
-c, --config Path to .toml configuration file [string]
|
|
135
|
+
-h, --help Show help [boolean]
|
|
136
|
+
-v, --version Show version number [boolean]"
|
|
140
137
|
`);
|
|
141
138
|
});
|
|
142
139
|
|
|
@@ -144,20 +141,19 @@ describe("wrangler", () => {
|
|
|
144
141
|
await runWrangler("kv:namespace");
|
|
145
142
|
await endEventLoop();
|
|
146
143
|
expect(std.out).toMatchInlineSnapshot(`
|
|
147
|
-
|
|
144
|
+
"wrangler kv:namespace
|
|
148
145
|
|
|
149
|
-
|
|
146
|
+
🗂️ Interact with your Workers KV Namespaces
|
|
150
147
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
148
|
+
Commands:
|
|
149
|
+
wrangler kv:namespace create <namespace> Create a new namespace
|
|
150
|
+
wrangler kv:namespace list Outputs a list of all KV namespaces associated with your account id.
|
|
151
|
+
wrangler kv:namespace delete Deletes a given namespace.
|
|
155
152
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
--legacy-env Use legacy environments [boolean]"
|
|
153
|
+
Flags:
|
|
154
|
+
-c, --config Path to .toml configuration file [string]
|
|
155
|
+
-h, --help Show help [boolean]
|
|
156
|
+
-v, --version Show version number [boolean]"
|
|
161
157
|
`);
|
|
162
158
|
});
|
|
163
159
|
|
|
@@ -165,60 +161,57 @@ describe("wrangler", () => {
|
|
|
165
161
|
await runWrangler("kv:key");
|
|
166
162
|
await endEventLoop();
|
|
167
163
|
expect(std.out).toMatchInlineSnapshot(`
|
|
168
|
-
|
|
164
|
+
"wrangler kv:key
|
|
169
165
|
|
|
170
|
-
|
|
166
|
+
🔑 Individually manage Workers KV key-value pairs
|
|
171
167
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
168
|
+
Commands:
|
|
169
|
+
wrangler kv:key put <key> [value] Writes a single key/value pair to the given namespace.
|
|
170
|
+
wrangler kv:key list Outputs a list of all keys in a given namespace.
|
|
171
|
+
wrangler kv:key get <key> Reads a single value by key from the given namespace.
|
|
172
|
+
wrangler kv:key delete <key> Removes a single key value pair from the given namespace.
|
|
177
173
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
`);
|
|
174
|
+
Flags:
|
|
175
|
+
-c, --config Path to .toml configuration file [string]
|
|
176
|
+
-h, --help Show help [boolean]
|
|
177
|
+
-v, --version Show version number [boolean]"
|
|
178
|
+
`);
|
|
184
179
|
});
|
|
185
180
|
|
|
186
181
|
it("no subcommand 'kv:bulk' should display a list of available subcommands", async () => {
|
|
187
182
|
await runWrangler("kv:bulk");
|
|
188
183
|
await endEventLoop();
|
|
189
184
|
expect(std.out).toMatchInlineSnapshot(`
|
|
190
|
-
|
|
185
|
+
"wrangler kv:bulk
|
|
191
186
|
|
|
192
|
-
|
|
187
|
+
💪 Interact with multiple Workers KV key-value pairs at once
|
|
193
188
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
189
|
+
Commands:
|
|
190
|
+
wrangler kv:bulk put <filename> Upload multiple key-value pairs to a namespace
|
|
191
|
+
wrangler kv:bulk delete <filename> Delete multiple key-value pairs from a namespace
|
|
197
192
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
`);
|
|
193
|
+
Flags:
|
|
194
|
+
-c, --config Path to .toml configuration file [string]
|
|
195
|
+
-h, --help Show help [boolean]
|
|
196
|
+
-v, --version Show version number [boolean]"
|
|
197
|
+
`);
|
|
204
198
|
});
|
|
205
199
|
it("no subcommand 'r2' should display a list of available subcommands", async () => {
|
|
206
200
|
await runWrangler("r2");
|
|
207
201
|
await endEventLoop();
|
|
208
202
|
expect(std.out).toMatchInlineSnapshot(`
|
|
209
|
-
|
|
203
|
+
"wrangler r2
|
|
210
204
|
|
|
211
|
-
|
|
205
|
+
📦 Interact with an R2 store
|
|
212
206
|
|
|
213
|
-
|
|
214
|
-
|
|
207
|
+
Commands:
|
|
208
|
+
wrangler r2 bucket Manage R2 buckets
|
|
215
209
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
`);
|
|
210
|
+
Flags:
|
|
211
|
+
-c, --config Path to .toml configuration file [string]
|
|
212
|
+
-h, --help Show help [boolean]
|
|
213
|
+
-v, --version Show version number [boolean]"
|
|
214
|
+
`);
|
|
222
215
|
});
|
|
223
216
|
});
|
|
224
217
|
describe("Deprecated commands", () => {
|
|
@@ -241,7 +234,7 @@ describe("wrangler", () => {
|
|
|
241
234
|
await runWrangler("build").catch((err) => {
|
|
242
235
|
expect(err.message).toMatchInlineSnapshot(`
|
|
243
236
|
"Deprecation:
|
|
244
|
-
\`wrangler build\` has been deprecated, please refer to https://
|
|
237
|
+
\`wrangler build\` has been deprecated, please refer to https://developers.cloudflare.com/workers/wrangler/migration/deprecations/#build for alternatives"
|
|
245
238
|
`);
|
|
246
239
|
});
|
|
247
240
|
});
|
|
@@ -8,6 +8,14 @@ import { confirm, prompt } from "../dialogs";
|
|
|
8
8
|
import { mockFetchInternal, mockFetchKVGetValue } from "./helpers/mock-cfetch";
|
|
9
9
|
import { MockWebSocket } from "./helpers/mock-web-socket";
|
|
10
10
|
|
|
11
|
+
// Mock out getPort since we don't actually care about what ports are open in unit tests.
|
|
12
|
+
jest.mock("get-port", () => {
|
|
13
|
+
return {
|
|
14
|
+
__esModule: true,
|
|
15
|
+
default: jest.fn().mockImplementation(async (options) => options.port),
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
|
|
11
19
|
jest.mock("ws", () => {
|
|
12
20
|
return {
|
|
13
21
|
__esModule: true,
|
package/src/__tests__/kv.test.ts
CHANGED
|
@@ -59,10 +59,9 @@ describe("wrangler", () => {
|
|
|
59
59
|
namespace The name of the new namespace [string] [required]
|
|
60
60
|
|
|
61
61
|
Flags:
|
|
62
|
-
-c, --config
|
|
63
|
-
-h, --help
|
|
64
|
-
-v, --version
|
|
65
|
-
--legacy-env Use legacy environments [boolean]
|
|
62
|
+
-c, --config Path to .toml configuration file [string]
|
|
63
|
+
-h, --help Show help [boolean]
|
|
64
|
+
-v, --version Show version number [boolean]
|
|
66
65
|
|
|
67
66
|
Options:
|
|
68
67
|
-e, --env Perform on a specific environment [string]
|
|
@@ -92,10 +91,9 @@ describe("wrangler", () => {
|
|
|
92
91
|
namespace The name of the new namespace [string] [required]
|
|
93
92
|
|
|
94
93
|
Flags:
|
|
95
|
-
-c, --config
|
|
96
|
-
-h, --help
|
|
97
|
-
-v, --version
|
|
98
|
-
--legacy-env Use legacy environments [boolean]
|
|
94
|
+
-c, --config Path to .toml configuration file [string]
|
|
95
|
+
-h, --help Show help [boolean]
|
|
96
|
+
-v, --version Show version number [boolean]
|
|
99
97
|
|
|
100
98
|
Options:
|
|
101
99
|
-e, --env Perform on a specific environment [string]
|
|
@@ -126,10 +124,9 @@ describe("wrangler", () => {
|
|
|
126
124
|
namespace The name of the new namespace [string] [required]
|
|
127
125
|
|
|
128
126
|
Flags:
|
|
129
|
-
-c, --config
|
|
130
|
-
-h, --help
|
|
131
|
-
-v, --version
|
|
132
|
-
--legacy-env Use legacy environments [boolean]
|
|
127
|
+
-c, --config Path to .toml configuration file [string]
|
|
128
|
+
-h, --help Show help [boolean]
|
|
129
|
+
-v, --version Show version number [boolean]
|
|
133
130
|
|
|
134
131
|
Options:
|
|
135
132
|
-e, --env Perform on a specific environment [string]
|
|
@@ -260,6 +257,14 @@ describe("wrangler", () => {
|
|
|
260
257
|
expect(requests.count).toEqual(1);
|
|
261
258
|
});
|
|
262
259
|
|
|
260
|
+
it("should encode URI id properly for deleting namespace", async () => {
|
|
261
|
+
const requests = mockDeleteRequest("%2Fvoyager");
|
|
262
|
+
await runWrangler(`kv:namespace delete --namespace-id /voyager`);
|
|
263
|
+
expect(requests.count).toEqual(1);
|
|
264
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
265
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
266
|
+
});
|
|
267
|
+
|
|
263
268
|
it("should delete a namespace specified by binding name", async () => {
|
|
264
269
|
writeWranglerConfig();
|
|
265
270
|
const requests = mockDeleteRequest("bound-id");
|
|
@@ -291,10 +296,9 @@ describe("wrangler", () => {
|
|
|
291
296
|
Deletes a given namespace.
|
|
292
297
|
|
|
293
298
|
Flags:
|
|
294
|
-
-c, --config
|
|
295
|
-
-h, --help
|
|
296
|
-
-v, --version
|
|
297
|
-
--legacy-env Use legacy environments [boolean]
|
|
299
|
+
-c, --config Path to .toml configuration file [string]
|
|
300
|
+
-h, --help Show help [boolean]
|
|
301
|
+
-v, --version Show version number [boolean]
|
|
298
302
|
|
|
299
303
|
Options:
|
|
300
304
|
--binding The name of the namespace to delete [string]
|
|
@@ -385,6 +389,21 @@ describe("wrangler", () => {
|
|
|
385
389
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
386
390
|
});
|
|
387
391
|
|
|
392
|
+
it("should encode URI key's properly for putting in a key request", async () => {
|
|
393
|
+
const requests = mockKeyPutRequest("DS9", {
|
|
394
|
+
key: "%2Fmy-key",
|
|
395
|
+
value: "my-value",
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
await runWrangler("kv:key put /my-key my-value --namespace-id DS9");
|
|
399
|
+
|
|
400
|
+
expect(requests.count).toEqual(1);
|
|
401
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
402
|
+
`"Writing the value \\"my-value\\" to key \\"/my-key\\" on namespace DS9."`
|
|
403
|
+
);
|
|
404
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
405
|
+
});
|
|
406
|
+
|
|
388
407
|
it("should put a key in a given namespace specified by binding", async () => {
|
|
389
408
|
writeWranglerConfig();
|
|
390
409
|
const requests = mockKeyPutRequest("bound-id", {
|
|
@@ -490,10 +509,9 @@ describe("wrangler", () => {
|
|
|
490
509
|
value The value to write [string]
|
|
491
510
|
|
|
492
511
|
Flags:
|
|
493
|
-
-c, --config
|
|
494
|
-
-h, --help
|
|
495
|
-
-v, --version
|
|
496
|
-
--legacy-env Use legacy environments [boolean]
|
|
512
|
+
-c, --config Path to .toml configuration file [string]
|
|
513
|
+
-h, --help Show help [boolean]
|
|
514
|
+
-v, --version Show version number [boolean]
|
|
497
515
|
|
|
498
516
|
Options:
|
|
499
517
|
--binding The binding of the namespace to write to [string]
|
|
@@ -530,10 +548,9 @@ describe("wrangler", () => {
|
|
|
530
548
|
value The value to write [string]
|
|
531
549
|
|
|
532
550
|
Flags:
|
|
533
|
-
-c, --config
|
|
534
|
-
-h, --help
|
|
535
|
-
-v, --version
|
|
536
|
-
--legacy-env Use legacy environments [boolean]
|
|
551
|
+
-c, --config Path to .toml configuration file [string]
|
|
552
|
+
-h, --help Show help [boolean]
|
|
553
|
+
-v, --version Show version number [boolean]
|
|
537
554
|
|
|
538
555
|
Options:
|
|
539
556
|
--binding The binding of the namespace to write to [string]
|
|
@@ -570,10 +587,9 @@ describe("wrangler", () => {
|
|
|
570
587
|
value The value to write [string]
|
|
571
588
|
|
|
572
589
|
Flags:
|
|
573
|
-
-c, --config
|
|
574
|
-
-h, --help
|
|
575
|
-
-v, --version
|
|
576
|
-
--legacy-env Use legacy environments [boolean]
|
|
590
|
+
-c, --config Path to .toml configuration file [string]
|
|
591
|
+
-h, --help Show help [boolean]
|
|
592
|
+
-v, --version Show version number [boolean]
|
|
577
593
|
|
|
578
594
|
Options:
|
|
579
595
|
--binding The binding of the namespace to write to [string]
|
|
@@ -610,10 +626,9 @@ describe("wrangler", () => {
|
|
|
610
626
|
value The value to write [string]
|
|
611
627
|
|
|
612
628
|
Flags:
|
|
613
|
-
-c, --config
|
|
614
|
-
-h, --help
|
|
615
|
-
-v, --version
|
|
616
|
-
--legacy-env Use legacy environments [boolean]
|
|
629
|
+
-c, --config Path to .toml configuration file [string]
|
|
630
|
+
-h, --help Show help [boolean]
|
|
631
|
+
-v, --version Show version number [boolean]
|
|
617
632
|
|
|
618
633
|
Options:
|
|
619
634
|
--binding The binding of the namespace to write to [string]
|
|
@@ -650,10 +665,9 @@ describe("wrangler", () => {
|
|
|
650
665
|
value The value to write [string]
|
|
651
666
|
|
|
652
667
|
Flags:
|
|
653
|
-
-c, --config
|
|
654
|
-
-h, --help
|
|
655
|
-
-v, --version
|
|
656
|
-
--legacy-env Use legacy environments [boolean]
|
|
668
|
+
-c, --config Path to .toml configuration file [string]
|
|
669
|
+
-h, --help Show help [boolean]
|
|
670
|
+
-v, --version Show version number [boolean]
|
|
657
671
|
|
|
658
672
|
Options:
|
|
659
673
|
--binding The binding of the namespace to write to [string]
|
|
@@ -956,10 +970,9 @@ describe("wrangler", () => {
|
|
|
956
970
|
key The key value to get. [string] [required]
|
|
957
971
|
|
|
958
972
|
Flags:
|
|
959
|
-
-c, --config
|
|
960
|
-
-h, --help
|
|
961
|
-
-v, --version
|
|
962
|
-
--legacy-env Use legacy environments [boolean]
|
|
973
|
+
-c, --config Path to .toml configuration file [string]
|
|
974
|
+
-h, --help Show help [boolean]
|
|
975
|
+
-v, --version Show version number [boolean]
|
|
963
976
|
|
|
964
977
|
Options:
|
|
965
978
|
--binding The name of the namespace to get from [string]
|
|
@@ -991,10 +1004,9 @@ describe("wrangler", () => {
|
|
|
991
1004
|
key The key value to get. [string] [required]
|
|
992
1005
|
|
|
993
1006
|
Flags:
|
|
994
|
-
-c, --config
|
|
995
|
-
-h, --help
|
|
996
|
-
-v, --version
|
|
997
|
-
--legacy-env Use legacy environments [boolean]
|
|
1007
|
+
-c, --config Path to .toml configuration file [string]
|
|
1008
|
+
-h, --help Show help [boolean]
|
|
1009
|
+
-v, --version Show version number [boolean]
|
|
998
1010
|
|
|
999
1011
|
Options:
|
|
1000
1012
|
--binding The name of the namespace to get from [string]
|
|
@@ -1027,10 +1039,9 @@ describe("wrangler", () => {
|
|
|
1027
1039
|
key The key value to get. [string] [required]
|
|
1028
1040
|
|
|
1029
1041
|
Flags:
|
|
1030
|
-
-c, --config
|
|
1031
|
-
-h, --help
|
|
1032
|
-
-v, --version
|
|
1033
|
-
--legacy-env Use legacy environments [boolean]
|
|
1042
|
+
-c, --config Path to .toml configuration file [string]
|
|
1043
|
+
-h, --help Show help [boolean]
|
|
1044
|
+
-v, --version Show version number [boolean]
|
|
1034
1045
|
|
|
1035
1046
|
Options:
|
|
1036
1047
|
--binding The name of the namespace to get from [string]
|
|
@@ -1090,6 +1101,16 @@ describe("wrangler", () => {
|
|
|
1090
1101
|
expect(requests.count).toEqual(1);
|
|
1091
1102
|
});
|
|
1092
1103
|
|
|
1104
|
+
it("should encode the URI properly for deleting a key requests", async () => {
|
|
1105
|
+
const requests = mockDeleteRequest("voyager", "%2FNCC-74656");
|
|
1106
|
+
await runWrangler(`kv:key delete --namespace-id voyager /NCC-74656`);
|
|
1107
|
+
expect(requests.count).toEqual(1);
|
|
1108
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
1109
|
+
`"Deleting the key \\"/NCC-74656\\" on namespace voyager."`
|
|
1110
|
+
);
|
|
1111
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1112
|
+
});
|
|
1113
|
+
|
|
1093
1114
|
it("should delete a key in a namespace specified by binding name", async () => {
|
|
1094
1115
|
writeWranglerConfig();
|
|
1095
1116
|
const requests = mockDeleteRequest("bound-id", "someKey");
|