wrangler 0.0.0-e2b7352 → 0.0.0-e2f9bb2

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 (86) hide show
  1. package/README.md +24 -13
  2. package/bin/wrangler.js +3 -0
  3. package/miniflare-dist/index.mjs +4828 -21
  4. package/package.json +29 -22
  5. package/pages/functions/buildPlugin.ts +92 -0
  6. package/pages/functions/buildWorker.ts +80 -4
  7. package/pages/functions/filepath-routing.test.ts +11 -0
  8. package/pages/functions/filepath-routing.ts +8 -0
  9. package/pages/functions/routes.ts +6 -1
  10. package/pages/functions/template-plugin.ts +146 -0
  11. package/pages/functions/template-worker.ts +21 -8
  12. package/src/__tests__/config-cache.test.ts +36 -0
  13. package/src/__tests__/configuration.test.ts +386 -81
  14. package/src/__tests__/dev.test.tsx +242 -21
  15. package/src/__tests__/guess-worker-format.test.ts +18 -1
  16. package/src/__tests__/helpers/mock-cfetch.ts +5 -1
  17. package/src/__tests__/helpers/mock-console.ts +20 -3
  18. package/src/__tests__/helpers/mock-dialogs.ts +24 -0
  19. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  20. package/src/__tests__/helpers/mock-istty.ts +27 -0
  21. package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
  22. package/src/__tests__/helpers/run-in-tmp.ts +7 -0
  23. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  24. package/src/__tests__/https-options.test.ts +5 -2
  25. package/src/__tests__/index.test.ts +25 -759
  26. package/src/__tests__/init.test.ts +1042 -0
  27. package/src/__tests__/jest.setup.ts +4 -4
  28. package/src/__tests__/kv.test.ts +130 -56
  29. package/src/__tests__/logger.test.ts +115 -0
  30. package/src/__tests__/pages.test.ts +290 -43
  31. package/src/__tests__/publish.test.ts +1699 -333
  32. package/src/__tests__/r2.test.ts +24 -8
  33. package/src/__tests__/route.test.ts +4 -4
  34. package/src/__tests__/secret.test.ts +55 -34
  35. package/src/__tests__/tail.test.ts +97 -45
  36. package/src/__tests__/user.test.ts +131 -0
  37. package/src/__tests__/whoami.test.tsx +14 -9
  38. package/src/bundle.ts +15 -1
  39. package/src/cfetch/internal.ts +0 -2
  40. package/src/cli.ts +5 -11
  41. package/src/config/README.md +1 -1
  42. package/src/config/config.ts +20 -4
  43. package/src/config/environment.ts +26 -3
  44. package/src/config/index.ts +2 -1
  45. package/src/config/validation-helpers.ts +26 -5
  46. package/src/config/validation.ts +233 -41
  47. package/src/config-cache.ts +45 -0
  48. package/src/create-worker-preview.ts +22 -13
  49. package/src/create-worker-upload-form.ts +32 -9
  50. package/src/dev/dev-vars.ts +36 -0
  51. package/src/dev/dev.tsx +60 -34
  52. package/src/dev/local.tsx +101 -21
  53. package/src/dev/remote.tsx +23 -13
  54. package/src/dev/use-esbuild.ts +19 -5
  55. package/src/dialogs.tsx +16 -6
  56. package/src/entry.ts +38 -11
  57. package/src/environment-variables.ts +3 -1
  58. package/src/errors.ts +11 -0
  59. package/src/https-options.ts +3 -2
  60. package/src/index.tsx +529 -303
  61. package/src/inspect.ts +17 -11
  62. package/src/logger.ts +66 -0
  63. package/src/miniflare-cli/index.ts +4 -0
  64. package/src/miniflare-cli/request-context.ts +40 -0
  65. package/src/module-collection.ts +7 -7
  66. package/src/open-in-browser.ts +5 -4
  67. package/src/package-manager.ts +9 -8
  68. package/src/pages.tsx +860 -55
  69. package/src/parse.ts +1 -1
  70. package/src/proxy.ts +25 -11
  71. package/src/publish.ts +260 -141
  72. package/src/sites.tsx +27 -14
  73. package/src/tail/index.ts +1 -1
  74. package/src/tail/printing.ts +13 -8
  75. package/src/update-check.ts +19 -0
  76. package/src/user.tsx +104 -38
  77. package/src/whoami.tsx +2 -1
  78. package/src/worker.ts +15 -6
  79. package/templates/gitignore +171 -0
  80. package/templates/static-asset-facade.js +1 -1
  81. package/wrangler-dist/cli.js +20948 -50169
  82. package/miniflare-dist/index.mjs.map +0 -7
  83. package/src/__tests__/logout.test.ts +0 -52
  84. package/src/__tests__/sentry.test.ts +0 -146
  85. package/src/reporting.ts +0 -131
  86. package/wrangler-dist/cli.js.map +0 -7
