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.
- package/README.md +24 -13
- package/bin/wrangler.js +3 -0
- package/miniflare-dist/index.mjs +4828 -21
- package/package.json +29 -22
- package/pages/functions/buildPlugin.ts +92 -0
- package/pages/functions/buildWorker.ts +80 -4
- package/pages/functions/filepath-routing.test.ts +11 -0
- package/pages/functions/filepath-routing.ts +8 -0
- package/pages/functions/routes.ts +6 -1
- package/pages/functions/template-plugin.ts +146 -0
- package/pages/functions/template-worker.ts +21 -8
- package/src/__tests__/config-cache.test.ts +36 -0
- package/src/__tests__/configuration.test.ts +386 -81
- package/src/__tests__/dev.test.tsx +242 -21
- package/src/__tests__/guess-worker-format.test.ts +18 -1
- package/src/__tests__/helpers/mock-cfetch.ts +5 -1
- package/src/__tests__/helpers/mock-console.ts +20 -3
- package/src/__tests__/helpers/mock-dialogs.ts +24 -0
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +27 -0
- package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
- package/src/__tests__/helpers/run-in-tmp.ts +7 -0
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/https-options.test.ts +5 -2
- package/src/__tests__/index.test.ts +25 -759
- package/src/__tests__/init.test.ts +1042 -0
- package/src/__tests__/jest.setup.ts +4 -4
- package/src/__tests__/kv.test.ts +130 -56
- package/src/__tests__/logger.test.ts +115 -0
- package/src/__tests__/pages.test.ts +290 -43
- package/src/__tests__/publish.test.ts +1699 -333
- package/src/__tests__/r2.test.ts +24 -8
- package/src/__tests__/route.test.ts +4 -4
- package/src/__tests__/secret.test.ts +55 -34
- package/src/__tests__/tail.test.ts +97 -45
- package/src/__tests__/user.test.ts +131 -0
- package/src/__tests__/whoami.test.tsx +14 -9
- package/src/bundle.ts +15 -1
- package/src/cfetch/internal.ts +0 -2
- package/src/cli.ts +5 -11
- package/src/config/README.md +1 -1
- package/src/config/config.ts +20 -4
- package/src/config/environment.ts +26 -3
- package/src/config/index.ts +2 -1
- package/src/config/validation-helpers.ts +26 -5
- package/src/config/validation.ts +233 -41
- package/src/config-cache.ts +45 -0
- package/src/create-worker-preview.ts +22 -13
- package/src/create-worker-upload-form.ts +32 -9
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +60 -34
- package/src/dev/local.tsx +101 -21
- package/src/dev/remote.tsx +23 -13
- package/src/dev/use-esbuild.ts +19 -5
- package/src/dialogs.tsx +16 -6
- package/src/entry.ts +38 -11
- package/src/environment-variables.ts +3 -1
- package/src/errors.ts +11 -0
- package/src/https-options.ts +3 -2
- package/src/index.tsx +529 -303
- package/src/inspect.ts +17 -11
- package/src/logger.ts +66 -0
- package/src/miniflare-cli/index.ts +4 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +7 -7
- package/src/open-in-browser.ts +5 -4
- package/src/package-manager.ts +9 -8
- package/src/pages.tsx +860 -55
- package/src/parse.ts +1 -1
- package/src/proxy.ts +25 -11
- package/src/publish.ts +260 -141
- package/src/sites.tsx +27 -14
- package/src/tail/index.ts +1 -1
- package/src/tail/printing.ts +13 -8
- package/src/update-check.ts +19 -0
- package/src/user.tsx +104 -38
- package/src/whoami.tsx +2 -1
- package/src/worker.ts +15 -6
- package/templates/gitignore +171 -0
- package/templates/static-asset-facade.js +1 -1
- package/wrangler-dist/cli.js +20948 -50169
- package/miniflare-dist/index.mjs.map +0 -7
- package/src/__tests__/logout.test.ts +0 -52
- package/src/__tests__/sentry.test.ts +0 -146
- package/src/reporting.ts +0 -131
- 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");
|
package/src/__tests__/kv.test.ts
CHANGED
|
@@ -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
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
66
71
|
|
|
67
|
-
|
|
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
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mUnknown arguments: def, ghi[0m
|
|
95
104
|
|
|
96
|
-
|
|
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
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThe namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number.[0m
|
|
125
138
|
|
|
126
|
-
|
|
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 = "
|
|
154
|
-
mockCreateRequest("
|
|
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 \\"
|
|
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
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot able to delete namespace.[0m
|
|
305
|
+
|
|
306
|
+
A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
|
|
291
307
|
|
|
292
|
-
|
|
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
|
-
`"
|
|
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
|
-
`"
|
|
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
|
-
`"
|
|
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
|
-
`"
|
|
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
|
-
`"
|
|
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
|
-
`"
|
|
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
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
488
507
|
|
|
489
|
-
|
|
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
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mExactly one of the arguments binding and namespace-id is required[0m
|
|
524
547
|
|
|
525
|
-
|
|
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
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mArguments binding and namespace-id are mutually exclusive[0m
|
|
560
587
|
|
|
561
|
-
|
|
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
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mExactly one of the arguments value and path is required[0m
|
|
596
627
|
|
|
597
|
-
|
|
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
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mArguments value and path are mutually exclusive[0m
|
|
632
667
|
|
|
633
|
-
|
|
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
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
683
|
+
`);
|
|
646
684
|
expect(std.err).toMatchInlineSnapshot(`
|
|
647
|
-
"
|
|
685
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
648
686
|
|
|
649
|
-
|
|
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
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
705
|
+
`);
|
|
665
706
|
expect(std.err).toMatchInlineSnapshot(`
|
|
666
|
-
"
|
|
707
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1msomeBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace.[0m
|
|
667
708
|
|
|
668
|
-
|
|
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
|
-
"
|
|
869
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
829
870
|
|
|
830
|
-
|
|
871
|
+
"
|
|
872
|
+
`);
|
|
873
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
874
|
+
"
|
|
875
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
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
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
922
970
|
|
|
923
|
-
|
|
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
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mExactly one of the arguments binding and namespace-id is required[0m
|
|
953
1005
|
|
|
954
|
-
|
|
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
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mArguments binding and namespace-id are mutually exclusive[0m
|
|
985
1041
|
|
|
986
|
-
|
|
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
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
1056
|
+
`);
|
|
998
1057
|
expect(std.err).toMatchInlineSnapshot(`
|
|
999
|
-
"
|
|
1058
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
1000
1059
|
|
|
1001
|
-
|
|
1060
|
+
"
|
|
1002
1061
|
`);
|
|
1003
1062
|
});
|
|
1004
1063
|
});
|
|
@@ -1058,9 +1117,9 @@ describe("wrangler", () => {
|
|
|
1058
1117
|
);
|
|
1059
1118
|
|
|
1060
1119
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1061
|
-
"
|
|
1120
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
1062
1121
|
|
|
1063
|
-
|
|
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
|
-
`"
|
|
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
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
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
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
1265
|
+
`);
|
|
1201
1266
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
1202
|
-
"
|
|
1203
|
-
|
|
1267
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mUnexpected key-value properties in \\"keys.json\\".[0m
|
|
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
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
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
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
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 = "
|
|
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
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThis is a warn message[0m
|
|
18
|
+
|
|
19
|
+
"
|
|
20
|
+
`);
|
|
21
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
22
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThis is a error message[0m
|
|
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
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThis is a warn message[0m
|
|
40
|
+
|
|
41
|
+
"
|
|
42
|
+
`);
|
|
43
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
44
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThis is a error message[0m
|
|
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
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThis is a warn message[0m
|
|
63
|
+
|
|
64
|
+
"
|
|
65
|
+
`);
|
|
66
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
67
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThis is a error message[0m
|
|
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
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThis is a warn message[0m
|
|
86
|
+
|
|
87
|
+
"
|
|
88
|
+
`);
|
|
89
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
90
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThis is a error message[0m
|
|
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
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThis is a error message[0m
|
|
110
|
+
|
|
111
|
+
"
|
|
112
|
+
`);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|