wrangler 0.0.0-e22f9d7 → 0.0.0-e2a26a0

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.
Files changed (54) hide show
  1. package/bin/wrangler.js +2 -2
  2. package/package.json +15 -10
  3. package/pages/functions/buildWorker.ts +1 -1
  4. package/pages/functions/filepath-routing.test.ts +21 -13
  5. package/pages/functions/filepath-routing.ts +38 -28
  6. package/pages/functions/routes.ts +8 -6
  7. package/pages/functions/template-worker.ts +16 -24
  8. package/src/__tests__/dev.test.tsx +7 -3
  9. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  10. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  11. package/src/__tests__/helpers/mock-account-id.ts +30 -0
  12. package/src/__tests__/helpers/mock-bin.ts +33 -0
  13. package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +49 -13
  14. package/src/__tests__/helpers/mock-console.ts +56 -0
  15. package/src/__tests__/{mock-dialogs.ts → helpers/mock-dialogs.ts} +1 -1
  16. package/src/__tests__/helpers/mock-kv.ts +40 -0
  17. package/src/__tests__/helpers/mock-user.ts +27 -0
  18. package/src/__tests__/helpers/run-in-tmp.ts +29 -0
  19. package/src/__tests__/helpers/run-wrangler.ts +14 -0
  20. package/src/__tests__/index.test.ts +312 -56
  21. package/src/__tests__/jest.setup.ts +17 -2
  22. package/src/__tests__/kv.test.ts +344 -316
  23. package/src/__tests__/logout.test.ts +50 -0
  24. package/src/__tests__/package-manager.test.ts +206 -0
  25. package/src/__tests__/publish.test.ts +1222 -0
  26. package/src/__tests__/secret.test.ts +210 -0
  27. package/src/__tests__/whoami.test.tsx +86 -0
  28. package/src/api/form_data.ts +10 -7
  29. package/src/api/preview.ts +2 -2
  30. package/src/api/worker.ts +3 -3
  31. package/src/cfetch/index.ts +14 -14
  32. package/src/cfetch/internal.ts +40 -8
  33. package/src/config.ts +162 -8
  34. package/src/dev.tsx +103 -53
  35. package/src/dialogs.tsx +2 -2
  36. package/src/index.tsx +438 -311
  37. package/src/inspect.ts +80 -23
  38. package/src/kv.tsx +9 -1
  39. package/src/module-collection.ts +5 -6
  40. package/src/package-manager.ts +120 -0
  41. package/src/pages.tsx +41 -26
  42. package/src/paths.ts +26 -0
  43. package/src/proxy.ts +78 -10
  44. package/src/publish.ts +98 -52
  45. package/src/sites.tsx +175 -53
  46. package/src/user.tsx +51 -59
  47. package/src/whoami.tsx +69 -0
  48. package/templates/new-worker.js +15 -0
  49. package/templates/new-worker.ts +15 -0
  50. package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
  51. package/wrangler-dist/cli.js +111479 -110187
  52. package/wrangler-dist/cli.js.map +3 -3
  53. package/src/__tests__/run-in-tmp.ts +0 -19
  54. package/src/__tests__/run-wrangler.ts +0 -32
@@ -1,20 +1,22 @@
1
- import { writeFileSync } from "fs";
1
+ import { writeFileSync } from "node:fs";
2
+ import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
2
3
  import {
3
4
  setMockResponse,
4
- setMockRawResponse,
5
5
  unsetAllMocks,
6
- createFetchResult,
7
- } from "./mock-cfetch";
8
- import { runWrangler } from "./run-wrangler";
9
- import { runInTempDir } from "./run-in-tmp";
10
-
11
- interface KVNamespaceInfo {
12
- title: string;
13
- id: string;
14
- }
6
+ unsetMockFetchKVGetValues,
7
+ setMockFetchKVGetValue,
8
+ } from "./helpers/mock-cfetch";
9
+ import { mockConsoleMethods } from "./helpers/mock-console";
10
+ import { mockKeyListRequest } from "./helpers/mock-kv";
11
+ import { runInTempDir } from "./helpers/run-in-tmp";
12
+ import { runWrangler } from "./helpers/run-wrangler";
13
+ import type { KVNamespaceInfo } from "../kv";
15
14
 