@@ -22,10 +22,6 @@ jest.mock("undici", () => {
22
22
  };
23
23
  });
24
24
 
25
- // Outside of the Sentry tests themselves, we mock Sentry to ensure that it doesn't actually send any data and
26
- // that it doesn't interfere with the rest of the tests.
27
- jest.mock("../reporting");
28
-
29
25
  fetchMock.doMock(() => {
30
26
  // Any un-mocked fetches should throw
31
27
  throw new Error("Unexpected fetch request");
@@ -67,3 +63,7 @@ jest.mock("../dev/dev", () => {
67
63
  return null;
68
64
  });
69
65
  });
66
+
67
+ // Make sure that we don't accidentally try to open a browser window when running tests.
68
+ // We will actually provide a mock implementation for `openInBrowser()` within relevant tests.
69
+ jest.mock("../open-in-browser");
@@ -8,7 +8,7 @@ import {
8
8
  setMockFetchKVGetValue,
9
9
  } from "./helpers/mock-cfetch";
10
10
  import { mockConsoleMethods } from "./helpers/mock-console";
11
- import { mockConfirm } from "./helpers/mock-dialogs";
11
+ import { clearConfirmMocks, mockConfirm } from "./helpers/mock-dialogs";
12
12
  import { mockKeyListRequest } from "./helpers/mock-kv";
13
13
  import { runInTempDir } from "./helpers/run-in-tmp";
14
14
  import { runWrangler } from "./helpers/run-wrangler";
