wrangler 2.0.19 → 2.0.23
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/miniflare-dist/index.mjs +464 -4
- package/package.json +11 -3
- package/src/__tests__/dev.test.tsx +136 -4
- package/src/__tests__/kv.test.ts +80 -59
- package/src/__tests__/metrics.test.ts +30 -0
- package/src/__tests__/publish.test.ts +76 -0
- package/src/__tests__/version.test.ts +35 -0
- package/src/api/dev.ts +43 -9
- package/src/bundle.ts +30 -4
- package/src/config/config.ts +7 -0
- package/src/config/validation.ts +9 -1
- package/src/create-worker-preview.ts +3 -1
- package/src/dev/dev.tsx +55 -20
- package/src/dev/local.tsx +29 -10
- package/src/dev/remote.tsx +5 -5
- package/src/dev.tsx +84 -30
- package/src/index.tsx +63 -26
- package/src/metrics/is-ci.ts +14 -0
- package/src/metrics/metrics-config.ts +32 -15
- package/src/metrics/metrics-dispatcher.ts +27 -25
- package/src/metrics/send-event.ts +27 -15
- package/src/miniflare-cli/assets.ts +543 -0
- package/src/miniflare-cli/index.ts +36 -4
- package/src/pages/build.tsx +1 -1
- package/src/pages/deployments.tsx +5 -2
- package/src/pages/dev.tsx +81 -640
- package/src/pages/projects.tsx +6 -3
- package/src/pages/publish.tsx +2 -2
- package/src/publish.ts +13 -0
- package/src/pubsub/pubsub-commands.tsx +19 -16
- package/src/user/choose-account.tsx +20 -11
- package/src/user/user.tsx +2 -1
- package/src/whoami.tsx +2 -1
- package/src/worker-namespace.ts +5 -5
- package/templates/pages-shim.ts +9 -0
- package/wrangler-dist/cli.d.ts +32 -3
- package/wrangler-dist/cli.js +1077 -5934
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.23",
|
|
4
4
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wrangler",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"bundle": "node -r esbuild-register scripts/bundle.ts",
|
|
54
54
|
"check:type": "tsc",
|
|
55
55
|
"clean": "rm -rf wrangler-dist miniflare-dist emitted-types",
|
|
56
|
-
"dev": "npm run clean && concurrently -c black,blue 'npm run bundle -- --watch' 'npm run check:type -- --watch --preserveWatchOutput'",
|
|
56
|
+
"dev": "npm run clean && concurrently -c black,blue --kill-others-on-fail false 'npm run bundle -- --watch' 'npm run check:type -- --watch --preserveWatchOutput'",
|
|
57
57
|
"emit-types": "tsc -p tsconfig.emit.json && node -r esbuild-register scripts/emit-types.ts",
|
|
58
58
|
"prepublishOnly": "SOURCEMAPS=false npm run build",
|
|
59
59
|
"start": "npm run bundle && NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
|
|
@@ -61,6 +61,13 @@
|
|
|
61
61
|
"test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch"
|
|
62
62
|
},
|
|
63
63
|
"jest": {
|
|
64
|
+
"collectCoverage": true,
|
|
65
|
+
"coverageReporters": [
|
|
66
|
+
"json",
|
|
67
|
+
"html",
|
|
68
|
+
"text",
|
|
69
|
+
"cobertura"
|
|
70
|
+
],
|
|
64
71
|
"moduleNameMapper": {
|
|
65
72
|
"clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",
|
|
66
73
|
"miniflare/cli": "<rootDir>/../../node_modules/miniflare/dist/src/cli.js"
|
|
@@ -88,6 +95,7 @@
|
|
|
88
95
|
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
|
|
89
96
|
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
|
|
90
97
|
"blake3-wasm": "^2.1.5",
|
|
98
|
+
"chokidar": "^3.5.3",
|
|
91
99
|
"esbuild": "0.14.47",
|
|
92
100
|
"miniflare": "^2.6.0",
|
|
93
101
|
"nanoid": "^3.3.3",
|
|
@@ -109,7 +117,6 @@
|
|
|
109
117
|
"@types/ws": "^8.5.3",
|
|
110
118
|
"@types/yargs": "^17.0.10",
|
|
111
119
|
"@webcontainer/env": "^1.0.1",
|
|
112
|
-
"chokidar": "^3.5.3",
|
|
113
120
|
"clipboardy": "^3.0.0",
|
|
114
121
|
"cmd-shim": "^4.1.0",
|
|
115
122
|
"command-exists": "^1.2.9",
|
|
@@ -130,6 +137,7 @@
|
|
|
130
137
|
"ink-table": "^3.0.0",
|
|
131
138
|
"ink-testing-library": "^2.1.0",
|
|
132
139
|
"ink-text-input": "^4.0.3",
|
|
140
|
+
"is-ci": "^3.0.1",
|
|
133
141
|
"jest-fetch-mock": "^3.0.3",
|
|
134
142
|
"jest-websocket-mock": "^2.3.0",
|
|
135
143
|
"mime": "^3.0.0",
|
|
@@ -525,9 +525,9 @@ describe("wrangler dev", () => {
|
|
|
525
525
|
|
|
526
526
|
await expect(runWrangler("dev")).rejects
|
|
527
527
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
528
|
+
"The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
|
|
529
|
+
The \`main\` property in wrangler.toml should point to the file generated by the custom build."
|
|
530
|
+
`);
|
|
531
531
|
expect(std.out).toMatchInlineSnapshot(`
|
|
532
532
|
"Running custom build: node -e \\"console.log('custom build');\\"
|
|
533
533
|
|
|
@@ -673,6 +673,78 @@ describe("wrangler dev", () => {
|
|
|
673
673
|
});
|
|
674
674
|
});
|
|
675
675
|
|
|
676
|
+
describe("inspector port", () => {
|
|
677
|
+
it("should use 9229 as the default port", async () => {
|
|
678
|
+
writeWranglerToml({
|
|
679
|
+
main: "index.js",
|
|
680
|
+
});
|
|
681
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
682
|
+
await runWrangler("dev");
|
|
683
|
+
expect((Dev as jest.Mock).mock.calls[0][0].inspectorPort).toEqual(9229);
|
|
684
|
+
expect(std).toMatchInlineSnapshot(`
|
|
685
|
+
Object {
|
|
686
|
+
"debug": "",
|
|
687
|
+
"err": "",
|
|
688
|
+
"out": "",
|
|
689
|
+
"warn": "",
|
|
690
|
+
}
|
|
691
|
+
`);
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
it("should read --inspector-port", async () => {
|
|
695
|
+
writeWranglerToml({
|
|
696
|
+
main: "index.js",
|
|
697
|
+
});
|
|
698
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
699
|
+
await runWrangler("dev --inspector-port=9999");
|
|
700
|
+
expect((Dev as jest.Mock).mock.calls[0][0].inspectorPort).toEqual(9999);
|
|
701
|
+
expect(std).toMatchInlineSnapshot(`
|
|
702
|
+
Object {
|
|
703
|
+
"debug": "",
|
|
704
|
+
"err": "",
|
|
705
|
+
"out": "",
|
|
706
|
+
"warn": "",
|
|
707
|
+
}
|
|
708
|
+
`);
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
it("should read dev.inspector_port from wrangler.toml", async () => {
|
|
712
|
+
writeWranglerToml({
|
|
713
|
+
main: "index.js",
|
|
714
|
+
dev: {
|
|
715
|
+
inspector_port: 9999,
|
|
716
|
+
},
|
|
717
|
+
});
|
|
718
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
719
|
+
await runWrangler("dev");
|
|
720
|
+
expect((Dev as jest.Mock).mock.calls[0][0].inspectorPort).toEqual(9999);
|
|
721
|
+
expect(std).toMatchInlineSnapshot(`
|
|
722
|
+
Object {
|
|
723
|
+
"debug": "",
|
|
724
|
+
"err": "",
|
|
725
|
+
"out": "",
|
|
726
|
+
"warn": "",
|
|
727
|
+
}
|
|
728
|
+
`);
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
it("should error if a bad dev.inspector_port config is provided", async () => {
|
|
732
|
+
writeWranglerToml({
|
|
733
|
+
main: "index.js",
|
|
734
|
+
dev: {
|
|
735
|
+
// @ts-expect-error intentionally bad port
|
|
736
|
+
inspector_port: "some string",
|
|
737
|
+
},
|
|
738
|
+
});
|
|
739
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
740
|
+
await expect(runWrangler("dev")).rejects
|
|
741
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
742
|
+
"Processing wrangler.toml configuration:
|
|
743
|
+
- Expected \\"dev.inspector_port\\" to be of type number but got \\"some string\\"."
|
|
744
|
+
`);
|
|
745
|
+
});
|
|
746
|
+
});
|
|
747
|
+
|
|
676
748
|
describe("port", () => {
|
|
677
749
|
it("should default port to 8787 if it is not in use", async () => {
|
|
678
750
|
writeWranglerToml({
|
|
@@ -686,7 +758,7 @@ describe("wrangler dev", () => {
|
|
|
686
758
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
687
759
|
});
|
|
688
760
|
|
|
689
|
-
it("should use
|
|
761
|
+
it("should use `port` from `wrangler.toml`, if available", async () => {
|
|
690
762
|
writeWranglerToml({
|
|
691
763
|
main: "index.js",
|
|
692
764
|
dev: {
|
|
@@ -704,6 +776,22 @@ describe("wrangler dev", () => {
|
|
|
704
776
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
705
777
|
});
|
|
706
778
|
|
|
779
|
+
it("should error if a bad dev.port config is provided", async () => {
|
|
780
|
+
writeWranglerToml({
|
|
781
|
+
main: "index.js",
|
|
782
|
+
dev: {
|
|
783
|
+
// @ts-expect-error intentionally bad port
|
|
784
|
+
port: "some string",
|
|
785
|
+
},
|
|
786
|
+
});
|
|
787
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
788
|
+
await expect(runWrangler("dev")).rejects
|
|
789
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
790
|
+
"Processing wrangler.toml configuration:
|
|
791
|
+
- Expected \\"dev.port\\" to be of type number but got \\"some string\\"."
|
|
792
|
+
`);
|
|
793
|
+
});
|
|
794
|
+
|
|
707
795
|
it("should use --port command line arg, if provided", async () => {
|
|
708
796
|
writeWranglerToml({
|
|
709
797
|
main: "index.js",
|
|
@@ -1049,6 +1137,50 @@ describe("wrangler dev", () => {
|
|
|
1049
1137
|
}
|
|
1050
1138
|
`);
|
|
1051
1139
|
});
|
|
1140
|
+
|
|
1141
|
+
it("should default to true, without a warning", async () => {
|
|
1142
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
1143
|
+
await runWrangler("dev index.js");
|
|
1144
|
+
expect((Dev as jest.Mock).mock.calls[0][0].inspect).toEqual(true);
|
|
1145
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1146
|
+
Object {
|
|
1147
|
+
"debug": "",
|
|
1148
|
+
"err": "",
|
|
1149
|
+
"out": "",
|
|
1150
|
+
"warn": "",
|
|
1151
|
+
}
|
|
1152
|
+
`);
|
|
1153
|
+
});
|
|
1154
|
+
|
|
1155
|
+
it("should pass true, with a warning", async () => {
|
|
1156
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
1157
|
+
await runWrangler("dev index.js --inspect");
|
|
1158
|
+
expect((Dev as jest.Mock).mock.calls[0][0].inspect).toEqual(true);
|
|
1159
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1160
|
+
Object {
|
|
1161
|
+
"debug": "",
|
|
1162
|
+
"err": "",
|
|
1163
|
+
"out": "",
|
|
1164
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mPassing --inspect is unnecessary, now you can always connect to devtools.[0m
|
|
1165
|
+
|
|
1166
|
+
",
|
|
1167
|
+
}
|
|
1168
|
+
`);
|
|
1169
|
+
});
|
|
1170
|
+
|
|
1171
|
+
it("should pass false, without a warning", async () => {
|
|
1172
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
1173
|
+
await runWrangler("dev index.js --inspect false");
|
|
1174
|
+
expect((Dev as jest.Mock).mock.calls[0][0].inspect).toEqual(false);
|
|
1175
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1176
|
+
Object {
|
|
1177
|
+
"debug": "",
|
|
1178
|
+
"err": "",
|
|
1179
|
+
"out": "",
|
|
1180
|
+
"warn": "",
|
|
1181
|
+
}
|
|
1182
|
+
`);
|
|
1183
|
+
});
|
|
1052
1184
|
});
|
|
1053
1185
|
|
|
1054
1186
|
describe("service bindings", () => {
|
package/src/__tests__/kv.test.ts
CHANGED
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
unsetAllMocks,
|
|
7
7
|
unsetMockFetchKVGetValues,
|
|
8
8
|
setMockFetchKVGetValue,
|
|
9
|
+
setMockRawResponse,
|
|
10
|
+
createFetchResult,
|
|
9
11
|
} from "./helpers/mock-cfetch";
|
|
10
12
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
11
13
|
import { clearConfirmMocks, mockConfirm } from "./helpers/mock-dialogs";
|
|
@@ -280,9 +282,9 @@ describe("wrangler", () => {
|
|
|
280
282
|
writeWranglerConfig();
|
|
281
283
|
await expect(runWrangler("kv:namespace delete --binding otherBinding"))
|
|
282
284
|
.rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
285
|
+
"Not able to delete namespace.
|
|
286
|
+
A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."
|
|
287
|
+
`);
|
|
286
288
|
expect(std.err).toMatchInlineSnapshot(`
|
|
287
289
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot able to delete namespace.[0m
|
|
288
290
|
|
|
@@ -299,7 +301,10 @@ describe("wrangler", () => {
|
|
|
299
301
|
"kv:namespace delete --binding someBinding --env some-environment --preview false"
|
|
300
302
|
);
|
|
301
303
|
|
|
302
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
304
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
305
|
+
"Deleting KV namespace env-bound-id.
|
|
306
|
+
Deleted KV namespace env-bound-id."
|
|
307
|
+
`);
|
|
303
308
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
304
309
|
expect(requests.count).toEqual(1);
|
|
305
310
|
});
|
|
@@ -1181,12 +1186,12 @@ describe("wrangler", () => {
|
|
|
1181
1186
|
setIsTTY({ stdin: false, stdout: true });
|
|
1182
1187
|
await expect(runWrangler("kv:key get key --namespace-id=xxxx"))
|
|
1183
1188
|
.rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1189
|
+
"More than one account available but unable to select one in non-interactive mode.
|
|
1190
|
+
Please set the appropriate \`account_id\` in your \`wrangler.toml\` file.
|
|
1191
|
+
Available accounts are (\\"<name>\\" - \\"<id>\\"):
|
|
1192
|
+
\\"one\\" - \\"1\\")
|
|
1193
|
+
\\"two\\" - \\"2\\")"
|
|
1194
|
+
`);
|
|
1190
1195
|
});
|
|
1191
1196
|
|
|
1192
1197
|
it("should error if there are multiple accounts available but not interactive on stdout", async () => {
|
|
@@ -1197,12 +1202,28 @@ describe("wrangler", () => {
|
|
|
1197
1202
|
setIsTTY({ stdin: true, stdout: false });
|
|
1198
1203
|
await expect(runWrangler("kv:key get key --namespace-id=xxxx"))
|
|
1199
1204
|
.rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1205
|
+
"More than one account available but unable to select one in non-interactive mode.
|
|
1206
|
+
Please set the appropriate \`account_id\` in your \`wrangler.toml\` file.
|
|
1207
|
+
Available accounts are (\\"<name>\\" - \\"<id>\\"):
|
|
1208
|
+
\\"one\\" - \\"1\\")
|
|
1209
|
+
\\"two\\" - \\"2\\")"
|
|
1210
|
+
`);
|
|
1211
|
+
});
|
|
1212
|
+
|
|
1213
|
+
it("should recommend using a configuration if unable to fetch memberships", async () => {
|
|
1214
|
+
setMockRawResponse("/memberships", () => {
|
|
1215
|
+
return createFetchResult(undefined, false, [
|
|
1216
|
+
{
|
|
1217
|
+
code: 9109,
|
|
1218
|
+
message: "Uauthorized to access requested resource",
|
|
1219
|
+
},
|
|
1220
|
+
]);
|
|
1221
|
+
});
|
|
1222
|
+
await expect(runWrangler("kv:key get key --namespace-id=xxxx"))
|
|
1223
|
+
.rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1224
|
+
"Failed to automatically retrieve account IDs for the logged in user.
|
|
1225
|
+
You may have incorrect permissions on your API token. You can skip this account check by adding an \`account_id\` in your \`wrangler.toml\`, or by setting the value of CLOUDFLARE_ACCOUNT_ID\\""
|
|
1226
|
+
`);
|
|
1206
1227
|
});
|
|
1207
1228
|
|
|
1208
1229
|
it("should error if there are multiple accounts available but not interactive at all", async () => {
|
|
@@ -1213,12 +1234,12 @@ describe("wrangler", () => {
|
|
|
1213
1234
|
setIsTTY(false);
|
|
1214
1235
|
await expect(runWrangler("kv:key get key --namespace-id=xxxx"))
|
|
1215
1236
|
.rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1237
|
+
"More than one account available but unable to select one in non-interactive mode.
|
|
1238
|
+
Please set the appropriate \`account_id\` in your \`wrangler.toml\` file.
|
|
1239
|
+
Available accounts are (\\"<name>\\" - \\"<id>\\"):
|
|
1240
|
+
\\"one\\" - \\"1\\")
|
|
1241
|
+
\\"two\\" - \\"2\\")"
|
|
1242
|
+
`);
|
|
1222
1243
|
});
|
|
1223
1244
|
});
|
|
1224
1245
|
});
|
|
@@ -1390,9 +1411,9 @@ describe("wrangler", () => {
|
|
|
1390
1411
|
await expect(
|
|
1391
1412
|
runWrangler(`kv:bulk put --namespace-id some-namespace-id keys.json`)
|
|
1392
1413
|
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1414
|
+
"Unexpected JSON input from \\"keys.json\\".
|
|
1415
|
+
Expected an array of key-value objects but got type \\"object\\"."
|
|
1416
|
+
`);
|
|
1396
1417
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1397
1418
|
"
|
|
1398
1419
|
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
@@ -1430,30 +1451,30 @@ describe("wrangler", () => {
|
|
|
1430
1451
|
await expect(
|
|
1431
1452
|
runWrangler(`kv:bulk put --namespace-id some-namespace-id keys.json`)
|
|
1432
1453
|
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1454
|
+
"Unexpected JSON input from \\"keys.json\\".
|
|
1455
|
+
Each item in the array should be an object that matches:
|
|
1456
|
+
|
|
1457
|
+
interface KeyValue {
|
|
1458
|
+
key: string;
|
|
1459
|
+
value: string;
|
|
1460
|
+
expiration?: number;
|
|
1461
|
+
expiration_ttl?: number;
|
|
1462
|
+
metadata?: object;
|
|
1463
|
+
base64?: boolean;
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
The item at index 0 is 123
|
|
1467
|
+
The item at index 1 is \\"a string\\"
|
|
1468
|
+
The item at index 2 is {\\"key\\":\\"someKey\\"}
|
|
1469
|
+
The item at index 3 is {\\"value\\":\\"someValue\\"}
|
|
1470
|
+
The item at index 6 is {\\"key\\":123,\\"value\\":\\"somevalue\\"}
|
|
1471
|
+
The item at index 7 is {\\"key\\":\\"somekey\\",\\"value\\":123}
|
|
1472
|
+
The item at index 8 is {\\"key\\":\\"someKey1\\",\\"value\\":\\"someValue1\\",\\"expiration\\":\\"string\\"}
|
|
1473
|
+
The item at index 9 is {\\"key\\":\\"someKey1\\",\\"value\\":\\"someValue1\\",\\"expiration_ttl\\":\\"string\\"}
|
|
1474
|
+
The item at index 10 is {\\"key\\":123,\\"value\\":{\\"a\\":{\\"nested\\":\\"object\\"}}}
|
|
1475
|
+
The item at index 11 is {\\"key\\":\\"someKey1\\",\\"value\\":\\"someValue1\\",\\"metadata\\":123}
|
|
1476
|
+
The item at index 12 is {\\"key\\":\\"someKey1\\",\\"value\\":\\"someValue1\\",\\"base64\\":\\"string\\"}"
|
|
1477
|
+
`);
|
|
1457
1478
|
|
|
1458
1479
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1459
1480
|
"
|
|
@@ -1592,10 +1613,10 @@ describe("wrangler", () => {
|
|
|
1592
1613
|
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1593
1614
|
)
|
|
1594
1615
|
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1616
|
+
"Unexpected JSON input from \\"keys.json\\".
|
|
1617
|
+
Expected an array of strings but got:
|
|
1618
|
+
12354"
|
|
1619
|
+
`);
|
|
1599
1620
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1600
1621
|
"
|
|
1601
1622
|
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
@@ -1615,12 +1636,12 @@ describe("wrangler", () => {
|
|
|
1615
1636
|
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1616
1637
|
)
|
|
1617
1638
|
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1639
|
+
"Unexpected JSON input from \\"keys.json\\".
|
|
1640
|
+
Expected an array of strings.
|
|
1641
|
+
The item at index 1 is type: \\"number\\" - 12354
|
|
1642
|
+
The item at index 2 is type: \\"object\\" - {\\"key\\":\\"someKey\\"}
|
|
1643
|
+
The item at index 3 is type: \\"object\\" - null"
|
|
1644
|
+
`);
|
|
1624
1645
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1625
1646
|
"
|
|
1626
1647
|
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
@@ -4,6 +4,7 @@ import { version as wranglerVersion } from "../../package.json";
|
|
|
4
4
|
import { purgeConfigCaches, saveToConfigCache } from "../config-cache";
|
|
5
5
|
import { logger } from "../logger";
|
|
6
6
|
import { getMetricsDispatcher, getMetricsConfig } from "../metrics";
|
|
7
|
+
import { CI } from "../metrics/is-ci";
|
|
7
8
|
import {
|
|
8
9
|
CURRENT_METRICS_DATE,
|
|
9
10
|
readMetricsConfig,
|
|
@@ -200,13 +201,42 @@ describe("metrics", () => {
|
|
|
200
201
|
});
|
|
201
202
|
|
|
202
203
|
describe("getMetricsConfig()", () => {
|
|
204
|
+
let isCISpy: jest.SpyInstance;
|
|
205
|
+
|
|
203
206
|
const { setIsTTY } = useMockIsTTY();
|
|
204
207
|
beforeEach(() => {
|
|
205
208
|
// Default the mock TTY to interactive for all these tests.
|
|
206
209
|
setIsTTY(true);
|
|
210
|
+
isCISpy = jest.spyOn(CI, "isCI").mockReturnValue(false);
|
|
207
211
|
});
|
|
208
212
|
|
|
209
213
|
describe("enabled", () => {
|
|
214
|
+
const ORIGINAL_ENV = process.env;
|
|
215
|
+
beforeEach(() => {
|
|
216
|
+
process.env = { ...ORIGINAL_ENV };
|
|
217
|
+
});
|
|
218
|
+
afterEach(() => {
|
|
219
|
+
process.env = ORIGINAL_ENV;
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("should return the WRANGLER_SEND_METRICS environment variable for enabled if it is defined", async () => {
|
|
223
|
+
process.env.WRANGLER_SEND_METRICS = "false";
|
|
224
|
+
expect(await getMetricsConfig({})).toMatchObject({
|
|
225
|
+
enabled: false,
|
|
226
|
+
});
|
|
227
|
+
process.env.WRANGLER_SEND_METRICS = "true";
|
|
228
|
+
expect(await getMetricsConfig({})).toMatchObject({
|
|
229
|
+
enabled: true,
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("should return false if running in a CI environment", async () => {
|
|
234
|
+
isCISpy.mockReturnValue(true);
|
|
235
|
+
expect(await getMetricsConfig({})).toMatchObject({
|
|
236
|
+
enabled: false,
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
210
240
|
it("should return the sendMetrics argument for enabled if it is defined", async () => {
|
|
211
241
|
expect(
|
|
212
242
|
await getMetricsConfig({ sendMetrics: false, offline: false })
|
|
@@ -6108,6 +6108,82 @@ addEventListener('fetch', event => {});`
|
|
|
6108
6108
|
expect(fs.readFileSync("dist/index.js", "utf-8")).toMatch(scriptContent);
|
|
6109
6109
|
});
|
|
6110
6110
|
});
|
|
6111
|
+
|
|
6112
|
+
describe("--no-bundle --minify", () => {
|
|
6113
|
+
it("should warn that no-bundle and minify can't be used together", async () => {
|
|
6114
|
+
writeWranglerToml();
|
|
6115
|
+
const scriptContent = `
|
|
6116
|
+
const xyz = 123; // a statement that would otherwise be compiled out
|
|
6117
|
+
`;
|
|
6118
|
+
fs.writeFileSync("index.js", scriptContent);
|
|
6119
|
+
await runWrangler(
|
|
6120
|
+
"publish index.js --no-bundle --minify --dry-run --outdir dist"
|
|
6121
|
+
);
|
|
6122
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
6123
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1m\`--minify\` and \`--no-bundle\` can't be used together. If you want to minify your Worker and disable Wrangler's bundling, please minify as part of your own bundling process.[0m
|
|
6124
|
+
|
|
6125
|
+
"
|
|
6126
|
+
`);
|
|
6127
|
+
});
|
|
6128
|
+
|
|
6129
|
+
it("should warn that no-bundle and minify can't be used together", async () => {
|
|
6130
|
+
writeWranglerToml({
|
|
6131
|
+
no_bundle: true,
|
|
6132
|
+
minify: true,
|
|
6133
|
+
});
|
|
6134
|
+
const scriptContent = `
|
|
6135
|
+
const xyz = 123; // a statement that would otherwise be compiled out
|
|
6136
|
+
`;
|
|
6137
|
+
fs.writeFileSync("index.js", scriptContent);
|
|
6138
|
+
await runWrangler("publish index.js --dry-run --outdir dist");
|
|
6139
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
6140
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1m\`--minify\` and \`--no-bundle\` can't be used together. If you want to minify your Worker and disable Wrangler's bundling, please minify as part of your own bundling process.[0m
|
|
6141
|
+
|
|
6142
|
+
"
|
|
6143
|
+
`);
|
|
6144
|
+
});
|
|
6145
|
+
});
|
|
6146
|
+
|
|
6147
|
+
describe("--no-bundle --node-compat", () => {
|
|
6148
|
+
it("should warn that no-bundle and node-compat can't be used together", async () => {
|
|
6149
|
+
writeWranglerToml();
|
|
6150
|
+
const scriptContent = `
|
|
6151
|
+
const xyz = 123; // a statement that would otherwise be compiled out
|
|
6152
|
+
`;
|
|
6153
|
+
fs.writeFileSync("index.js", scriptContent);
|
|
6154
|
+
await runWrangler(
|
|
6155
|
+
"publish index.js --no-bundle --node-compat --dry-run --outdir dist"
|
|
6156
|
+
);
|
|
6157
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
6158
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
|
|
6159
|
+
|
|
6160
|
+
|
|
6161
|
+
[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1m\`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process.[0m
|
|
6162
|
+
|
|
6163
|
+
"
|
|
6164
|
+
`);
|
|
6165
|
+
});
|
|
6166
|
+
|
|
6167
|
+
it("should warn that no-bundle and node-compat can't be used together", async () => {
|
|
6168
|
+
writeWranglerToml({
|
|
6169
|
+
no_bundle: true,
|
|
6170
|
+
node_compat: true,
|
|
6171
|
+
});
|
|
6172
|
+
const scriptContent = `
|
|
6173
|
+
const xyz = 123; // a statement that would otherwise be compiled out
|
|
6174
|
+
`;
|
|
6175
|
+
fs.writeFileSync("index.js", scriptContent);
|
|
6176
|
+
await runWrangler("publish index.js --dry-run --outdir dist");
|
|
6177
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
6178
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
|
|
6179
|
+
|
|
6180
|
+
|
|
6181
|
+
[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1m\`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process.[0m
|
|
6182
|
+
|
|
6183
|
+
"
|
|
6184
|
+
`);
|
|
6185
|
+
});
|
|
6186
|
+
});
|
|
6111
6187
|
});
|
|
6112
6188
|
|
|
6113
6189
|
/** Write mock assets to the file system so they can be uploaded. */
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { version } from "./../../package.json";
|
|
2
|
+
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
3
|
+
import { useMockIsTTY } from "./helpers/mock-istty";
|
|
4
|
+
import { runWrangler } from "./helpers/run-wrangler";
|
|
5
|
+
|
|
6
|
+
describe("version", () => {
|
|
7
|
+
const std = mockConsoleMethods();
|
|
8
|
+
const { setIsTTY } = useMockIsTTY();
|
|
9
|
+
|
|
10
|
+
// We cannot test output of version banner,
|
|
11
|
+
// as it is disabled in jest environments
|
|
12
|
+
|
|
13
|
+
// it("should output version banner", async () => {
|
|
14
|
+
// await runWrangler("-v");
|
|
15
|
+
// expect(std.out).toMatchInlineSnapshot(`
|
|
16
|
+
// " ⛅️ wrangler 2.0.22
|
|
17
|
+
// [38;5;214m--------------------[39m"
|
|
18
|
+
// `);
|
|
19
|
+
// });
|
|
20
|
+
|
|
21
|
+
it("should output current version if !isTTY calling -v", async () => {
|
|
22
|
+
setIsTTY(false);
|
|
23
|
+
|
|
24
|
+
await runWrangler("-v");
|
|
25
|
+
expect(std.out).toMatch(version);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// This run separately as command handling is different
|
|
29
|
+
it("should output current version if !isTTY calling --version", async () => {
|
|
30
|
+
setIsTTY(false);
|
|
31
|
+
|
|
32
|
+
await runWrangler("--version");
|
|
33
|
+
expect(std.out).toMatch(version);
|
|
34
|
+
});
|
|
35
|
+
});
|