wrangler 0.0.0-e88a54e → 0.0.0-e95e5a0
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 +25 -14
- package/bin/wrangler.js +13 -1
- package/miniflare-dist/index.mjs +4828 -21
- package/package.json +29 -24
- 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 +530 -201
- package/src/__tests__/dev.test.tsx +284 -18
- package/src/__tests__/guess-worker-format.test.ts +28 -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 +26 -1
- 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 +27 -769
- package/src/__tests__/init.test.ts +1516 -0
- package/src/__tests__/jest.setup.ts +4 -4
- package/src/__tests__/kv.test.ts +133 -61
- package/src/__tests__/logger.test.ts +115 -0
- package/src/__tests__/pages.test.ts +311 -26
- package/src/__tests__/publish.test.ts +2789 -618
- package/src/__tests__/r2.test.ts +26 -10
- package/src/__tests__/route.test.ts +4 -4
- package/src/__tests__/secret.test.ts +55 -34
- package/src/__tests__/tail.test.ts +146 -20
- package/src/__tests__/user.test.ts +131 -0
- package/src/__tests__/whoami.test.tsx +14 -9
- package/src/bundle.ts +30 -3
- 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 +32 -4
- package/src/config/index.ts +4 -3
- package/src/config/validation-helpers.ts +96 -7
- package/src/config/validation.ts +388 -54
- 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 +132 -78
- package/src/dev/local.tsx +101 -21
- package/src/dev/remote.tsx +23 -13
- package/src/dev/use-esbuild.ts +23 -5
- package/src/dialogs.tsx +16 -6
- package/src/entry.ts +83 -24
- package/src/environment-variables.ts +3 -1
- package/src/errors.ts +11 -0
- package/src/https-options.ts +3 -2
- package/src/index.tsx +689 -394
- package/src/inspect.ts +17 -11
- package/src/intl-polyfill.d.ts +139 -0
- 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 +875 -56
- package/src/parse.ts +1 -1
- package/src/proxy.ts +28 -19
- package/src/publish.ts +263 -141
- package/src/sites.tsx +27 -14
- package/src/tail/index.ts +2 -2
- package/src/tail/printing.ts +13 -8
- package/src/update-check.ts +19 -0
- package/src/user.tsx +116 -41
- 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 +21162 -50227
- package/miniflare-dist/index.mjs.map +0 -7
- package/src/__tests__/dev2.test.tsx +0 -154
- 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
|
|
|
@@ -72,9 +77,12 @@ describe("wrangler", () => {
|
|
|
72
77
|
await expect(
|
|
73
78
|
runWrangler("kv:namespace create abc def ghi")
|
|
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
|
});
|
|
@@ -809,9 +850,7 @@ describe("wrangler", () => {
|
|
|
809
850
|
100,
|
|
810
851
|
blankCursorValue
|
|
811
852
|
);
|
|
812
|
-
await runWrangler(
|
|
813
|
-
"kv:key list --namespace-id some-namespace-id --limit 100"
|
|
814
|
-
);
|
|
853
|
+
await runWrangler("kv:key list --namespace-id some-namespace-id");
|
|
815
854
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
816
855
|
expect(JSON.parse(std.out)).toEqual(keys);
|
|
817
856
|
expect(requests.count).toEqual(6);
|
|
@@ -827,11 +866,14 @@ describe("wrangler", () => {
|
|
|
827
866
|
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
828
867
|
);
|
|
829
868
|
expect(std.err).toMatchInlineSnapshot(`
|
|
830
|
-
"
|
|
869
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
831
870
|
|
|
832
|
-
|
|
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"
|
|
833
876
|
`);
|
|
834
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
835
877
|
});
|
|
836
878
|
});
|
|
837
879
|
|
|
@@ -889,7 +931,7 @@ describe("wrangler", () => {
|
|
|
889
931
|
"my-value"
|
|
890
932
|
);
|
|
891
933
|
await runWrangler(
|
|
892
|
-
"kv:key get my-key
|
|
934
|
+
"kv:key get my-key --binding someBinding --env some-environment --preview false"
|
|
893
935
|
);
|
|
894
936
|
expect(std.out).toMatchInlineSnapshot(`"my-value"`);
|
|
895
937
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
@@ -901,7 +943,10 @@ describe("wrangler", () => {
|
|
|
901
943
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
902
944
|
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
903
945
|
);
|
|
904
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
946
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
947
|
+
"
|
|
948
|
+
"
|
|
949
|
+
`);
|
|
905
950
|
expect(std.err).toMatchInlineSnapshot(`
|
|
906
951
|
"wrangler kv:key get <key>
|
|
907
952
|
|
|
@@ -921,8 +966,9 @@ describe("wrangler", () => {
|
|
|
921
966
|
--namespace-id The id of the namespace to get from [string]
|
|
922
967
|
-e, --env Perform on a specific environment [string]
|
|
923
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
|
|
924
970
|
|
|
925
|
-
|
|
971
|
+
"
|
|
926
972
|
`);
|
|
927
973
|
});
|
|
928
974
|
|
|
@@ -932,7 +978,10 @@ describe("wrangler", () => {
|
|
|
932
978
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
933
979
|
`"Exactly one of the arguments binding and namespace-id is required"`
|
|
934
980
|
);
|
|
935
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
981
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
982
|
+
"
|
|
983
|
+
"
|
|
984
|
+
`);
|
|
936
985
|
expect(std.err).toMatchInlineSnapshot(`
|
|
937
986
|
"wrangler kv:key get <key>
|
|
938
987
|
|
|
@@ -952,8 +1001,9 @@ describe("wrangler", () => {
|
|
|
952
1001
|
--namespace-id The id of the namespace to get from [string]
|
|
953
1002
|
-e, --env Perform on a specific environment [string]
|
|
954
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
|
|
955
1005
|
|
|
956
|
-
|
|
1006
|
+
"
|
|
957
1007
|
`);
|
|
958
1008
|
});
|
|
959
1009
|
|
|
@@ -964,7 +1014,10 @@ describe("wrangler", () => {
|
|
|
964
1014
|
`"Arguments binding and namespace-id are mutually exclusive"`
|
|
965
1015
|
);
|
|
966
1016
|
|
|
967
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
1017
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1018
|
+
"
|
|
1019
|
+
"
|
|
1020
|
+
`);
|
|
968
1021
|
expect(std.err).toMatchInlineSnapshot(`
|
|
969
1022
|
"wrangler kv:key get <key>
|
|
970
1023
|
|
|
@@ -984,8 +1037,9 @@ describe("wrangler", () => {
|
|
|
984
1037
|
--namespace-id The id of the namespace to get from [string]
|
|
985
1038
|
-e, --env Perform on a specific environment [string]
|
|
986
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
|
|
987
1041
|
|
|
988
|
-
|
|
1042
|
+
"
|
|
989
1043
|
`);
|
|
990
1044
|
});
|
|
991
1045
|
|
|
@@ -996,11 +1050,14 @@ describe("wrangler", () => {
|
|
|
996
1050
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
997
1051
|
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
998
1052
|
);
|
|
999
|
-
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
|
+
`);
|
|
1000
1057
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1001
|
-
"
|
|
1058
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
1002
1059
|
|
|
1003
|
-
|
|
1060
|
+
"
|
|
1004
1061
|
`);
|
|
1005
1062
|
});
|
|
1006
1063
|
});
|
|
@@ -1060,9 +1117,9 @@ describe("wrangler", () => {
|
|
|
1060
1117
|
);
|
|
1061
1118
|
|
|
1062
1119
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1063
|
-
"
|
|
1120
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
1064
1121
|
|
|
1065
|
-
|
|
1122
|
+
"
|
|
1066
1123
|
`);
|
|
1067
1124
|
});
|
|
1068
1125
|
|
|
@@ -1073,7 +1130,7 @@ describe("wrangler", () => {
|
|
|
1073
1130
|
`kv:key delete --binding someBinding --env some-environment --preview false someKey`
|
|
1074
1131
|
);
|
|
1075
1132
|
expect(std.out).toMatchInlineSnapshot(
|
|
1076
|
-
`"
|
|
1133
|
+
`"Deleting the key \\"someKey\\" on namespace env-bound-id."`
|
|
1077
1134
|
);
|
|
1078
1135
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1079
1136
|
expect(requests.count).toEqual(1);
|
|
@@ -1165,7 +1222,10 @@ describe("wrangler", () => {
|
|
|
1165
1222
|
"Unexpected JSON input from \\"keys.json\\".
|
|
1166
1223
|
Expected an array of key-value objects but got type \\"object\\"."
|
|
1167
1224
|
`);
|
|
1168
|
-
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
|
+
`);
|
|
1169
1229
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1170
1230
|
});
|
|
1171
1231
|
|
|
@@ -1199,10 +1259,16 @@ describe("wrangler", () => {
|
|
|
1199
1259
|
The item at index 3 is {\\"value\\":\\"someValue\\"}"
|
|
1200
1260
|
`);
|
|
1201
1261
|
|
|
1202
|
-
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
|
+
`);
|
|
1203
1266
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
1204
|
-
"
|
|
1205
|
-
|
|
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
|
+
"
|
|
1206
1272
|
`);
|
|
1207
1273
|
});
|
|
1208
1274
|
});
|
|
@@ -1334,7 +1400,10 @@ describe("wrangler", () => {
|
|
|
1334
1400
|
Expected an array of strings but got:
|
|
1335
1401
|
12354"
|
|
1336
1402
|
`);
|
|
1337
|
-
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
|
+
`);
|
|
1338
1407
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1339
1408
|
});
|
|
1340
1409
|
|
|
@@ -1356,7 +1425,10 @@ describe("wrangler", () => {
|
|
|
1356
1425
|
The item at index 2 is type: \\"object\\" - {\\"key\\":\\"someKey\\"}
|
|
1357
1426
|
The item at index 3 is type: \\"object\\" - null"
|
|
1358
1427
|
`);
|
|
1359
|
-
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
|
+
`);
|
|
1360
1432
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1361
1433
|
});
|
|
1362
1434
|
});
|
|
@@ -1367,7 +1439,7 @@ function writeWranglerConfig() {
|
|
|
1367
1439
|
writeFileSync(
|
|
1368
1440
|
"./wrangler.toml",
|
|
1369
1441
|
[
|
|
1370
|
-
'name = "
|
|
1442
|
+
'name = "other-worker"',
|
|
1371
1443
|
"kv_namespaces = [",
|
|
1372
1444
|
' { binding = "someBinding", id = "bound-id", preview_id = "preview-bound-id" }',
|
|
1373
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
|
+
});
|