@@ -22,6 +22,7 @@ describe("wrangler", () => {
22
22
 
23
23
  afterEach(() => {
24
24
  unsetAllMocks();
25
+ clearConfirmMocks();
25
26
  });
26
27
 
27
28
  describe("kv:namespace", () => {
@@ -45,7 +46,10 @@ describe("wrangler", () => {
45
46
  ).rejects.toThrowErrorMatchingInlineSnapshot(
46
47
  `"Not enough non-option arguments: got 0, need at least 1"`
47
48
  );
48
- expect(std.out).toMatchInlineSnapshot(`""`);
49
+ expect(std.out).toMatchInlineSnapshot(`
50
+ "
51
+ "
52
+ `);
49
53
  expect(std.err).toMatchInlineSnapshot(`
50
54
  "wrangler kv:namespace create <namespace>
51
55
 
@@ -63,8 +67,9 @@ describe("wrangler", () => {
63
67
  Options:
64
68
  -e, --env Perform on a specific environment [string]
65
69
  --preview Interact with a preview namespace [boolean]
70
+ X [ERROR] Not enough non-option arguments: got 0, need at least 1
66
71
 
67
- Not enough non-option arguments: got 0, need at least 1"
72
+ "
68
73
  `);
69
74
  });
70
75
 
@@ -74,7 +79,10 @@ describe("wrangler", () => {
74
79
  ).rejects.toThrowErrorMatchingInlineSnapshot(
75
80
  `"Unknown arguments: def, ghi"`
76
81
  );
77
- expect(std.out).toMatchInlineSnapshot(`""`);
82
+ expect(std.out).toMatchInlineSnapshot(`
83
+ "
84
+ "
85
+ `);
78
86
  expect(std.err).toMatchInlineSnapshot(`
79
87
  "wrangler kv:namespace create <namespace>
80
88
 
@@ -92,8 +100,9 @@ describe("wrangler", () => {
92
100
  Options:
93
101
  -e, --env Perform on a specific environment [string]
94
102
  --preview Interact with a preview namespace [boolean]
103
+ X [ERROR] Unknown arguments: def, ghi
95
104
 
96
- Unknown arguments: def, ghi"
105
+ "
97
106
  `);
98
107
  });
99
108
 
@@ -104,7 +113,10 @@ describe("wrangler", () => {
104
113
  `"The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number."`
105
114
  );
106
115
 
107
- expect(std.out).toMatchInlineSnapshot(`""`);
116
+ expect(std.out).toMatchInlineSnapshot(`
117
+ "
118
+ "
119
+ `);
108
120
  expect(std.err).toMatchInlineSnapshot(`
109
121
  "wrangler kv:namespace create <namespace>
110
122
 
@@ -122,8 +134,9 @@ describe("wrangler", () => {
122
134
  Options:
123
135
  -e, --env Perform on a specific environment [string]
124
136
  --preview Interact with a preview namespace [boolean]
137
+ X [ERROR] The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number.
125
138
 
126
- The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number."
139
+ "
127
140
  `);
128
141
  });
129
142
 
@@ -150,11 +163,11 @@ describe("wrangler", () => {
150
163
  });
151
164
 
152
165
  it("should create a namespace using configured worker name", async () => {
153
- writeFileSync("./wrangler.toml", 'name = "otherWorker"', "utf-8");
154
- mockCreateRequest("otherWorker-UnitTestNamespace");
166
+ writeFileSync("./wrangler.toml", 'name = "other-worker"', "utf-8");
167
+ mockCreateRequest("other-worker-UnitTestNamespace");
155
168
  await runWrangler("kv:namespace create UnitTestNamespace");
156
169
  expect(std.out).toMatchInlineSnapshot(`
157
- "🌀 Creating namespace with title \\"otherWorker-UnitTestNamespace\\"
170
+ "🌀 Creating namespace with title \\"other-worker-UnitTestNamespace\\"
158
171
  ✨ Success!
159
172
  Add the following to your configuration file in your kv_namespaces array:
160
173
  { binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }"
@@ -288,9 +301,11 @@ describe("wrangler", () => {
288
301
  --namespace-id The id of the namespace to delete [string]
289
302
  -e, --env Perform on a specific environment [string]
290
303
  --preview Interact with a preview namespace [boolean]
304
+ X [ERROR] Not able to delete namespace.
305
+
306
+ A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
291
307
 
292
- Not able to delete namespace.
293
- A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."
308
+ "
294
309
  `);
295
310
  });
296
311
 
@@ -365,7 +380,7 @@ describe("wrangler", () => {
365
380
 
366
381
  expect(requests.count).toEqual(1);
367
382
  expect(std.out).toMatchInlineSnapshot(
368
- `"writing the value \\"my-value\\" to key \\"my-key\\" on namespace some-namespace-id"`
383
+ `"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace some-namespace-id."`
369
384
  );
370
385
  expect(std.err).toMatchInlineSnapshot(`""`);
371
386
  });
@@ -381,7 +396,7 @@ describe("wrangler", () => {
381
396
  );
382
397
 
383
398
  expect(std.out).toMatchInlineSnapshot(
384
- `"writing the value \\"my-value\\" to key \\"my-key\\" on namespace bound-id"`
399
+ `"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace bound-id."`
385
400
  );
386
401
  expect(std.err).toMatchInlineSnapshot(`""`);
387
402
  expect(requests.count).toEqual(1);
@@ -399,7 +414,7 @@ describe("wrangler", () => {
399
414
  );
400
415
 
401
416
  expect(std.out).toMatchInlineSnapshot(
402
- `"writing the value \\"my-value\\" to key \\"my-key\\" on namespace preview-bound-id"`
417
+ `"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace preview-bound-id."`
403
418
  );
404
419
  expect(std.err).toMatchInlineSnapshot(`""`);
405
420
  expect(requests.count).toEqual(1);
@@ -417,7 +432,7 @@ describe("wrangler", () => {
417
432
  );
418
433
  expect(requests.count).toEqual(1);
419
434
  expect(std.out).toMatchInlineSnapshot(
420
- `"writing the value \\"my-value\\" to key \\"my-key\\" on namespace some-namespace-id"`
435
+ `"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace some-namespace-id."`
421
436
  );
422
437
  expect(std.err).toMatchInlineSnapshot(`""`);
423
438
  });
@@ -432,7 +447,7 @@ describe("wrangler", () => {
432
447
  "kv:key put my-key my-value --binding someBinding --env some-environment --preview false"
433
448
  );
434
449
  expect(std.out).toMatchInlineSnapshot(
435
- `"writing the value \\"my-value\\" to key \\"my-key\\" on namespace env-bound-id"`
450
+ `"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace env-bound-id."`
436
451
  );
437
452
  expect(std.err).toMatchInlineSnapshot(`""`);
438
453
  expect(requests.count).toEqual(1);
@@ -448,7 +463,7 @@ describe("wrangler", () => {
448
463
  "kv:key put my-key --namespace-id some-namespace-id --path foo.txt"
449
464
  );
450
465
  expect(std.out).toMatchInlineSnapshot(
451
- `"writing the contents of foo.txt to the key \\"my-key\\" on namespace some-namespace-id"`
466
+ `"Writing the contents of foo.txt to the key \\"my-key\\" on namespace some-namespace-id."`
452
467
  );
453
468
  expect(std.err).toMatchInlineSnapshot(`""`);
454
469
  expect(requests.count).toEqual(1);
@@ -461,7 +476,10 @@ describe("wrangler", () => {
461
476
  `"Not enough non-option arguments: got 0, need at least 1"`
462
477
  );
463
478
 
464
- expect(std.out).toMatchInlineSnapshot(`""`);
479
+ expect(std.out).toMatchInlineSnapshot(`
480
+ "
481
+ "
482
+ `);
465
483
  expect(std.err).toMatchInlineSnapshot(`
466
484
  "wrangler kv:key put <key> [value]
467
485
 
@@ -485,8 +503,9 @@ describe("wrangler", () => {
485
503
  --ttl Time for which the entries should be visible [number]
486
504
  --expiration Time since the UNIX epoch after which the entry expires [number]
487
505
  --path Read value from the file at a given path [string]
506
+ X [ERROR] Not enough non-option arguments: got 0, need at least 1
488
507
 
489
- Not enough non-option arguments: got 0, need at least 1"
508
+ "
490
509
  `);
491
510
  });
492
511
 
@@ -497,7 +516,10 @@ describe("wrangler", () => {
497
516
  `"Exactly one of the arguments binding and namespace-id is required"`
498
517
  );
499
518
 
500
- expect(std.out).toMatchInlineSnapshot(`""`);
519
+ expect(std.out).toMatchInlineSnapshot(`
520
+ "
521
+ "
522
+ `);
501
523
  expect(std.err).toMatchInlineSnapshot(`
502
524
  "wrangler kv:key put <key> [value]
503
525
 
@@ -521,8 +543,9 @@ describe("wrangler", () => {
521
543
  --ttl Time for which the entries should be visible [number]
522
544
  --expiration Time since the UNIX epoch after which the entry expires [number]
523
545
  --path Read value from the file at a given path [string]
546
+ X [ERROR] Exactly one of the arguments binding and namespace-id is required
524
547
 
525
- Exactly one of the arguments binding and namespace-id is required"
548
+ "
526
549
  `);
527
550
  });
528
551
 
@@ -533,7 +556,10 @@ describe("wrangler", () => {
533
556
  `"Arguments binding and namespace-id are mutually exclusive"`
534
557
  );
535
558
 
536
- expect(std.out).toMatchInlineSnapshot(`""`);
559
+ expect(std.out).toMatchInlineSnapshot(`
560
+ "
561
+ "
562
+ `);
537
563
  expect(std.err).toMatchInlineSnapshot(`
538
564
  "wrangler kv:key put <key> [value]
539
565
 
@@ -557,8 +583,9 @@ describe("wrangler", () => {
557
583
  --ttl Time for which the entries should be visible [number]
558
584
  --expiration Time since the UNIX epoch after which the entry expires [number]
559
585
  --path Read value from the file at a given path [string]
586
+ X [ERROR] Arguments binding and namespace-id are mutually exclusive
560
587
 
561
- Arguments binding and namespace-id are mutually exclusive"
588
+ "
562
589
  `);
563
590
  });
564
591
 
@@ -569,7 +596,10 @@ describe("wrangler", () => {
569
596
  `"Exactly one of the arguments value and path is required"`
570
597
  );
571
598
 
572
- expect(std.out).toMatchInlineSnapshot(`""`);
599
+ expect(std.out).toMatchInlineSnapshot(`
600
+ "
601
+ "
602
+ `);
573
603
  expect(std.err).toMatchInlineSnapshot(`
574
604
  "wrangler kv:key put <key> [value]
575
605
 
@@ -593,8 +623,9 @@ describe("wrangler", () => {
593
623
  --ttl Time for which the entries should be visible [number]
594
624
  --expiration Time since the UNIX epoch after which the entry expires [number]
595
625
  --path Read value from the file at a given path [string]
626
+ X [ERROR] Exactly one of the arguments value and path is required
596
627
 
597
- Exactly one of the arguments value and path is required"
628
+ "
598
629
  `);
599
630
  });
