wrangler 2.0.1 → 2.0.5
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 +23 -3
- 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 +75 -48
- package/src/__tests__/pages.test.ts +12 -14
- package/src/__tests__/publish.test.ts +127 -6
- package/src/__tests__/r2.test.ts +12 -16
- package/src/bundle.ts +1 -1
- package/src/cfetch/internal.ts +3 -0
- 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 +81 -55
- package/src/kv.ts +38 -13
- package/src/pages.tsx +19 -12
- package/src/sites.tsx +10 -10
- package/src/user.tsx +11 -1
- package/wrangler-dist/cli.js +1022 -791
|
@@ -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const { spawn } = require("
|
|
3
|
-
const { join } = require("
|
|
2
|
+
const { spawn } = require("child_process");
|
|
3
|
+
const { join } = require("path");
|
|
4
4
|
const semiver = require("semiver");
|
|
5
5
|
|
|
6
6
|
const MIN_NODE_VERSION = "16.7.0";
|
|
@@ -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.5",
|
|
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]
|
|
@@ -291,10 +288,9 @@ describe("wrangler", () => {
|
|
|
291
288
|
Deletes a given namespace.
|
|
292
289
|
|
|
293
290
|
Flags:
|
|
294
|
-
-c, --config
|
|
295
|
-
-h, --help
|
|
296
|
-
-v, --version
|
|
297
|
-
--legacy-env Use legacy environments [boolean]
|
|
291
|
+
-c, --config Path to .toml configuration file [string]
|
|
292
|
+
-h, --help Show help [boolean]
|
|
293
|
+
-v, --version Show version number [boolean]
|
|
298
294
|
|
|
299
295
|
Options:
|
|
300
296
|
--binding The name of the namespace to delete [string]
|
|
@@ -385,6 +381,21 @@ describe("wrangler", () => {
|
|
|
385
381
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
386
382
|
});
|
|
387
383
|
|
|
384
|
+
it("should encode the key in the api request to put a value", async () => {
|
|
385
|
+
const requests = mockKeyPutRequest("DS9", {
|
|
386
|
+
key: "%2Fmy-key",
|
|
387
|
+
value: "my-value",
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
await runWrangler("kv:key put /my-key my-value --namespace-id DS9");
|
|
391
|
+
|
|
392
|
+
expect(requests.count).toEqual(1);
|
|
393
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
394
|
+
`"Writing the value \\"my-value\\" to key \\"/my-key\\" on namespace DS9."`
|
|
395
|
+
);
|
|
396
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
397
|
+
});
|
|
398
|
+
|
|
388
399
|
it("should put a key in a given namespace specified by binding", async () => {
|
|
389
400
|
writeWranglerConfig();
|
|
390
401
|
const requests = mockKeyPutRequest("bound-id", {
|
|
@@ -490,10 +501,9 @@ describe("wrangler", () => {
|
|
|
490
501
|
value The value to write [string]
|
|
491
502
|
|
|
492
503
|
Flags:
|
|
493
|
-
-c, --config
|
|
494
|
-
-h, --help
|
|
495
|
-
-v, --version
|
|
496
|
-
--legacy-env Use legacy environments [boolean]
|
|
504
|
+
-c, --config Path to .toml configuration file [string]
|
|
505
|
+
-h, --help Show help [boolean]
|
|
506
|
+
-v, --version Show version number [boolean]
|
|
497
507
|
|
|
498
508
|
Options:
|
|
499
509
|
--binding The binding of the namespace to write to [string]
|
|
@@ -530,10 +540,9 @@ describe("wrangler", () => {
|
|
|
530
540
|
value The value to write [string]
|
|
531
541
|
|
|
532
542
|
Flags:
|
|
533
|
-
-c, --config
|
|
534
|
-
-h, --help
|
|
535
|
-
-v, --version
|
|
536
|
-
--legacy-env Use legacy environments [boolean]
|
|
543
|
+
-c, --config Path to .toml configuration file [string]
|
|
544
|
+
-h, --help Show help [boolean]
|
|
545
|
+
-v, --version Show version number [boolean]
|
|
537
546
|
|
|
538
547
|
Options:
|
|
539
548
|
--binding The binding of the namespace to write to [string]
|
|
@@ -570,10 +579,9 @@ describe("wrangler", () => {
|
|
|
570
579
|
value The value to write [string]
|
|
571
580
|
|
|
572
581
|
Flags:
|
|
573
|
-
-c, --config
|
|
574
|
-
-h, --help
|
|
575
|
-
-v, --version
|
|
576
|
-
--legacy-env Use legacy environments [boolean]
|
|
582
|
+
-c, --config Path to .toml configuration file [string]
|
|
583
|
+
-h, --help Show help [boolean]
|
|
584
|
+
-v, --version Show version number [boolean]
|
|
577
585
|
|
|
578
586
|
Options:
|
|
579
587
|
--binding The binding of the namespace to write to [string]
|
|
@@ -610,10 +618,9 @@ describe("wrangler", () => {
|
|
|
610
618
|
value The value to write [string]
|
|
611
619
|
|
|
612
620
|
Flags:
|
|
613
|
-
-c, --config
|
|
614
|
-
-h, --help
|
|
615
|
-
-v, --version
|
|
616
|
-
--legacy-env Use legacy environments [boolean]
|
|
621
|
+
-c, --config Path to .toml configuration file [string]
|
|
622
|
+
-h, --help Show help [boolean]
|
|
623
|
+
-v, --version Show version number [boolean]
|
|
617
624
|
|
|
618
625
|
Options:
|
|
619
626
|
--binding The binding of the namespace to write to [string]
|
|
@@ -650,10 +657,9 @@ describe("wrangler", () => {
|
|
|
650
657
|
value The value to write [string]
|
|
651
658
|
|
|
652
659
|
Flags:
|
|
653
|
-
-c, --config
|
|
654
|
-
-h, --help
|
|
655
|
-
-v, --version
|
|
656
|
-
--legacy-env Use legacy environments [boolean]
|
|
660
|
+
-c, --config Path to .toml configuration file [string]
|
|
661
|
+
-h, --help Show help [boolean]
|
|
662
|
+
-v, --version Show version number [boolean]
|
|
657
663
|
|
|
658
664
|
Options:
|
|
659
665
|
--binding The binding of the namespace to write to [string]
|
|
@@ -937,6 +943,20 @@ describe("wrangler", () => {
|
|
|
937
943
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
938
944
|
});
|
|
939
945
|
|
|
946
|
+
it("should encode the key in the api request to get a value", async () => {
|
|
947
|
+
setMockFetchKVGetValue(
|
|
948
|
+
"some-account-id",
|
|
949
|
+
"some-namespace-id",
|
|
950
|
+
"%2Fmy%2Ckey",
|
|
951
|
+
"my-value"
|
|
952
|
+
);
|
|
953
|
+
await runWrangler(
|
|
954
|
+
"kv:key get /my,key --namespace-id some-namespace-id"
|
|
955
|
+
);
|
|
956
|
+
expect(std.out).toMatchInlineSnapshot(`"my-value"`);
|
|
957
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
958
|
+
});
|
|
959
|
+
|
|
940
960
|
it("should error if no key is provided", async () => {
|
|
941
961
|
await expect(
|
|
942
962
|
runWrangler("kv:key get")
|
|
@@ -956,10 +976,9 @@ describe("wrangler", () => {
|
|
|
956
976
|
key The key value to get. [string] [required]
|
|
957
977
|
|
|
958
978
|
Flags:
|
|
959
|
-
-c, --config
|
|
960
|
-
-h, --help
|
|
961
|
-
-v, --version
|
|
962
|
-
--legacy-env Use legacy environments [boolean]
|
|
979
|
+
-c, --config Path to .toml configuration file [string]
|
|
980
|
+
-h, --help Show help [boolean]
|
|
981
|
+
-v, --version Show version number [boolean]
|
|
963
982
|
|
|
964
983
|
Options:
|
|
965
984
|
--binding The name of the namespace to get from [string]
|
|
@@ -991,10 +1010,9 @@ describe("wrangler", () => {
|
|
|
991
1010
|
key The key value to get. [string] [required]
|
|
992
1011
|
|
|
993
1012
|
Flags:
|
|
994
|
-
-c, --config
|
|
995
|
-
-h, --help
|
|
996
|
-
-v, --version
|
|
997
|
-
--legacy-env Use legacy environments [boolean]
|
|
1013
|
+
-c, --config Path to .toml configuration file [string]
|
|
1014
|
+
-h, --help Show help [boolean]
|
|
1015
|
+
-v, --version Show version number [boolean]
|
|
998
1016
|
|
|
999
1017
|
Options:
|
|
1000
1018
|
--binding The name of the namespace to get from [string]
|
|
@@ -1027,10 +1045,9 @@ describe("wrangler", () => {
|
|
|
1027
1045
|
key The key value to get. [string] [required]
|
|
1028
1046
|
|
|
1029
1047
|
Flags:
|
|
1030
|
-
-c, --config
|
|
1031
|
-
-h, --help
|
|
1032
|
-
-v, --version
|
|
1033
|
-
--legacy-env Use legacy environments [boolean]
|
|
1048
|
+
-c, --config Path to .toml configuration file [string]
|
|
1049
|
+
-h, --help Show help [boolean]
|
|
1050
|
+
-v, --version Show version number [boolean]
|
|
1034
1051
|
|
|
1035
1052
|
Options:
|
|
1036
1053
|
--binding The name of the namespace to get from [string]
|
|
@@ -1090,6 +1107,16 @@ describe("wrangler", () => {
|
|
|
1090
1107
|
expect(requests.count).toEqual(1);
|
|
1091
1108
|
});
|
|
1092
1109
|
|
|
1110
|
+
it("should encode the key in the api request to delete a value", async () => {
|
|
1111
|
+
const requests = mockDeleteRequest("voyager", "%2FNCC-74656");
|
|
1112
|
+
await runWrangler(`kv:key delete --namespace-id voyager /NCC-74656`);
|
|
1113
|
+
expect(requests.count).toEqual(1);
|
|
1114
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
1115
|
+
`"Deleting the key \\"/NCC-74656\\" on namespace voyager."`
|
|
1116
|
+
);
|
|
1117
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1118
|
+
});
|
|
1119
|
+
|
|
1093
1120
|
it("should delete a key in a namespace specified by binding name", async () => {
|
|
1094
1121
|
writeWranglerConfig();
|
|
1095
1122
|
const requests = mockDeleteRequest("bound-id", "someKey");
|