16
15
  describe("wrangler", () => {
16
+ mockAccountId();
17
+ mockApiToken();
17
18
  runInTempDir();
19
+ const std = mockConsoleMethods();
18
20
 
19
21
  afterEach(() => {
20
22
  unsetAllMocks();
@@ -36,11 +38,13 @@ describe("wrangler", () => {
36
38
  }
37
39
 
38
40
  it("should error if no namespace is given", async () => {
39
- const { error, stdout, stderr } = await runWrangler(
40
- "kv:namespace create"
41
+ await expect(
42
+ runWrangler("kv:namespace create")
43
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
44
+ `"Not enough non-option arguments: got 0, need at least 1"`
41
45
  );
42
- expect(stdout).toMatchInlineSnapshot(`""`);
43
- expect(stderr).toMatchInlineSnapshot(`
46
+ expect(std.out).toMatchInlineSnapshot(`""`);
47
+ expect(std.err).toMatchInlineSnapshot(`
44
48
  "wrangler kv:namespace create <namespace>
45
49
 
46
50
  Create a new namespace
@@ -60,17 +64,16 @@ describe("wrangler", () => {
60
64
 
61
65
  Not enough non-option arguments: got 0, need at least 1"
62
66
  `);
63
- expect(error).toMatchInlineSnapshot(
64
- `[Error: Not enough non-option arguments: got 0, need at least 1]`
65
- );
66
67
  });
67
68
 
68
69
  it("should error if the namespace to create contains spaces", async () => {
69
- const { error, stdout, stderr } = await runWrangler(
70
- "kv:namespace create abc def ghi"
70
+ await expect(
71
+ runWrangler("kv:namespace create abc def ghi")
72
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
73
+ `"Unexpected additional positional arguments \\"def ghi\\"."`
71
74
  );
72
- expect(stdout).toMatchInlineSnapshot(`""`);
73
- expect(stderr).toMatchInlineSnapshot(`
75
+ expect(std.out).toMatchInlineSnapshot(`""`);
76
+ expect(std.err).toMatchInlineSnapshot(`
74
77
  "wrangler kv:namespace create <namespace>
75
78
 
76
79
  Create a new namespace
@@ -90,17 +93,17 @@ describe("wrangler", () => {
90
93
 
91
94
  Unexpected additional positional arguments \\"def ghi\\"."
92
95
  `);
93
- expect(error).toMatchInlineSnapshot(
94
- `[Error: Unexpected additional positional arguments "def ghi".]`
95
- );
96
96
  });
97
97
 
98
98
  it("should error if the namespace to create is not valid", async () => {
99
- const { error, stdout, stderr } = await runWrangler(
100
- "kv:namespace create abc-def"
99
+ await expect(
100
+ runWrangler("kv:namespace create abc-def")
101
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
102
+ `"The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number."`
101
103
  );
102
- expect(stdout).toMatchInlineSnapshot(`""`);
103
- expect(stderr).toMatchInlineSnapshot(`
104
+
105
+ expect(std.out).toMatchInlineSnapshot(`""`);
106
+ expect(std.err).toMatchInlineSnapshot(`
104
107
  "wrangler kv:namespace create <namespace>
105
108
 
106
109
  Create a new namespace
@@ -120,17 +123,12 @@ describe("wrangler", () => {
120
123
 
121
124
  The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number."
122
125
  `);
123
- expect(error).toMatchInlineSnapshot(
124
- `[Error: The namespace binding name "abc-def" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number.]`
125
- );
126
126
  });
127
127
 
128
128
  it("should create a namespace", async () => {
129
129
  mockCreateRequest("worker-UnitTestNamespace");
130
- const { stdout } = await runWrangler(
131
- "kv:namespace create UnitTestNamespace"
132
- );
133
- expect(stdout).toMatchInlineSnapshot(`
130
+ await runWrangler("kv:namespace create UnitTestNamespace");
131
+ expect(std.out).toMatchInlineSnapshot(`
134
132
  "🌀 Creating namespace with title \\"worker-UnitTestNamespace\\"
135
133
  ✨ Success!
136
134
  Add the following to your configuration file in your kv_namespaces array:
@@ -140,10 +138,8 @@ describe("wrangler", () => {
140
138
 
141
139
  it("should create a preview namespace if configured to do so", async () => {
142
140
  mockCreateRequest("worker-UnitTestNamespace_preview");
143
- const { stdout } = await runWrangler(
144
- "kv:namespace create UnitTestNamespace --preview"
145
- );
146
- expect(stdout).toMatchInlineSnapshot(`
141
+ await runWrangler("kv:namespace create UnitTestNamespace --preview");
142
+ expect(std.out).toMatchInlineSnapshot(`
147
143
  "🌀 Creating namespace with title \\"worker-UnitTestNamespace_preview\\"
148
144
  ✨ Success!
149
145
  Add the following to your configuration file in your kv_namespaces array:
@@ -154,10 +150,8 @@ describe("wrangler", () => {
154
150
  it("should create a namespace using configured worker name", async () => {
155
151
  writeFileSync("./wrangler.toml", 'name = "otherWorker"', "utf-8");
156
152
  mockCreateRequest("otherWorker-UnitTestNamespace");
157
- const { stdout } = await runWrangler(
158
- "kv:namespace create UnitTestNamespace"
159
- );
160
- expect(stdout).toMatchInlineSnapshot(`
153
+ await runWrangler("kv:namespace create UnitTestNamespace");
154
+ expect(std.out).toMatchInlineSnapshot(`
161
155
  "🌀 Creating namespace with title \\"otherWorker-UnitTestNamespace\\"
162
156
  ✨ Success!
163
157
  Add the following to your configuration file in your kv_namespaces array:
@@ -167,10 +161,10 @@ describe("wrangler", () => {
167
161
 
168
162
  it("should create a namespace in an environment if configured to do so", async () => {
169
163
  mockCreateRequest("worker-customEnv-UnitTestNamespace");
170
- const { stdout } = await runWrangler(
164
+ await runWrangler(
171
165
  "kv:namespace create UnitTestNamespace --env customEnv"
172
166
  );
173
- expect(stdout).toMatchInlineSnapshot(`
167
+ expect(std.out).toMatchInlineSnapshot(`
174
168
  "🌀 Creating namespace with title \\"worker-customEnv-UnitTestNamespace\\"
175
169
  ✨ Success!
176
170
  Add the following to your configuration file in your kv_namespaces array under [env.customEnv]:
@@ -206,12 +200,10 @@ describe("wrangler", () => {
206
200
  { title: "title-2", id: "id-2" },
207
201
  ];
208
202
  mockListRequest(kvNamespaces);
209
- const { error, stdout, stderr } = await runWrangler(
210
- "kv:namespace list"
211
- );
212
- expect(error).toMatchInlineSnapshot(`undefined`);
213
- expect(stderr).toMatchInlineSnapshot(`""`);
214
- const namespaces = JSON.parse(stdout);
203
+ await runWrangler("kv:namespace list");
204
+
205
+ expect(std.err).toMatchInlineSnapshot(`""`);
206
+ const namespaces = JSON.parse(std.out);
215
207
  expect(namespaces).toEqual(kvNamespaces);
216
208
  });
217
209
 
@@ -222,8 +214,8 @@ describe("wrangler", () => {
222
214
  kvNamespaces.push({ title: "title-" + i, id: "id-" + i });
223
215
  }
224
216
  const requests = mockListRequest(kvNamespaces);
225
- const { stdout } = await runWrangler("kv:namespace list");
226
- const namespaces = JSON.parse(stdout);
217
+ await runWrangler("kv:namespace list");
218
+ const namespaces = JSON.parse(std.out);
227
219
  expect(namespaces).toEqual(kvNamespaces);
228
220
  expect(requests.count).toEqual(6);
229
221
  });
@@ -273,10 +265,12 @@ describe("wrangler", () => {
273
265
 
274
266
  it("should error if a given binding name is not in the configured kv namespaces", async () => {
275
267
  writeWranglerConfig();
276
- const { stderr } = await runWrangler(
277
- `kv:namespace delete --binding otherBinding`
278
- );
279
- expect(stderr).toMatchInlineSnapshot(`
268
+ await expect(runWrangler("kv:namespace delete --binding otherBinding"))
269
+ .rejects.toThrowErrorMatchingInlineSnapshot(`
270
+ "Not able to delete namespace.
271
+ A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."
272
+ `);
273
+ expect(std.err).toMatchInlineSnapshot(`
280
274
  "wrangler kv:namespace delete
281
275
 
282
276
  Deletes a given namespace.
@@ -301,12 +295,12 @@ describe("wrangler", () => {
301
295
  it("should delete a namespace specified by binding name in a given environment", async () => {
302
296
  writeWranglerConfig();
303
297
  const requests = mockDeleteRequest("env-bound-id");
304
- const { stdout, stderr, error } = await runWrangler(
305
- `kv:namespace delete --binding someBinding --env some-environment --preview false`
298
+ await runWrangler(
299
+ "kv:namespace delete --binding someBinding --env some-environment --preview false"
306
300
  );
307
- expect(stdout).toMatchInlineSnapshot(`""`);
308
- expect(stderr).toMatchInlineSnapshot(`""`);
309
- expect(error).toMatchInlineSnapshot(`undefined`);
301
+
302
+ expect(std.out).toMatchInlineSnapshot(`""`);
303
+ expect(std.err).toMatchInlineSnapshot(`""`);
310
304
  expect(requests.count).toEqual(1);
311
305
  });
312
306
 
@@ -362,28 +356,29 @@ describe("wrangler", () => {
362
356
  "my-key",
363
357
  "my-value"
364
358
  );
365
- const { error, stderr, stdout } = await runWrangler(
359
+
360
+ await runWrangler(
366
361
  "kv:key put my-key my-value --namespace-id some-namespace-id"
367
362
  );
363
+
368
364
  expect(requests.count).toEqual(1);
369
- expect(stdout).toMatchInlineSnapshot(
365
+ expect(std.out).toMatchInlineSnapshot(
370
366
  `"writing the value \\"my-value\\" to key \\"my-key\\" on namespace some-namespace-id"`
371
367
  );
372
- expect(stderr).toMatchInlineSnapshot(`""`);
373
- expect(error).toMatchInlineSnapshot(`undefined`);
368
+ expect(std.err).toMatchInlineSnapshot(`""`);
374
369
  });
375
370
 
376
371
  it("should put a key in a given namespace specified by binding", async () => {
377
372
  writeWranglerConfig();
378
373
  const requests = mockKeyPutRequest("bound-id", "my-key", "my-value");
379
- const { error, stderr, stdout } = await runWrangler(
374
+ await runWrangler(
380
375
  "kv:key put my-key my-value --binding someBinding --preview false"
381
376
  );
382
- expect(stdout).toMatchInlineSnapshot(
377
+
378
+ expect(std.out).toMatchInlineSnapshot(
383
379
  `"writing the value \\"my-value\\" to key \\"my-key\\" on namespace bound-id"`
384
380
  );
385
- expect(stderr).toMatchInlineSnapshot(`""`);
386
- expect(error).toMatchInlineSnapshot(`undefined`);
381
+ expect(std.err).toMatchInlineSnapshot(`""`);
387
382
  expect(requests.count).toEqual(1);
388
383
  });
389
384
 
@@ -394,14 +389,15 @@ describe("wrangler", () => {
394
389
  "my-key",
395
390
  "my-value"
396
391
  );
397
- const { error, stderr, stdout } = await runWrangler(
392
+
393
+ await runWrangler(
398
394
  "kv:key put my-key my-value --binding someBinding --preview"
399
395
  );
400
- expect(stdout).toMatchInlineSnapshot(
396
+
397
+ expect(std.out).toMatchInlineSnapshot(
401
398
  `"writing the value \\"my-value\\" to key \\"my-key\\" on namespace preview-bound-id"`
402
399
  );
403
- expect(stderr).toMatchInlineSnapshot(`""`);
404
- expect(error).toMatchInlineSnapshot(`undefined`);
400
+ expect(std.err).toMatchInlineSnapshot(`""`);
405
401
  expect(requests.count).toEqual(1);
406
402
  });
407
403
 
@@ -413,15 +409,14 @@ describe("wrangler", () => {
413
409
  10,
414
410
  20
415
411
  );
416
- const { error, stderr, stdout } = await runWrangler(
412
+ await runWrangler(
417
413
  "kv:key put my-key my-value --namespace-id some-namespace-id --expiration 10 --ttl 20"
418
414
  );
419
415
  expect(requests.count).toEqual(1);
420
- expect(stdout).toMatchInlineSnapshot(
416
+ expect(std.out).toMatchInlineSnapshot(
421
417
  `"writing the value \\"my-value\\" to key \\"my-key\\" on namespace some-namespace-id"`
422
418
  );
423
- expect(stderr).toMatchInlineSnapshot(`""`);
424
- expect(error).toMatchInlineSnapshot(`undefined`);
419
+ expect(std.err).toMatchInlineSnapshot(`""`);
425
420
  });
426
421
 
427
422
  it("should put a key to the specified environment in a given namespace", async () => {
@@ -431,14 +426,13 @@ describe("wrangler", () => {
431
426
  "my-key",
432
427
  "my-value"
433
428
  );
434
- const { error, stderr, stdout } = await runWrangler(
429
+ await runWrangler(
435
430
  "kv:key put my-key my-value --binding someBinding --env some-environment --preview false"
436
431
  );
437
- expect(stdout).toMatchInlineSnapshot(
432
+ expect(std.out).toMatchInlineSnapshot(
438
433
  `"writing the value \\"my-value\\" to key \\"my-key\\" on namespace env-bound-id"`
439
434
  );
440
- expect(stderr).toMatchInlineSnapshot(`""`);
441
- expect(error).toMatchInlineSnapshot(`undefined`);
435
+ expect(std.err).toMatchInlineSnapshot(`""`);
442
436
  expect(requests.count).toEqual(1);
443
437
  });
444
438
 
@@ -449,22 +443,25 @@ describe("wrangler", () => {
449
443
  "my-key",
450
444
  "file-contents"
451
445
  );
452
- const { error, stderr, stdout } = await runWrangler(
446
+ await runWrangler(
453
447
  "kv:key put my-key --namespace-id some-namespace-id --path foo.txt"
454
448
  );
455
- expect(stdout).toMatchInlineSnapshot(
449
+ expect(std.out).toMatchInlineSnapshot(
456
450
  `"writing the contents of foo.txt to the key \\"my-key\\" on namespace some-namespace-id"`
457
451
  );
458
- expect(stderr).toMatchInlineSnapshot(`""`);
459
- expect(error).toMatchInlineSnapshot(`undefined`);
452
+ expect(std.err).toMatchInlineSnapshot(`""`);
460
453
  expect(requests.count).toEqual(1);
461
454
  });
462
455
 
463
456
  it("should error if no key is provided", async () => {
464
- const { error, stdout, stderr } = await runWrangler("kv:key put");
457
+ await expect(
458
+ runWrangler("kv:key put")
459
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
460
+ `"Not enough non-option arguments: got 0, need at least 1"`
461
+ );
465
462
 
466
- expect(stdout).toMatchInlineSnapshot(`""`);
467
- expect(stderr).toMatchInlineSnapshot(`
463
+ expect(std.out).toMatchInlineSnapshot(`""`);
464
+ expect(std.err).toMatchInlineSnapshot(`
468
465
  "wrangler kv:key put <key> [value]
469
466
 
470
467
  Writes a single key/value pair to the given namespace.
@@ -490,18 +487,17 @@ describe("wrangler", () => {
490
487
 
491
488
  Not enough non-option arguments: got 0, need at least 1"
492
489
  `);
493
- expect(error).toMatchInlineSnapshot(
494
- `[Error: Not enough non-option arguments: got 0, need at least 1]`
495
- );
496
490
  });
497
491
 
498
492
  it("should error if no binding nor namespace is provided", async () => {
499
- const { error, stdout, stderr } = await runWrangler(
500
- "kv:key put foo bar"
493
+ await expect(
494
+ runWrangler("kv:key put foo bar")
495
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
496
+ `"Exactly one of the arguments binding and namespace-id is required"`
501
497
  );
502
498
 
503
- expect(stdout).toMatchInlineSnapshot(`""`);
504
- expect(stderr).toMatchInlineSnapshot(`
499
+ expect(std.out).toMatchInlineSnapshot(`""`);
500
+ expect(std.err).toMatchInlineSnapshot(`
505
501
  "wrangler kv:key put <key> [value]
506
502
 
507
503
  Writes a single key/value pair to the given namespace.
@@ -527,18 +523,17 @@ describe("wrangler", () => {
527
523
 
528
524
  Exactly one of the arguments binding and namespace-id is required"
529
525
  `);
530
- expect(error).toMatchInlineSnapshot(
531
- `[Error: Exactly one of the arguments binding and namespace-id is required]`
532
- );
533
526
  });
534
527
 
535
528
  it("should error if both binding and namespace is provided", async () => {
536
- const { error, stdout, stderr } = await runWrangler(
537
- "kv:key put foo bar --binding x --namespace-id y"
529
+ await expect(
530
+ runWrangler("kv:key put foo bar --binding x --namespace-id y")
531
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
532
+ `"Arguments binding and namespace-id are mutually exclusive"`
538
533
  );
539
534
 
540
- expect(stdout).toMatchInlineSnapshot(`""`);
541
- expect(stderr).toMatchInlineSnapshot(`
535
+ expect(std.out).toMatchInlineSnapshot(`""`);
536
+ expect(std.err).toMatchInlineSnapshot(`
542
537
  "wrangler kv:key put <key> [value]
543
538
 
544
539
  Writes a single key/value pair to the given namespace.
@@ -564,18 +559,17 @@ describe("wrangler", () => {
564
559
 
565
560
  Arguments binding and namespace-id are mutually exclusive"
566
561
  `);
567
- expect(error).toMatchInlineSnapshot(
568
- `[Error: Arguments binding and namespace-id are mutually exclusive]`
569
- );
570
562
  });
571
563
 
572
564
  it("should error if no value nor path is provided", async () => {
573
- const { error, stdout, stderr } = await runWrangler(
574
- "kv:key put key --namespace-id 12345"
565
+ await expect(
566
+ runWrangler("kv:key put key --namespace-id 12345")
567
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
568
+ `"Exactly one of the arguments value and path is required"`
575
569
  );
576
570
 
577
- expect(stdout).toMatchInlineSnapshot(`""`);
578
- expect(stderr).toMatchInlineSnapshot(`
571
+ expect(std.out).toMatchInlineSnapshot(`""`);
572
+ expect(std.err).toMatchInlineSnapshot(`
579
573
  "wrangler kv:key put <key> [value]
580
574
 
581
575
  Writes a single key/value pair to the given namespace.
@@ -601,18 +595,17 @@ describe("wrangler", () => {
601
595
 
602
596
  Exactly one of the arguments value and path is required"
603
597
  `);
604
- expect(error).toMatchInlineSnapshot(
605
- `[Error: Exactly one of the arguments value and path is required]`
606
- );
607
598
  });
608
599
 
609
600
  it("should error if both value and path is provided", async () => {
610
- const { error, stdout, stderr } = await runWrangler(
611
- "kv:key put key value --path xyz --namespace-id 12345"
601
+ await expect(
602
+ runWrangler("kv:key put key value --path xyz --namespace-id 12345")
603
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
604
+ `"Arguments value and path are mutually exclusive"`
612
605
  );
613
606
 
614
- expect(stdout).toMatchInlineSnapshot(`""`);
615
- expect(stderr).toMatchInlineSnapshot(`
607
+ expect(std.out).toMatchInlineSnapshot(`""`);
608
+ expect(std.err).toMatchInlineSnapshot(`
616
609
  "wrangler kv:key put <key> [value]
617
610
 
618
611
  Writes a single key/value pair to the given namespace.
@@ -638,23 +631,23 @@ describe("wrangler", () => {
638
631
 
639
632
  Arguments value and path are mutually exclusive"
640
633
  `);
641
- expect(error).toMatchInlineSnapshot(
642
- `[Error: Arguments value and path are mutually exclusive]`
643
- );
644
634
  });
645
635
 
646
636
  it("should error if a given binding name is not in the configured kv namespaces", async () => {
647
637
  writeWranglerConfig();
648
- const { error, stdout, stderr } = await runWrangler(
649
- `kv:key put key value --binding otherBinding`
650
- );
651
- expect(stdout).toMatchInlineSnapshot(`""`);
652
- expect(stderr).toMatchInlineSnapshot(
638
+ await expect(
639
+ runWrangler("kv:key put key value --binding otherBinding")
640
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
653
641
  `"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
654
642
  );
655
- expect(error).toMatchInlineSnapshot(
656
- `[Error: A namespace with binding name "otherBinding" was not found in the configured "kv_namespaces".]`
657
- );
643
+
644
+ expect(std.out).toMatchInlineSnapshot(`""`);
645
+ expect(std.err).toMatchInlineSnapshot(`
646
+ "A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
647
+
648
+ %s
649
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
650
+ `);
658
651
  });
659
652
 
660
653
  it("should error if a given binding has both preview and non-preview and --preview is not specified", async () => {
@@ -664,64 +657,46 @@ describe("wrangler", () => {
664
657
  "my-key",
665
658
  "my-value"
666
659
  );
667
- const { error, stderr, stdout } = await runWrangler(
668
- "kv:key put my-key my-value --binding someBinding"
669
- );
670
- expect(stdout).toMatchInlineSnapshot(`""`);
671
- expect(stderr).toMatchInlineSnapshot(
660
+ await expect(
661
+ runWrangler("kv:key put my-key my-value --binding someBinding")
662
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
672
663
  `"someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace."`
673
664
  );
674
- expect(error).toMatchInlineSnapshot(
675
- `[Error: someBinding has both a namespace ID and a preview ID. Specify "--preview" or "--preview false" to avoid writing data to the wrong namespace.]`
676
- );
665
+ expect(std.out).toMatchInlineSnapshot(`""`);
666
+ expect(std.err).toMatchInlineSnapshot(`
667
+ "someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace.
668
+
669
+ %s
670
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
671
+ `);
677
672
  expect(requests.count).toEqual(0);
678
673
  });
679
674
  });
680
675
 
681
676
  describe("list", () => {
682
- function mockKeyListRequest(
683
- expectedNamespaceId: string,
684
- expectedKeys: string[],
685
- keysPerRequest = 1000
686
- ) {
687
- const requests = { count: 0 };
688
- setMockRawResponse(
689
- "/accounts/:accountId/storage/kv/namespaces/:namespaceId/keys",
690
- ([_url, accountId, namespaceId], _init, query) => {
691
- requests.count++;
692
- expect(accountId).toEqual("some-account-id");
693
- expect(namespaceId).toEqual(expectedNamespaceId);
694
- if (expectedKeys.length <= keysPerRequest) {
695
- return createFetchResult(expectedKeys);
696
- } else {
697
- const start = parseInt(query.get("cursor") ?? "0") || 0;
698
- const end = start + keysPerRequest;
699
- const cursor = end < expectedKeys.length ? end : undefined;
700
- return createFetchResult(
701
- expectedKeys.slice(start, end),
702
- true,
703
- [],
704
- [],
705
- { cursor }
706
- );
707
- }
708
- }
709
- );
710
- return requests;
711
- }
712
-
713
677
  it("should list the keys of a namespace specified by namespace-id", async () => {
714
678
  const keys = ["key-1", "key-2", "key-3"];
715
679
  mockKeyListRequest("some-namespace-id", keys);
716
- const { error, stdout, stderr } = await runWrangler(
717
- "kv:key list --namespace-id some-namespace-id"
718
- );
719
- expect(error).toMatchInlineSnapshot(`undefined`);
720
- expect(stderr).toMatchInlineSnapshot(`""`);
721
- expect(stdout).toMatchInlineSnapshot(`
722
- "key-1
723
- key-2
724
- key-3"
680
+ await runWrangler("kv:key list --namespace-id some-namespace-id");
681
+ expect(std.err).toMatchInlineSnapshot(`""`);
682
+ expect(std.out).toMatchInlineSnapshot(`
683
+ "[
684
+ {
685
+ \\"name\\": \\"key-1\\",
686
+ \\"expiration\\": 123456789,
687
+ \\"metadata\\": {}
688
+ },
689
+ {
690
+ \\"name\\": \\"key-2\\",
691
+ \\"expiration\\": 123456789,
692
+ \\"metadata\\": {}
693
+ },
694
+ {
695
+ \\"name\\": \\"key-3\\",
696
+ \\"expiration\\": 123456789,
697
+ \\"metadata\\": {}
698
+ }
699
+ ]"
725
700
  `);
726
701
  });
727
702
 
@@ -729,15 +704,27 @@ describe("wrangler", () => {
729
704
  writeWranglerConfig();
730
705
  const keys = ["key-1", "key-2", "key-3"];
731
706
  mockKeyListRequest("bound-id", keys);
732
- const { error, stdout, stderr } = await runWrangler(
733
- "kv:key list --binding someBinding"
734
- );
735
- expect(error).toMatchInlineSnapshot(`undefined`);
736
- expect(stderr).toMatchInlineSnapshot(`""`);
737
- expect(stdout).toMatchInlineSnapshot(`
738
- "key-1
739
- key-2
740
- key-3"
707
+
708
+ await runWrangler("kv:key list --binding someBinding");
709
+ expect(std.err).toMatchInlineSnapshot(`""`);
710
+ expect(std.out).toMatchInlineSnapshot(`
711
+ "[
712
+ {
713
+ \\"name\\": \\"key-1\\",
714
+ \\"expiration\\": 123456789,
715
+ \\"metadata\\": {}
716
+ },
717
+ {
718
+ \\"name\\": \\"key-2\\",
719
+ \\"expiration\\": 123456789,
720
+ \\"metadata\\": {}
721
+ },
722
+ {
723
+ \\"name\\": \\"key-3\\",
724
+ \\"expiration\\": 123456789,
725
+ \\"metadata\\": {}
726
+ }
727
+ ]"
741
728
  `);
742
729
  });
743
730
 
@@ -745,15 +732,26 @@ describe("wrangler", () => {
745
732
  writeWranglerConfig();
746
733
  const keys = ["key-1", "key-2", "key-3"];
747
734
  mockKeyListRequest("preview-bound-id", keys);
748
- const { error, stdout, stderr } = await runWrangler(
749
- "kv:key list --binding someBinding --preview"
750
- );
751
- expect(error).toMatchInlineSnapshot(`undefined`);
752
- expect(stderr).toMatchInlineSnapshot(`""`);
753
- expect(stdout).toMatchInlineSnapshot(`
754
- "key-1
755
- key-2
756
- key-3"
735
+ await runWrangler("kv:key list --binding someBinding --preview");
736
+ expect(std.err).toMatchInlineSnapshot(`""`);
737
+ expect(std.out).toMatchInlineSnapshot(`
738
+ "[
739
+ {
740
+ \\"name\\": \\"key-1\\",
741
+ \\"expiration\\": 123456789,
742
+ \\"metadata\\": {}
743
+ },
744
+ {
745
+ \\"name\\": \\"key-2\\",
746
+ \\"expiration\\": 123456789,
747
+ \\"metadata\\": {}
748
+ },
749
+ {
750
+ \\"name\\": \\"key-3\\",
751
+ \\"expiration\\": 123456789,
752
+ \\"metadata\\": {}
753
+ }
754
+ ]"
757
755
  `);
758
756
  });
759
757
 
@@ -761,15 +759,28 @@ describe("wrangler", () => {
761
759
  writeWranglerConfig();
762
760
  const keys = ["key-1", "key-2", "key-3"];
763
761
  mockKeyListRequest("env-bound-id", keys);
764
- const { error, stdout, stderr } = await runWrangler(
762
+ await runWrangler(
765
763
  "kv:key list --binding someBinding --env some-environment"
766
764
  );
767
- expect(error).toMatchInlineSnapshot(`undefined`);
768
- expect(stderr).toMatchInlineSnapshot(`""`);
769
- expect(stdout).toMatchInlineSnapshot(`
770
- "key-1
771
- key-2
772
- key-3"
765
+ expect(std.err).toMatchInlineSnapshot(`""`);
766
+ expect(std.out).toMatchInlineSnapshot(`
767
+ "[
768
+ {
769
+ \\"name\\": \\"key-1\\",
770
+ \\"expiration\\": 123456789,
771
+ \\"metadata\\": {}
772
+ },
773
+ {
774
+ \\"name\\": \\"key-2\\",
775
+ \\"expiration\\": 123456789,
776
+ \\"metadata\\": {}
777
+ },
778
+ {
779
+ \\"name\\": \\"key-3\\",
780
+ \\"expiration\\": 123456789,
781
+ \\"metadata\\": {}
782
+ }
783
+ ]"
773
784
  `);
774
785
  });
775
786
 
@@ -777,134 +788,148 @@ describe("wrangler", () => {
777
788
  writeWranglerConfig();
778
789
  const keys = ["key-1", "key-2", "key-3"];
779
790
  mockKeyListRequest("preview-env-bound-id", keys);
780
- const { error, stdout, stderr } = await runWrangler(
791
+ await runWrangler(
781
792
  "kv:key list --binding someBinding --preview --env some-environment"
782
793
  );
783
- expect(error).toMatchInlineSnapshot(`undefined`);
784
- expect(stderr).toMatchInlineSnapshot(`""`);
785
- expect(stdout).toMatchInlineSnapshot(`
786
- "key-1
787
- key-2
788
- key-3"
794
+ expect(std.err).toMatchInlineSnapshot(`""`);
795
+ expect(std.out).toMatchInlineSnapshot(`
796
+ "[
797
+ {
798
+ \\"name\\": \\"key-1\\",
799
+ \\"expiration\\": 123456789,
800
+ \\"metadata\\": {}
801
+ },
802
+ {
803
+ \\"name\\": \\"key-2\\",
804
+ \\"expiration\\": 123456789,
805
+ \\"metadata\\": {}
806
+ },
807
+ {
808
+ \\"name\\": \\"key-3\\",
809
+ \\"expiration\\": 123456789,
810
+ \\"metadata\\": {}
811
+ }
812
+ ]"
789
813
  `);
790
814
  });
791
815
 
792
- it("should make multiple requests for paginated results", async () => {
793
- // Create a lot of mock keys, so that the fetch requests will be paginated
794
- const keys: string[] = [];
795
- for (let i = 0; i < 550; i++) {
796
- keys.push("key-" + i);
797
- }
798
- // Ask for the keys in pages of size 100.
799
- const requests = mockKeyListRequest("some-namespace-id", keys, 100);
800
- const { stdout, stderr, error } = await runWrangler(
801
- "kv:key list --namespace-id some-namespace-id --limit 100"
802
- );
803
- expect(error).toMatchInlineSnapshot(`undefined`);
804
- expect(stderr).toMatchInlineSnapshot(`""`);
805
- expect(stdout).toEqual(keys.join("\n"));
806
- expect(requests.count).toEqual(6);
807
- });
816
+ // We'll run the next test with variations on the cursor
817
+ // that's returned on cloudflare's API after all results
818
+ // have been drained.
819
+ for (const blankCursorValue of [undefined, null, ""] as [
820
+ undefined,
821
+ null,
822
+ ""
823
+ ]) {
824
+ describe(`cursor - ${blankCursorValue}`, () => {
825
+ it("should make multiple requests for paginated results", async () => {
826
+ // Create a lot of mock keys, so that the fetch requests will be paginated
827
+ const keys: string[] = [];
828
+ for (let i = 0; i < 550; i++) {
829
+ keys.push("key-" + i);
830
+ }
831
+ // Ask for the keys in pages of size 100.
832
+ const requests = mockKeyListRequest(
833
+ "some-namespace-id",
834
+ keys,
835
+ 100,
836
+ blankCursorValue
837
+ );
838
+ await runWrangler(
839
+ "kv:key list --namespace-id some-namespace-id --limit 100"
840
+ );
841
+ expect(std.err).toMatchInlineSnapshot(`""`);
842
+ expect(JSON.parse(std.out).map((k) => k.name)).toEqual(keys);
843
+ expect(requests.count).toEqual(6);
844
+ });
845
+ });
846
+ }
808
847
 
809
848
  it("should error if a given binding name is not in the configured kv namespaces", async () => {
810
849
  writeWranglerConfig();
811
- const { error, stdout, stderr } = await runWrangler(
812
- "kv:key list --binding otherBinding"
813
- );
814
- expect(error).toMatchInlineSnapshot(
815
- `[Error: A namespace with binding name "otherBinding" was not found in the configured "kv_namespaces".]`
816
- );
817
- expect(stderr).toMatchInlineSnapshot(
850
+ await expect(
851
+ runWrangler("kv:key list --binding otherBinding")
852
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
818
853
  `"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
819
854
  );
820
- expect(stdout).toMatchInlineSnapshot(`""`);
855
+ expect(std.err).toMatchInlineSnapshot(`
856
+ "A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
857
+
858
+ %s
859
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
860
+ `);
861
+ expect(std.out).toMatchInlineSnapshot(`""`);
821
862
  });
822
863
  });
823
864
 
824
865
  describe("get", () => {
825
- function mockKeyGetRequest(
826
- expectedNamespaceId: string,
827
- expectedKey: string,
828
- expectedValue: string
829
- ) {
830
- const requests = { count: 0 };
831
- setMockRawResponse(
832
- "/accounts/:accountId/storage/kv/namespaces/:namespaceId/values/:key",
833
- ([_url, accountId, namespaceId, key]) => {
834
- requests.count++;
835
- expect(accountId).toEqual("some-account-id");
836
- expect(namespaceId).toEqual(expectedNamespaceId);
837
- expect(key).toEqual(expectedKey);
838
- return expectedValue;
839
- }
840
- );
841
- return requests;
842
- }
866
+ afterEach(() => {
867
+ unsetMockFetchKVGetValues();
868
+ });
843
869
 
844
870
  it("should get a key in a given namespace specified by namespace-id", async () => {
845
- const requests = mockKeyGetRequest(
871
+ setMockFetchKVGetValue(
872
+ "some-account-id",
846
873
  "some-namespace-id",
847
874
  "my-key",
848
875
  "my-value"
849
876
  );
850
- const { error, stderr, stdout } = await runWrangler(
851
- "kv:key get my-key --namespace-id some-namespace-id"
852
- );
853
- expect(stdout).toMatchInlineSnapshot(`"my-value"`);
854
- expect(stderr).toMatchInlineSnapshot(`""`);
855
- expect(error).toMatchInlineSnapshot(`undefined`);
856
- expect(requests.count).toEqual(1);
877
+ await runWrangler("kv:key get my-key --namespace-id some-namespace-id");
878
+ expect(std.out).toMatchInlineSnapshot(`"my-value"`);
879
+ expect(std.err).toMatchInlineSnapshot(`""`);
857
880
  });
858
881
 
859
882
  it("should get a key in a given namespace specified by binding", async () => {
860
883
  writeWranglerConfig();
861
- const requests = mockKeyGetRequest("bound-id", "my-key", "my-value");
862
- const { error, stderr, stdout } = await runWrangler(
884
+ setMockFetchKVGetValue(
885
+ "some-account-id",
886
+ "bound-id",
887
+ "my-key",
888
+ "my-value"
889
+ );
890
+ await runWrangler(
863
891
  "kv:key get my-key --binding someBinding --preview false"
864
892
  );
865
- expect(stdout).toMatchInlineSnapshot(`"my-value"`);
866
- expect(stderr).toMatchInlineSnapshot(`""`);
867
- expect(error).toMatchInlineSnapshot(`undefined`);
868
- expect(requests.count).toEqual(1);
893
+ expect(std.out).toMatchInlineSnapshot(`"my-value"`);
894
+ expect(std.err).toMatchInlineSnapshot(`""`);
869
895
  });
870
896
 
871
897
  it("should get a key in a given preview namespace specified by binding", async () => {
872
898
  writeWranglerConfig();
873
- const requests = mockKeyGetRequest(
899
+ setMockFetchKVGetValue(
900
+ "some-account-id",
874
901
  "preview-bound-id",
875
902
  "my-key",
876
903
  "my-value"
877
904
  );
878
- const { error, stderr, stdout } = await runWrangler(
879
- "kv:key get my-key --binding someBinding --preview"
880
- );
881
- expect(stdout).toMatchInlineSnapshot(`"my-value"`);
882
- expect(stderr).toMatchInlineSnapshot(`""`);
883
- expect(error).toMatchInlineSnapshot(`undefined`);
884
- expect(requests.count).toEqual(1);
905
+ await runWrangler("kv:key get my-key --binding someBinding --preview");
906
+ expect(std.out).toMatchInlineSnapshot(`"my-value"`);
907
+ expect(std.err).toMatchInlineSnapshot(`""`);
885
908
  });
886
909
 
887
910
  it("should get a key for the specified environment in a given namespace", async () => {
888
911
  writeWranglerConfig();
889
- const requests = mockKeyGetRequest(
912
+ setMockFetchKVGetValue(
913
+ "some-account-id",
890
914
  "env-bound-id",
891
915
  "my-key",
892
916
  "my-value"
893
917
  );
894
- const { error, stderr, stdout } = await runWrangler(
918
+ await runWrangler(
895
919
  "kv:key get my-key my-value --binding someBinding --env some-environment --preview false"
896
920
  );
897
- expect(stdout).toMatchInlineSnapshot(`"my-value"`);
898
- expect(stderr).toMatchInlineSnapshot(`""`);
899
- expect(error).toMatchInlineSnapshot(`undefined`);
900
- expect(requests.count).toEqual(1);
921
+ expect(std.out).toMatchInlineSnapshot(`"my-value"`);
922
+ expect(std.err).toMatchInlineSnapshot(`""`);
901
923
  });
902
924
 
903
925
  it("should error if no key is provided", async () => {
904
- const { error, stdout, stderr } = await runWrangler("kv:key get");
905
-
906
- expect(stdout).toMatchInlineSnapshot(`""`);
907
- expect(stderr).toMatchInlineSnapshot(`
926
+ await expect(
927
+ runWrangler("kv:key get")
928
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
929
+ `"Not enough non-option arguments: got 0, need at least 1"`
930
+ );
931
+ expect(std.out).toMatchInlineSnapshot(`""`);
932
+ expect(std.err).toMatchInlineSnapshot(`
908
933
  "wrangler kv:key get <key>
909
934
 
910
935
  Reads a single value by key from the given namespace.
@@ -926,16 +951,16 @@ describe("wrangler", () => {
926
951
 
927
952
  Not enough non-option arguments: got 0, need at least 1"
928
953
  `);
929
- expect(error).toMatchInlineSnapshot(
930
- `[Error: Not enough non-option arguments: got 0, need at least 1]`
931
- );
932
954
  });
933
955
 
934
956
  it("should error if no binding nor namespace is provided", async () => {
935
- const { error, stdout, stderr } = await runWrangler("kv:key get foo");
936
-
937
- expect(stdout).toMatchInlineSnapshot(`""`);
938
- expect(stderr).toMatchInlineSnapshot(`
957
+ await expect(
958
+ runWrangler("kv:key get foo")
959
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
960
+ `"Exactly one of the arguments binding and namespace-id is required"`
961
+ );
962
+ expect(std.out).toMatchInlineSnapshot(`""`);
963
+ expect(std.err).toMatchInlineSnapshot(`
939
964
  "wrangler kv:key get <key>
940
965
 
941
966
  Reads a single value by key from the given namespace.
@@ -957,18 +982,17 @@ describe("wrangler", () => {
957
982
 
958
983
  Exactly one of the arguments binding and namespace-id is required"
959
984
  `);
960
- expect(error).toMatchInlineSnapshot(
961
- `[Error: Exactly one of the arguments binding and namespace-id is required]`
962
- );
963
985
  });
964
986
 
965
987
  it("should error if both binding and namespace is provided", async () => {
966
- const { error, stdout, stderr } = await runWrangler(
967
- "kv:key get foo --binding x --namespace-id y"
988
+ await expect(
989
+ runWrangler("kv:key get foo --binding x --namespace-id y")
990
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
991
+ `"Arguments binding and namespace-id are mutually exclusive"`
968
992
  );
969
993
 
970
- expect(stdout).toMatchInlineSnapshot(`""`);
971
- expect(stderr).toMatchInlineSnapshot(`
994
+ expect(std.out).toMatchInlineSnapshot(`""`);
995
+ expect(std.err).toMatchInlineSnapshot(`
972
996
  "wrangler kv:key get <key>
973
997
 
974
998
  Reads a single value by key from the given namespace.
@@ -990,23 +1014,22 @@ describe("wrangler", () => {
990
1014
 
991
1015
  Arguments binding and namespace-id are mutually exclusive"
992
1016
  `);
993
- expect(error).toMatchInlineSnapshot(
994
- `[Error: Arguments binding and namespace-id are mutually exclusive]`
995
- );
996
1017
  });
997
1018
 
998
1019
  it("should error if a given binding name is not in the configured kv namespaces", async () => {
999
1020
  writeWranglerConfig();
1000
- const { error, stdout, stderr } = await runWrangler(
1001
- `kv:key get key --binding otherBinding`
1002
- );
1003
- expect(stdout).toMatchInlineSnapshot(`""`);
1004
- expect(stderr).toMatchInlineSnapshot(
1021
+ await expect(
1022
+ runWrangler("kv:key get key --binding otherBinding")
1023
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
1005
1024
  `"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
1006
1025
  );
1007
- expect(error).toMatchInlineSnapshot(
1008
- `[Error: A namespace with binding name "otherBinding" was not found in the configured "kv_namespaces".]`
1009
- );
1026
+ expect(std.out).toMatchInlineSnapshot(`""`);
1027
+ expect(std.err).toMatchInlineSnapshot(`
1028
+ "A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
1029
+
1030
+ %s
1031
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1032
+ `);
1010
1033
  });
1011
1034
  });
1012
1035
 
@@ -1058,25 +1081,30 @@ describe("wrangler", () => {
1058
1081
 
1059
1082
  it("should error if a given binding name is not in the configured kv namespaces", async () => {
1060
1083
  writeWranglerConfig();
1061
- const { stderr } = await runWrangler(
1062
- `kv:key delete --binding otherBinding someKey`
1063
- );
1064
- expect(stderr).toMatchInlineSnapshot(
1084
+ await expect(
1085
+ runWrangler(`kv:key delete --binding otherBinding someKey`)
1086
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
1065
1087
  `"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
1066
1088
  );
1089
+
1090
+ expect(std.err).toMatchInlineSnapshot(`
1091
+ "A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
1092
+
1093
+ %s
1094
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1095
+ `);
1067
1096
  });
1068
1097
 
1069
1098
  it("should delete a key in a namespace specified by binding name in a given environment", async () => {
1070
1099
  writeWranglerConfig();
1071
1100
  const requests = mockDeleteRequest("env-bound-id", "someKey");
1072
- const { stdout, stderr, error } = await runWrangler(
1101
+ await runWrangler(
1073
1102
  `kv:key delete --binding someBinding --env some-environment --preview false someKey`
1074
1103
  );
1075
- expect(stdout).toMatchInlineSnapshot(
1104
+ expect(std.out).toMatchInlineSnapshot(
1076
1105
  `"deleting the key \\"someKey\\" on namespace env-bound-id"`
1077
1106
  );
1078
- expect(stderr).toMatchInlineSnapshot(`""`);
1079
- expect(error).toMatchInlineSnapshot(`undefined`);
1107
+ expect(std.err).toMatchInlineSnapshot(`""`);
1080
1108
  expect(requests.count).toEqual(1);
1081
1109
  });
1082
1110