600
631
 
@@ -605,7 +636,10 @@ describe("wrangler", () => {
605
636
  `"Arguments value and path are mutually exclusive"`
606
637
  );
607
638
 
608
- expect(std.out).toMatchInlineSnapshot(`""`);
639
+ expect(std.out).toMatchInlineSnapshot(`
640
+ "
641
+ "
642
+ `);
609
643
  expect(std.err).toMatchInlineSnapshot(`
610
644
  "wrangler kv:key put <key> [value]
611
645
 
@@ -629,8 +663,9 @@ describe("wrangler", () => {
629
663
  --ttl Time for which the entries should be visible [number]
630
664
  --expiration Time since the UNIX epoch after which the entry expires [number]
631
665
  --path Read value from the file at a given path [string]
666
+ X [ERROR] Arguments value and path are mutually exclusive
632
667
 
633
- Arguments value and path are mutually exclusive"
668
+ "
634
669
  `);
635
670
  });
636
671
 
@@ -642,11 +677,14 @@ describe("wrangler", () => {
642
677
  `"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
643
678
  );
644
679
 
645
- expect(std.out).toMatchInlineSnapshot(`""`);
680
+ expect(std.out).toMatchInlineSnapshot(`
681
+ "
682
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
683
+ `);
646
684
  expect(std.err).toMatchInlineSnapshot(`
647
- "A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
685
+ "X [ERROR] A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
648
686
 
649
- %s If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
687
+ "
650
688
  `);
651
689
  });
652
690
 
@@ -661,11 +699,14 @@ describe("wrangler", () => {
661
699
  ).rejects.toThrowErrorMatchingInlineSnapshot(
662
700
  `"someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace."`
663
701
  );
664
- expect(std.out).toMatchInlineSnapshot(`""`);
702
+ expect(std.out).toMatchInlineSnapshot(`
703
+ "
704
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
705
+ `);
665
706
  expect(std.err).toMatchInlineSnapshot(`
666
- "someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace.
707
+ "X [ERROR] someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace.
667
708
 
668
- %s If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
709
+ "
669
710
  `);
670
711
  expect(requests.count).toEqual(0);
671
712
  });
@@ -825,11 +866,14 @@ describe("wrangler", () => {
825
866
  `"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
826
867
  );
827
868
  expect(std.err).toMatchInlineSnapshot(`
828
- "A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
869
+ "X [ERROR] A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
829
870
 
830
- %s If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
871
+ "
872
+ `);
873
+ expect(std.out).toMatchInlineSnapshot(`
874
+ "
875
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
831
876
  `);
832
- expect(std.out).toMatchInlineSnapshot(`""`);
833
877
  });
834
878
  });
835
879
 
@@ -899,7 +943,10 @@ describe("wrangler", () => {
899
943
  ).rejects.toThrowErrorMatchingInlineSnapshot(
900
944
  `"Not enough non-option arguments: got 0, need at least 1"`
901
945
  );
902
- expect(std.out).toMatchInlineSnapshot(`""`);
946
+ expect(std.out).toMatchInlineSnapshot(`
947
+ "
948
+ "
949
+ `);
903
950
  expect(std.err).toMatchInlineSnapshot(`
904
951
  "wrangler kv:key get <key>
905
952
 
@@ -919,8 +966,9 @@ describe("wrangler", () => {
919
966
  --namespace-id The id of the namespace to get from [string]
920
967
  -e, --env Perform on a specific environment [string]
921
968
  --preview Interact with a preview namespace [boolean] [default: false]
969
+ X [ERROR] Not enough non-option arguments: got 0, need at least 1
922
970
 
923
- Not enough non-option arguments: got 0, need at least 1"
971
+ "
924
972
  `);
925
973
  });
926
974
 
@@ -930,7 +978,10 @@ describe("wrangler", () => {
930
978
  ).rejects.toThrowErrorMatchingInlineSnapshot(
931
979
  `"Exactly one of the arguments binding and namespace-id is required"`
932
980
  );
933
- expect(std.out).toMatchInlineSnapshot(`""`);
981
+ expect(std.out).toMatchInlineSnapshot(`
982
+ "
983
+ "
984
+ `);
934
985
  expect(std.err).toMatchInlineSnapshot(`
935
986
  "wrangler kv:key get <key>
936
987
 
@@ -950,8 +1001,9 @@ describe("wrangler", () => {
950
1001
  --namespace-id The id of the namespace to get from [string]
951
1002
  -e, --env Perform on a specific environment [string]
952
1003
  --preview Interact with a preview namespace [boolean] [default: false]
1004
+ X [ERROR] Exactly one of the arguments binding and namespace-id is required
953
1005
 
954
- Exactly one of the arguments binding and namespace-id is required"
1006
+ "
955
1007
  `);
956
1008
  });
957
1009
 
@@ -962,7 +1014,10 @@ describe("wrangler", () => {
962
1014
  `"Arguments binding and namespace-id are mutually exclusive"`
963
1015
  );
964
1016
 
965
- expect(std.out).toMatchInlineSnapshot(`""`);
1017
+ expect(std.out).toMatchInlineSnapshot(`
1018
+ "
1019
+ "
1020
+ `);
966
1021
  expect(std.err).toMatchInlineSnapshot(`
967
1022
  "wrangler kv:key get <key>
968
1023
 
@@ -982,8 +1037,9 @@ describe("wrangler", () => {
982
1037
  --namespace-id The id of the namespace to get from [string]
983
1038
  -e, --env Perform on a specific environment [string]
984
1039
  --preview Interact with a preview namespace [boolean] [default: false]
1040
+ X [ERROR] Arguments binding and namespace-id are mutually exclusive
985
1041
 
986
- Arguments binding and namespace-id are mutually exclusive"
1042
+ "
987
1043
  `);
988
1044
  });
989
1045
 
@@ -994,11 +1050,14 @@ describe("wrangler", () => {
994
1050
  ).rejects.toThrowErrorMatchingInlineSnapshot(
995
1051
  `"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
996
1052
  );
997
- expect(std.out).toMatchInlineSnapshot(`""`);
1053
+ expect(std.out).toMatchInlineSnapshot(`
1054
+ "
1055
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1056
+ `);
998
1057
  expect(std.err).toMatchInlineSnapshot(`
999
- "A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
1058
+ "X [ERROR] A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
1000
1059
 
1001
- %s If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1060
+ "
1002
1061
  `);
1003
1062
  });
1004
1063
  });
@@ -1058,9 +1117,9 @@ describe("wrangler", () => {
1058
1117
  );
1059
1118
 
1060
1119
  expect(std.err).toMatchInlineSnapshot(`
1061
- "A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
1120
+ "X [ERROR] A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
1062
1121
 
1063
- %s If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1122
+ "
1064
1123
  `);
1065
1124
  });
1066
1125
 
@@ -1071,7 +1130,7 @@ describe("wrangler", () => {
1071
1130
  `kv:key delete --binding someBinding --env some-environment --preview false someKey`
1072
1131
  );
1073
1132
  expect(std.out).toMatchInlineSnapshot(
1074
- `"deleting the key \\"someKey\\" on namespace env-bound-id"`
1133
+ `"Deleting the key \\"someKey\\" on namespace env-bound-id."`
1075
1134
  );
1076
1135
  expect(std.err).toMatchInlineSnapshot(`""`);
1077
1136
  expect(requests.count).toEqual(1);
@@ -1163,7 +1222,10 @@ describe("wrangler", () => {
1163
1222
  "Unexpected JSON input from \\"keys.json\\".
1164
1223
  Expected an array of key-value objects but got type \\"object\\"."
1165
1224
  `);
1166
- expect(std.out).toMatchInlineSnapshot(`""`);
1225
+ expect(std.out).toMatchInlineSnapshot(`
1226
+ "
1227
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1228
+ `);
1167
1229
  expect(std.warn).toMatchInlineSnapshot(`""`);
1168
1230
  });
1169
1231
 
@@ -1197,10 +1259,16 @@ describe("wrangler", () => {
1197
1259
  The item at index 3 is {\\"value\\":\\"someValue\\"}"
1198
1260
  `);
1199
1261
 
1200
- expect(std.out).toMatchInlineSnapshot(`""`);
1262
+ expect(std.out).toMatchInlineSnapshot(`
1263
+ "
1264
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1265
+ `);
1201
1266
  expect(std.warn).toMatchInlineSnapshot(`
1202
- "Unexpected key-value properties in \\"keys.json\\".
1203
- The item at index 4 contains unexpected properties: [\\"invalid\\"]."
1267
+ "▲ [WARNING] Unexpected key-value properties in \\"keys.json\\".
1268
+
1269
+ The item at index 4 contains unexpected properties: [\\"invalid\\"].
1270
+
1271
+ "
1204
1272
  `);
1205
1273
  });
1206
1274
  });
@@ -1332,7 +1400,10 @@ describe("wrangler", () => {
1332
1400
  Expected an array of strings but got:
1333
1401
  12354"
1334
1402
  `);
1335
- expect(std.out).toMatchInlineSnapshot(`""`);
1403
+ expect(std.out).toMatchInlineSnapshot(`
1404
+ "
1405
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1406
+ `);
1336
1407
  expect(std.warn).toMatchInlineSnapshot(`""`);
1337
1408
  });
1338
1409
 
@@ -1354,7 +1425,10 @@ describe("wrangler", () => {
1354
1425
  The item at index 2 is type: \\"object\\" - {\\"key\\":\\"someKey\\"}
1355
1426
  The item at index 3 is type: \\"object\\" - null"
1356
1427
  `);
1357
- expect(std.out).toMatchInlineSnapshot(`""`);
1428
+ expect(std.out).toMatchInlineSnapshot(`
1429
+ "
1430
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1431
+ `);
1358
1432
  expect(std.warn).toMatchInlineSnapshot(`""`);
1359
1433
  });
1360
1434
  });
@@ -1365,7 +1439,7 @@ function writeWranglerConfig() {
1365
1439
  writeFileSync(
1366
1440
  "./wrangler.toml",
1367
1441
  [
1368
- 'name = "otherWorker"',
1442
+ 'name = "other-worker"',
1369
1443
  "kv_namespaces = [",
1370
1444
  ' { binding = "someBinding", id = "bound-id", preview_id = "preview-bound-id" }',
1371
1445
  "]",
@@ -0,0 +1,115 @@
1
+ import { logger } from "../logger";
2
+ import { mockConsoleMethods } from "./helpers/mock-console";
3
+
4
+ describe("logger", () => {
5
+ const std = mockConsoleMethods();
6
+
7
+ it("should add colored markers to error and warning messages", () => {
8
+ logger.loggerLevel = "debug";
9
+ logger.debug("This is a debug message");
10
+ logger.log("This is a log message");
11
+ logger.warn("This is a warn message");
12
+ logger.error("This is a error message");
13
+
14
+ expect(std.debug).toMatchInlineSnapshot(`"This is a debug message"`);
15
+ expect(std.out).toMatchInlineSnapshot(`"This is a log message"`);
16
+ expect(std.warn).toMatchInlineSnapshot(`
17
+ "▲ [WARNING] This is a warn message
18
+
19
+ "
20
+ `);
21
+ expect(std.err).toMatchInlineSnapshot(`
22
+ "X [ERROR] This is a error message
23
+
24
+ "
25
+ `);
26
+ });
27
+
28
+ describe("loggerLevel=debug", () => {
29
+ it("should render messages that are at or above the log level set in the logger", () => {
30
+ logger.loggerLevel = "debug";
31
+ logger.debug("This is a debug message");
32
+ logger.log("This is a log message");
33
+ logger.warn("This is a warn message");
34
+ logger.error("This is a error message");
35
+
36
+ expect(std.debug).toMatchInlineSnapshot(`"This is a debug message"`);
37
+ expect(std.out).toMatchInlineSnapshot(`"This is a log message"`);
38
+ expect(std.warn).toMatchInlineSnapshot(`
39
+ "▲ [WARNING] This is a warn message
40
+
41
+ "
42
+ `);
43
+ expect(std.err).toMatchInlineSnapshot(`
44
+ "X [ERROR] This is a error message
45
+
46
+ "
47
+ `);
48
+ });
49
+ });
50
+
51
+ describe("loggerLevel=log", () => {
52
+ it("should render messages that are at or above the log level set in the logger", () => {
53
+ logger.loggerLevel = "log";
54
+ logger.debug("This is a debug message");
55
+ logger.log("This is a log message");
56
+ logger.warn("This is a warn message");
57
+ logger.error("This is a error message");
58
+
59
+ expect(std.debug).toMatchInlineSnapshot(`""`);
60
+ expect(std.out).toMatchInlineSnapshot(`"This is a log message"`);
61
+ expect(std.warn).toMatchInlineSnapshot(`
62
+ "▲ [WARNING] This is a warn message
63
+
64
+ "
65
+ `);
66
+ expect(std.err).toMatchInlineSnapshot(`
67
+ "X [ERROR] This is a error message
68
+
69
+ "
70
+ `);
71
+ });
72
+ });
73
+
74
+ describe("loggerLevel=warn", () => {
75
+ it("should render messages that are at or above the log level set in the logger", () => {
76
+ logger.loggerLevel = "warn";
77
+ logger.debug("This is a debug message");
78
+ logger.log("This is a log message");
79
+ logger.warn("This is a warn message");
80
+ logger.error("This is a error message");
81
+
82
+ expect(std.debug).toMatchInlineSnapshot(`""`);
83
+ expect(std.out).toMatchInlineSnapshot(`""`);
84
+ expect(std.warn).toMatchInlineSnapshot(`
85
+ "▲ [WARNING] This is a warn message
86
+
87
+ "
88
+ `);
89
+ expect(std.err).toMatchInlineSnapshot(`
90
+ "X [ERROR] This is a error message
91
+
92
+ "
93
+ `);
94
+ });
95
+ });
96
+
97
+ describe("loggerLevel=error", () => {
98
+ it("should render messages that are at or above the log level set in the logger", () => {
99
+ logger.loggerLevel = "error";
100
+ logger.debug("This is a debug message");
101
+ logger.log("This is a log message");
102
+ logger.warn("This is a warn message");
103
+ logger.error("This is a error message");
104
+
105
+ expect(std.debug).toMatchInlineSnapshot(`""`);
106
+ expect(std.out).toMatchInlineSnapshot(`""`);
107
+ expect(std.warn).toMatchInlineSnapshot(`""`);
108
+ expect(std.err).toMatchInlineSnapshot(`
109
+ "X [ERROR] This is a error message
110
+
111
+ "
112
+ `);
113
+ });
114
+ });
115
+ });