wrangler 0.0.0-e492c10 → 0.0.0-e5a3814
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/Cloudflare_CA.pem +18 -0
- package/README.md +1 -1
- package/bin/wrangler.js +36 -4
- package/package.json +9 -5
- package/pages/functions/buildPlugin.ts +13 -0
- package/pages/functions/buildWorker.ts +14 -1
- package/pages/functions/template-plugin.ts +3 -2
- package/src/__tests__/configuration.test.ts +590 -228
- package/src/__tests__/dev.test.tsx +229 -73
- package/src/__tests__/helpers/mock-dialogs.ts +41 -1
- package/src/__tests__/index.test.ts +31 -16
- package/src/__tests__/init.test.ts +252 -131
- package/src/__tests__/kv.test.ts +140 -101
- package/src/__tests__/package-manager.test.ts +154 -7
- package/src/__tests__/pages.test.ts +466 -39
- package/src/__tests__/parse.test.ts +5 -1
- package/src/__tests__/publish.test.ts +1021 -215
- package/src/__tests__/r2.test.ts +47 -24
- package/src/__tests__/secret.test.ts +39 -4
- package/src/__tests__/whoami.test.tsx +34 -0
- package/src/abort.d.ts +3 -0
- package/src/bundle.ts +33 -5
- package/src/cfetch/index.ts +21 -4
- package/src/cfetch/internal.ts +23 -18
- package/src/config/config.ts +1 -1
- package/src/config/environment.ts +41 -15
- package/src/config/index.ts +162 -0
- package/src/config/validation-helpers.ts +10 -1
- package/src/config/validation.ts +205 -77
- package/src/create-worker-preview.ts +32 -22
- package/src/create-worker-upload-form.ts +22 -8
- package/src/dev/dev.tsx +14 -31
- package/src/dev/local.tsx +10 -0
- package/src/dev/remote.tsx +40 -16
- package/src/dialogs.tsx +48 -0
- package/src/durable.ts +102 -0
- package/src/entry.ts +64 -9
- package/src/index.tsx +455 -307
- package/src/inspect.ts +39 -0
- package/src/kv.ts +114 -25
- package/src/open-in-browser.ts +5 -12
- package/src/package-manager.ts +50 -3
- package/src/pages.tsx +381 -163
- package/src/parse.ts +23 -5
- package/src/proxy.ts +55 -26
- package/src/publish.ts +374 -127
- package/src/sites.tsx +61 -28
- package/src/user.tsx +12 -1
- package/src/whoami.tsx +3 -2
- package/src/worker.ts +10 -1
- package/src/zones.ts +73 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.ts +16 -1
- package/templates/static-asset-facade.js +0 -4
- package/wrangler-dist/cli.js +96875 -83512
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
|
@@ -19,7 +19,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
19
19
|
build: {
|
|
20
20
|
command: undefined,
|
|
21
21
|
cwd: undefined,
|
|
22
|
-
watch_dir:
|
|
22
|
+
watch_dir: "./src",
|
|
23
23
|
},
|
|
24
24
|
compatibility_date: undefined,
|
|
25
25
|
compatibility_flags: [],
|
|
@@ -43,6 +43,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
43
43
|
migrations: [],
|
|
44
44
|
name: undefined,
|
|
45
45
|
r2_buckets: [],
|
|
46
|
+
services: [],
|
|
46
47
|
route: undefined,
|
|
47
48
|
routes: undefined,
|
|
48
49
|
rules: [],
|
|
@@ -60,6 +61,8 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
60
61
|
data_blobs: undefined,
|
|
61
62
|
workers_dev: undefined,
|
|
62
63
|
zone_id: undefined,
|
|
64
|
+
minify: undefined,
|
|
65
|
+
node_compat: undefined,
|
|
63
66
|
});
|
|
64
67
|
expect(diagnostics.hasErrors()).toBe(false);
|
|
65
68
|
expect(diagnostics.hasWarnings()).toBe(false);
|
|
@@ -162,68 +165,110 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
162
165
|
`);
|
|
163
166
|
});
|
|
164
167
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
168
|
+
describe("migrations", () => {
|
|
169
|
+
it("should override `migrations` config defaults with provided values", () => {
|
|
170
|
+
const expectedConfig: RawConfig = {
|
|
171
|
+
migrations: [
|
|
172
|
+
{
|
|
173
|
+
tag: "TAG",
|
|
174
|
+
new_classes: ["CLASS_1", "CLASS_2"],
|
|
175
|
+
renamed_classes: [
|
|
176
|
+
{
|
|
177
|
+
from: "FROM_CLASS",
|
|
178
|
+
to: "TO_CLASS",
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
deleted_classes: ["CLASS_3", "CLASS_4"],
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
};
|
|
181
185
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
186
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
187
|
+
expectedConfig,
|
|
188
|
+
undefined,
|
|
189
|
+
{ env: undefined }
|
|
190
|
+
);
|
|
187
191
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
193
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
194
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
195
|
+
});
|
|
192
196
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
197
|
+
it("should error on invalid `migrations` values", () => {
|
|
198
|
+
const expectedConfig = {
|
|
199
|
+
migrations: [
|
|
200
|
+
{
|
|
201
|
+
tag: 111,
|
|
202
|
+
new_classes: [222, 333],
|
|
203
|
+
renamed_classes: [
|
|
204
|
+
{
|
|
205
|
+
from: 444,
|
|
206
|
+
to: 555,
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
deleted_classes: [666, 777],
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
};
|
|
209
213
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
214
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
215
|
+
expectedConfig as unknown as RawConfig,
|
|
216
|
+
undefined,
|
|
217
|
+
{ env: undefined }
|
|
218
|
+
);
|
|
215
219
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
220
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
221
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
222
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
223
|
+
"Processing wrangler configuration:
|
|
224
|
+
- Expected \\"migrations[0].tag\\" to be of type string but got 111.
|
|
225
|
+
- Expected \\"migrations[0].new_classes.[0]\\" to be of type string but got 222.
|
|
226
|
+
- Expected \\"migrations[0].new_classes.[1]\\" to be of type string but got 333.
|
|
227
|
+
- Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
|
|
228
|
+
- Expected \\"migrations[0].deleted_classes.[0]\\" to be of type string but got 666.
|
|
229
|
+
- Expected \\"migrations[0].deleted_classes.[1]\\" to be of type string but got 777."
|
|
230
|
+
`);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("should warn/error on unexpected fields on `migrations`", async () => {
|
|
234
|
+
const expectedConfig = {
|
|
235
|
+
migrations: [
|
|
236
|
+
{
|
|
237
|
+
tag: "TAG",
|
|
238
|
+
new_classes: ["CLASS_1", "CLASS_2"],
|
|
239
|
+
renamed_classes: [
|
|
240
|
+
{
|
|
241
|
+
from: "FROM_CLASS",
|
|
242
|
+
to: "TO_CLASS",
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
a: "something",
|
|
246
|
+
b: "someone",
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
deleted_classes: ["CLASS_3", "CLASS_4"],
|
|
250
|
+
unrecognized_field: "FOO",
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
256
|
+
expectedConfig as unknown as RawConfig,
|
|
257
|
+
undefined,
|
|
258
|
+
{ env: undefined }
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
262
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
263
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
264
|
+
"Processing wrangler configuration:
|
|
265
|
+
- Unexpected fields found in migrations field: \\"unrecognized_field\\""
|
|
266
|
+
`);
|
|
267
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
268
|
+
"Processing wrangler configuration:
|
|
269
|
+
- Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":\\"FROM_CLASS\\",\\"to\\":\\"TO_CLASS\\"},{\\"a\\":\\"something\\",\\"b\\":\\"someone\\"}]."
|
|
270
|
+
`);
|
|
271
|
+
});
|
|
227
272
|
});
|
|
228
273
|
|
|
229
274
|
describe("site", () => {
|
|
@@ -393,6 +438,40 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
393
438
|
expect(diagnostics.hasWarnings()).toBe(false);
|
|
394
439
|
});
|
|
395
440
|
|
|
441
|
+
it("should warn on unexpected fields on `triggers`", async () => {
|
|
442
|
+
const expectedConfig: RawConfig = {
|
|
443
|
+
triggers: {
|
|
444
|
+
crons: ["1 * * * *"],
|
|
445
|
+
// @ts-expect-error we're purposely adding a field
|
|
446
|
+
// that doesn't belong here
|
|
447
|
+
someOtherfield: 123,
|
|
448
|
+
},
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
452
|
+
expectedConfig,
|
|
453
|
+
"project/wrangler.toml",
|
|
454
|
+
{ env: undefined }
|
|
455
|
+
);
|
|
456
|
+
|
|
457
|
+
expect(config).toEqual(
|
|
458
|
+
expect.objectContaining({
|
|
459
|
+
triggers: {
|
|
460
|
+
crons: ["1 * * * *"],
|
|
461
|
+
someOtherfield: 123,
|
|
462
|
+
},
|
|
463
|
+
})
|
|
464
|
+
);
|
|
465
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
466
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
467
|
+
|
|
468
|
+
expect(normalizePath(diagnostics.renderWarnings()))
|
|
469
|
+
.toMatchInlineSnapshot(`
|
|
470
|
+
"Processing project/wrangler.toml configuration:
|
|
471
|
+
- Unexpected fields found in triggers field: \\"someOtherfield\\""
|
|
472
|
+
`);
|
|
473
|
+
});
|
|
474
|
+
|
|
396
475
|
it("should error on invalid `wasm_modules` paths", () => {
|
|
397
476
|
const expectedConfig = {
|
|
398
477
|
wasm_modules: {
|
|
@@ -620,6 +699,12 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
620
699
|
class_name: "CLASS2",
|
|
621
700
|
script_name: "SCRIPT2",
|
|
622
701
|
},
|
|
702
|
+
{
|
|
703
|
+
name: "DO_BINDING_3",
|
|
704
|
+
class_name: "CLASS3",
|
|
705
|
+
script_name: "SCRIPT3",
|
|
706
|
+
environment: "ENV3",
|
|
707
|
+
},
|
|
623
708
|
],
|
|
624
709
|
},
|
|
625
710
|
kv_namespaces: [
|
|
@@ -638,6 +723,13 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
638
723
|
preview_bucket_name: "R2_PREVIEW_2",
|
|
639
724
|
},
|
|
640
725
|
],
|
|
726
|
+
services: [
|
|
727
|
+
{
|
|
728
|
+
binding: "SERVICE_BINDING_1",
|
|
729
|
+
service: "SERVICE_TYPE_1",
|
|
730
|
+
environment: "SERVICE_BINDING_ENVIRONMENT_1",
|
|
731
|
+
},
|
|
732
|
+
],
|
|
641
733
|
unsafe: {
|
|
642
734
|
bindings: [
|
|
643
735
|
{ name: "UNSAFE_BINDING_1", type: "UNSAFE_TYPE_1" },
|
|
@@ -648,6 +740,8 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
648
740
|
},
|
|
649
741
|
],
|
|
650
742
|
},
|
|
743
|
+
minify: true,
|
|
744
|
+
node_compat: true,
|
|
651
745
|
};
|
|
652
746
|
|
|
653
747
|
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
@@ -661,9 +755,19 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
661
755
|
);
|
|
662
756
|
expect(diagnostics.hasErrors()).toBe(false);
|
|
663
757
|
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
758
|
+
"Processing wrangler configuration:
|
|
759
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time.
|
|
760
|
+
- \\"services\\" fields are experimental and may change or break at any time.
|
|
761
|
+
- In wrangler.toml, you have configured [durable_objects] exported by this Worker (CLASS1), but no [migrations] for them. This may not work as expected until you add a [migrations] section to your wrangler.toml. Add this configuration to your wrangler.toml:
|
|
762
|
+
|
|
763
|
+
\`\`\`
|
|
764
|
+
[[migrations]]
|
|
765
|
+
tag = \\"v1\\" # Should be unique for each entry
|
|
766
|
+
new_classes = [\\"CLASS1\\"]
|
|
767
|
+
\`\`\`
|
|
768
|
+
|
|
769
|
+
Refer to https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml for more details."
|
|
770
|
+
`);
|
|
667
771
|
});
|
|
668
772
|
|
|
669
773
|
it("should error on invalid environment values", () => {
|
|
@@ -705,6 +809,8 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
705
809
|
cwd: 1555,
|
|
706
810
|
watch_dir: 1666,
|
|
707
811
|
},
|
|
812
|
+
minify: "INVALID",
|
|
813
|
+
node_compat: "INVALID",
|
|
708
814
|
} as unknown as RawEnvironment;
|
|
709
815
|
|
|
710
816
|
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
@@ -717,8 +823,8 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
717
823
|
expect(diagnostics.hasWarnings()).toBe(false);
|
|
718
824
|
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
719
825
|
"Processing wrangler configuration:
|
|
720
|
-
- Expected \\"route\\" to be either a string, or an object with shape { pattern, zone_id | zone_name }, but got 888.
|
|
721
|
-
- Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, zone_id | zone_name }, but these weren't valid: [
|
|
826
|
+
- Expected \\"route\\" to be either a string, or an object with shape { pattern, custom_domain, zone_id | zone_name }, but got 888.
|
|
827
|
+
- Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, custom_domain, zone_id | zone_name }, but these weren't valid: [
|
|
722
828
|
666,
|
|
723
829
|
777,
|
|
724
830
|
{
|
|
@@ -767,175 +873,256 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
767
873
|
- Expected \\"tsconfig\\" to be of type string but got true.
|
|
768
874
|
- Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got 111.
|
|
769
875
|
- Expected \\"main\\" to be of type string but got 1333.
|
|
770
|
-
- Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\".
|
|
876
|
+
- Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\".
|
|
877
|
+
- Expected \\"minify\\" to be of type boolean but got \\"INVALID\\".
|
|
878
|
+
- Expected \\"node_compat\\" to be of type boolean but got \\"INVALID\\"."
|
|
771
879
|
`);
|
|
772
880
|
});
|
|
773
881
|
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
882
|
+
describe("name", () => {
|
|
883
|
+
it("should error on invalid `name` value with spaces", () => {
|
|
884
|
+
const expectedConfig: RawEnvironment = {
|
|
885
|
+
name: "NCC 1701 D",
|
|
886
|
+
} as unknown as RawEnvironment;
|
|
778
887
|
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
888
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
889
|
+
expectedConfig,
|
|
890
|
+
undefined,
|
|
891
|
+
{ env: undefined }
|
|
892
|
+
);
|
|
784
893
|
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
894
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
895
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
896
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
897
|
+
"Processing wrangler configuration:
|
|
898
|
+
- Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"NCC 1701 D\\"."
|
|
899
|
+
`);
|
|
900
|
+
});
|
|
792
901
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
902
|
+
it("should be valid `name` with underscores", () => {
|
|
903
|
+
const expectedConfig: RawEnvironment = {
|
|
904
|
+
name: "enterprise_nx_01",
|
|
905
|
+
} as unknown as RawEnvironment;
|
|
797
906
|
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
907
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
908
|
+
expectedConfig,
|
|
909
|
+
undefined,
|
|
910
|
+
{ env: undefined }
|
|
911
|
+
);
|
|
803
912
|
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
913
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
914
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
915
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
916
|
+
});
|
|
808
917
|
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
918
|
+
it("should error on invalid `name` value with special characters", () => {
|
|
919
|
+
const expectedConfig: RawEnvironment = {
|
|
920
|
+
name: "Thy'lek-Shran",
|
|
921
|
+
} as unknown as RawEnvironment;
|
|
813
922
|
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
923
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
924
|
+
expectedConfig,
|
|
925
|
+
undefined,
|
|
926
|
+
{ env: undefined }
|
|
927
|
+
);
|
|
819
928
|
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
929
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
930
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
931
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
932
|
+
"Processing wrangler configuration:
|
|
933
|
+
- Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"Thy'lek-Shran\\"."
|
|
934
|
+
`);
|
|
935
|
+
});
|
|
827
936
|
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
937
|
+
it("should error on invalid `name` value with only special characters", () => {
|
|
938
|
+
const expectedConfig: RawEnvironment = {
|
|
939
|
+
name: "!@#$%^&*(()",
|
|
940
|
+
} as unknown as RawEnvironment;
|
|
832
941
|
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
942
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
943
|
+
expectedConfig,
|
|
944
|
+
undefined,
|
|
945
|
+
{ env: undefined }
|
|
946
|
+
);
|
|
838
947
|
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
948
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
949
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
950
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
951
|
+
"Processing wrangler configuration:
|
|
952
|
+
- Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"!@#$%^&*(()\\"."
|
|
953
|
+
`);
|
|
954
|
+
});
|
|
845
955
|
});
|
|
846
956
|
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
957
|
+
describe("build", () => {
|
|
958
|
+
it("should override build.upload config defaults with provided values and warn about deprecations", () => {
|
|
959
|
+
const expectedConfig: RawEnvironment = {
|
|
960
|
+
build: {
|
|
961
|
+
upload: {
|
|
962
|
+
dir: "src",
|
|
963
|
+
format: "modules",
|
|
964
|
+
main: "index.ts",
|
|
965
|
+
rules: [{ type: "Text", globs: ["GLOB"], fallthrough: true }],
|
|
966
|
+
},
|
|
855
967
|
},
|
|
856
|
-
}
|
|
857
|
-
};
|
|
968
|
+
};
|
|
858
969
|
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
970
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
971
|
+
expectedConfig,
|
|
972
|
+
path.resolve("project/wrangler.toml"),
|
|
973
|
+
{ env: undefined }
|
|
974
|
+
);
|
|
864
975
|
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
976
|
+
expect(config.main).toEqual(path.resolve("project/src/index.ts"));
|
|
977
|
+
expect(config.build.upload).toBeUndefined();
|
|
978
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
979
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
980
|
+
expect(normalizePath(diagnostics.renderWarnings()))
|
|
981
|
+
.toMatchInlineSnapshot(`
|
|
982
|
+
"Processing project/wrangler.toml configuration:
|
|
983
|
+
- [1mDeprecation[0m: \\"build.upload.format\\":
|
|
984
|
+
The format is inferred automatically from the code.
|
|
985
|
+
- [1mDeprecation[0m: \\"build.upload.main\\":
|
|
986
|
+
Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
|
|
987
|
+
Then add the top level \`main\` field to your configuration file:
|
|
988
|
+
\`\`\`
|
|
989
|
+
main = \\"src/index.ts\\"
|
|
990
|
+
\`\`\`
|
|
991
|
+
- [1mDeprecation[0m: \\"build.upload.dir\\":
|
|
992
|
+
Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the Worker.
|
|
993
|
+
- Deprecation: The \`build.upload.rules\` config field is no longer used, the rules should be specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration file, and add this:
|
|
994
|
+
\`\`\`
|
|
995
|
+
[[rules]]
|
|
996
|
+
type = \\"Text\\"
|
|
997
|
+
globs = [ \\"GLOB\\" ]
|
|
998
|
+
fallthrough = true
|
|
999
|
+
\`\`\`"
|
|
1000
|
+
`);
|
|
1001
|
+
});
|
|
891
1002
|
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
1003
|
+
it("should default custom build watch directories to src", () => {
|
|
1004
|
+
const expectedConfig: RawEnvironment = {
|
|
1005
|
+
build: {
|
|
1006
|
+
command: "execute some --build",
|
|
1007
|
+
},
|
|
1008
|
+
};
|
|
898
1009
|
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
1010
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1011
|
+
expectedConfig,
|
|
1012
|
+
undefined,
|
|
1013
|
+
{ env: undefined }
|
|
1014
|
+
);
|
|
904
1015
|
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
1016
|
+
expect(config.build).toEqual(
|
|
1017
|
+
expect.objectContaining({
|
|
1018
|
+
command: "execute some --build",
|
|
1019
|
+
watch_dir: "./src",
|
|
1020
|
+
})
|
|
1021
|
+
);
|
|
911
1022
|
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
1023
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
1024
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1025
|
+
});
|
|
915
1026
|
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
1027
|
+
it("should resolve custom build watch directories relative to wrangler.toml", async () => {
|
|
1028
|
+
const expectedConfig: RawEnvironment = {
|
|
1029
|
+
build: {
|
|
1030
|
+
command: "execute some --build",
|
|
1031
|
+
watch_dir: "some/path",
|
|
1032
|
+
},
|
|
1033
|
+
};
|
|
923
1034
|
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
1035
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1036
|
+
expectedConfig,
|
|
1037
|
+
"project/wrangler.toml",
|
|
1038
|
+
{ env: undefined }
|
|
1039
|
+
);
|
|
929
1040
|
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
1041
|
+
expect(config.build).toEqual(
|
|
1042
|
+
expect.objectContaining({
|
|
1043
|
+
command: "execute some --build",
|
|
1044
|
+
watch_dir: path.normalize("project/some/path"),
|
|
1045
|
+
})
|
|
1046
|
+
);
|
|
936
1047
|
|
|
937
|
-
|
|
938
|
-
|
|
1048
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
1049
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1050
|
+
});
|
|
1051
|
+
|
|
1052
|
+
it("should allow watch_dir to be an array of paths", () => {
|
|
1053
|
+
const expectedConfig: RawEnvironment = {
|
|
1054
|
+
build: {
|
|
1055
|
+
command: "execute some --build",
|
|
1056
|
+
watch_dir: ["some/path/a", "some/path/b", "some/path/c"],
|
|
1057
|
+
},
|
|
1058
|
+
};
|
|
1059
|
+
|
|
1060
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1061
|
+
expectedConfig,
|
|
1062
|
+
"project/wrangler.toml",
|
|
1063
|
+
{ env: undefined }
|
|
1064
|
+
);
|
|
1065
|
+
|
|
1066
|
+
expect(config.build).toEqual(
|
|
1067
|
+
expect.objectContaining({
|
|
1068
|
+
command: "execute some --build",
|
|
1069
|
+
watch_dir: [
|
|
1070
|
+
path.normalize("project/some/path/a"),
|
|
1071
|
+
path.normalize("project/some/path/b"),
|
|
1072
|
+
path.normalize("project/some/path/c"),
|
|
1073
|
+
],
|
|
1074
|
+
})
|
|
1075
|
+
);
|
|
1076
|
+
|
|
1077
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
1078
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1079
|
+
});
|
|
1080
|
+
|
|
1081
|
+
it("should error when the watch_dir array isn't an array of strings", () => {
|
|
1082
|
+
const expectedConfig: RawEnvironment = {
|
|
1083
|
+
build: {
|
|
1084
|
+
command: "execute some --build",
|
|
1085
|
+
watch_dir: [
|
|
1086
|
+
"some/path/a",
|
|
1087
|
+
"some/path/b",
|
|
1088
|
+
// @ts-expect-error intentionally bad "paths"
|
|
1089
|
+
123,
|
|
1090
|
+
"some/path/c",
|
|
1091
|
+
// @ts-expect-error intentionally bad "paths"
|
|
1092
|
+
false,
|
|
1093
|
+
],
|
|
1094
|
+
},
|
|
1095
|
+
};
|
|
1096
|
+
|
|
1097
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1098
|
+
expectedConfig,
|
|
1099
|
+
"project/wrangler.toml",
|
|
1100
|
+
{ env: undefined }
|
|
1101
|
+
);
|
|
1102
|
+
|
|
1103
|
+
expect(config.build).toEqual(
|
|
1104
|
+
expect.objectContaining({
|
|
1105
|
+
command: "execute some --build",
|
|
1106
|
+
watch_dir: [
|
|
1107
|
+
path.normalize("project/some/path/a"),
|
|
1108
|
+
path.normalize("project/some/path/b"),
|
|
1109
|
+
path.normalize("project/123"),
|
|
1110
|
+
path.normalize("project/some/path/c"),
|
|
1111
|
+
path.normalize("project/false"),
|
|
1112
|
+
],
|
|
1113
|
+
})
|
|
1114
|
+
);
|
|
1115
|
+
|
|
1116
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1117
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
1118
|
+
|
|
1119
|
+
expect(normalizePath(diagnostics.renderErrors()))
|
|
1120
|
+
.toMatchInlineSnapshot(`
|
|
1121
|
+
"Processing project/wrangler.toml configuration:
|
|
1122
|
+
- Expected \\"build.watch_dir.[2]\\" to be of type string but got 123.
|
|
1123
|
+
- Expected \\"build.watch_dir.[4]\\" to be of type string but got false."
|
|
1124
|
+
`);
|
|
1125
|
+
});
|
|
939
1126
|
});
|
|
940
1127
|
|
|
941
1128
|
describe("durable_objects field", () => {
|
|
@@ -1106,13 +1293,29 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
1106
1293
|
durable_objects: {
|
|
1107
1294
|
bindings: [
|
|
1108
1295
|
{},
|
|
1109
|
-
{ name: "
|
|
1296
|
+
{ name: "MISSING_CLASS" },
|
|
1110
1297
|
{ name: 1555, class_name: 1666 },
|
|
1111
1298
|
{
|
|
1112
1299
|
name: 1777,
|
|
1113
1300
|
class_name: 1888,
|
|
1114
1301
|
script_name: 1999,
|
|
1115
1302
|
},
|
|
1303
|
+
{
|
|
1304
|
+
name: "SOMENAME",
|
|
1305
|
+
class_name: "SomeClass",
|
|
1306
|
+
environment: "staging",
|
|
1307
|
+
},
|
|
1308
|
+
{
|
|
1309
|
+
name: 1778,
|
|
1310
|
+
class_name: 1889,
|
|
1311
|
+
script_name: 1992,
|
|
1312
|
+
environment: 2111,
|
|
1313
|
+
},
|
|
1314
|
+
{
|
|
1315
|
+
name: 1772,
|
|
1316
|
+
class_name: 1883,
|
|
1317
|
+
environment: 2112,
|
|
1318
|
+
},
|
|
1116
1319
|
],
|
|
1117
1320
|
},
|
|
1118
1321
|
} as unknown as RawConfig,
|
|
@@ -1126,6 +1329,8 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
1126
1329
|
})
|
|
1127
1330
|
);
|
|
1128
1331
|
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1332
|
+
|
|
1333
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
1129
1334
|
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1130
1335
|
"Processing wrangler configuration:
|
|
1131
1336
|
|
|
@@ -1133,7 +1338,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
1133
1338
|
- binding should have a string \\"name\\" field.
|
|
1134
1339
|
- binding should have a string \\"class_name\\" field.
|
|
1135
1340
|
|
|
1136
|
-
- \\"durable_objects.bindings[1]\\": {\\"name\\":\\"
|
|
1341
|
+
- \\"durable_objects.bindings[1]\\": {\\"name\\":\\"MISSING_CLASS\\"}
|
|
1137
1342
|
- binding should have a string \\"class_name\\" field.
|
|
1138
1343
|
|
|
1139
1344
|
- \\"durable_objects.bindings[2]\\": {\\"name\\":1555,\\"class_name\\":1666}
|
|
@@ -1143,7 +1348,22 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
1143
1348
|
- \\"durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
|
|
1144
1349
|
- binding should have a string \\"name\\" field.
|
|
1145
1350
|
- binding should have a string \\"class_name\\" field.
|
|
1146
|
-
-
|
|
1351
|
+
- the field \\"script_name\\", when present, should be a string.
|
|
1352
|
+
|
|
1353
|
+
- \\"durable_objects.bindings[4]\\": {\\"name\\":\\"SOMENAME\\",\\"class_name\\":\\"SomeClass\\",\\"environment\\":\\"staging\\"}
|
|
1354
|
+
- binding should have a \\"script_name\\" field if \\"environment\\" is present.
|
|
1355
|
+
|
|
1356
|
+
- \\"durable_objects.bindings[5]\\": {\\"name\\":1778,\\"class_name\\":1889,\\"script_name\\":1992,\\"environment\\":2111}
|
|
1357
|
+
- binding should have a string \\"name\\" field.
|
|
1358
|
+
- binding should have a string \\"class_name\\" field.
|
|
1359
|
+
- the field \\"script_name\\", when present, should be a string.
|
|
1360
|
+
- the field \\"environment\\", when present, should be a string.
|
|
1361
|
+
|
|
1362
|
+
- \\"durable_objects.bindings[6]\\": {\\"name\\":1772,\\"class_name\\":1883,\\"environment\\":2112}
|
|
1363
|
+
- binding should have a string \\"name\\" field.
|
|
1364
|
+
- binding should have a string \\"class_name\\" field.
|
|
1365
|
+
- the field \\"environment\\", when present, should be a string.
|
|
1366
|
+
- binding should have a \\"script_name\\" field if \\"environment\\" is present."
|
|
1147
1367
|
`);
|
|
1148
1368
|
});
|
|
1149
1369
|
});
|
|
@@ -1358,6 +1578,151 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
1358
1578
|
});
|
|
1359
1579
|
});
|
|
1360
1580
|
|
|
1581
|
+
describe("services field", () => {
|
|
1582
|
+
it("should error if services is an object", () => {
|
|
1583
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1584
|
+
{ services: {} } as unknown as RawConfig,
|
|
1585
|
+
undefined,
|
|
1586
|
+
{ env: undefined }
|
|
1587
|
+
);
|
|
1588
|
+
|
|
1589
|
+
expect(config).toEqual(
|
|
1590
|
+
expect.not.objectContaining({ services: expect.anything })
|
|
1591
|
+
);
|
|
1592
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
1593
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
1594
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1595
|
+
"Processing wrangler configuration:
|
|
1596
|
+
- \\"services\\" fields are experimental and may change or break at any time."
|
|
1597
|
+
`);
|
|
1598
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1599
|
+
"Processing wrangler configuration:
|
|
1600
|
+
- The field \\"services\\" should be an array but got {}."
|
|
1601
|
+
`);
|
|
1602
|
+
});
|
|
1603
|
+
|
|
1604
|
+
it("should error if services is a string", () => {
|
|
1605
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1606
|
+
{ services: "BAD" } as unknown as RawConfig,
|
|
1607
|
+
undefined,
|
|
1608
|
+
{ env: undefined }
|
|
1609
|
+
);
|
|
1610
|
+
|
|
1611
|
+
expect(config).toEqual(
|
|
1612
|
+
expect.not.objectContaining({ services: expect.anything })
|
|
1613
|
+
);
|
|
1614
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
1615
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
1616
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1617
|
+
"Processing wrangler configuration:
|
|
1618
|
+
- \\"services\\" fields are experimental and may change or break at any time."
|
|
1619
|
+
`);
|
|
1620
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1621
|
+
"Processing wrangler configuration:
|
|
1622
|
+
- The field \\"services\\" should be an array but got \\"BAD\\"."
|
|
1623
|
+
`);
|
|
1624
|
+
});
|
|
1625
|
+
|
|
1626
|
+
it("should error if services is a number", () => {
|
|
1627
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1628
|
+
{ services: 999 } as unknown as RawConfig,
|
|
1629
|
+
undefined,
|
|
1630
|
+
{ env: undefined }
|
|
1631
|
+
);
|
|
1632
|
+
|
|
1633
|
+
expect(config).toEqual(
|
|
1634
|
+
expect.not.objectContaining({ services: expect.anything })
|
|
1635
|
+
);
|
|
1636
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
1637
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
1638
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1639
|
+
"Processing wrangler configuration:
|
|
1640
|
+
- \\"services\\" fields are experimental and may change or break at any time."
|
|
1641
|
+
`);
|
|
1642
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1643
|
+
"Processing wrangler configuration:
|
|
1644
|
+
- The field \\"services\\" should be an array but got 999."
|
|
1645
|
+
`);
|
|
1646
|
+
});
|
|
1647
|
+
|
|
1648
|
+
it("should error if services is null", () => {
|
|
1649
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1650
|
+
{ services: null } as unknown as RawConfig,
|
|
1651
|
+
undefined,
|
|
1652
|
+
{ env: undefined }
|
|
1653
|
+
);
|
|
1654
|
+
|
|
1655
|
+
expect(config).toEqual(
|
|
1656
|
+
expect.not.objectContaining({ services: expect.anything })
|
|
1657
|
+
);
|
|
1658
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
1659
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
1660
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1661
|
+
"Processing wrangler configuration:
|
|
1662
|
+
- \\"services\\" fields are experimental and may change or break at any time."
|
|
1663
|
+
`);
|
|
1664
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1665
|
+
"Processing wrangler configuration:
|
|
1666
|
+
- The field \\"services\\" should be an array but got null."
|
|
1667
|
+
`);
|
|
1668
|
+
});
|
|
1669
|
+
|
|
1670
|
+
it("should error if services bindings are not valid", () => {
|
|
1671
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1672
|
+
{
|
|
1673
|
+
services: [
|
|
1674
|
+
{},
|
|
1675
|
+
{ binding: "SERVICE_BINDING_1" },
|
|
1676
|
+
{ binding: 123, service: 456 },
|
|
1677
|
+
{ binding: 123, service: 456, environment: 789 },
|
|
1678
|
+
{ binding: "SERVICE_BINDING_1", service: 456, environment: 789 },
|
|
1679
|
+
{
|
|
1680
|
+
binding: 123,
|
|
1681
|
+
service: "SERVICE_BINDING_SERVICE_1",
|
|
1682
|
+
environment: 789,
|
|
1683
|
+
},
|
|
1684
|
+
{
|
|
1685
|
+
binding: 123,
|
|
1686
|
+
service: 456,
|
|
1687
|
+
environment: "SERVICE_BINDING_ENVIRONMENT_1",
|
|
1688
|
+
},
|
|
1689
|
+
],
|
|
1690
|
+
} as unknown as RawConfig,
|
|
1691
|
+
undefined,
|
|
1692
|
+
{ env: undefined }
|
|
1693
|
+
);
|
|
1694
|
+
|
|
1695
|
+
expect(config).toEqual(
|
|
1696
|
+
expect.not.objectContaining({
|
|
1697
|
+
services: { bindings: expect.anything },
|
|
1698
|
+
})
|
|
1699
|
+
);
|
|
1700
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
1701
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
1702
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1703
|
+
"Processing wrangler configuration:
|
|
1704
|
+
- \\"services\\" fields are experimental and may change or break at any time."
|
|
1705
|
+
`);
|
|
1706
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1707
|
+
"Processing wrangler configuration:
|
|
1708
|
+
- \\"services[0]\\" bindings should have a string \\"binding\\" field but got {}.
|
|
1709
|
+
- \\"services[0]\\" bindings should have a string \\"service\\" field but got {}.
|
|
1710
|
+
- \\"services[1]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":\\"SERVICE_BINDING_1\\"}.
|
|
1711
|
+
- \\"services[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456}.
|
|
1712
|
+
- \\"services[2]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":123,\\"service\\":456}.
|
|
1713
|
+
- \\"services[3]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":789}.
|
|
1714
|
+
- \\"services[3]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":789}.
|
|
1715
|
+
- \\"services[3]\\" bindings should have a string \\"environment\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":789}.
|
|
1716
|
+
- \\"services[4]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":\\"SERVICE_BINDING_1\\",\\"service\\":456,\\"environment\\":789}.
|
|
1717
|
+
- \\"services[4]\\" bindings should have a string \\"environment\\" field but got {\\"binding\\":\\"SERVICE_BINDING_1\\",\\"service\\":456,\\"environment\\":789}.
|
|
1718
|
+
- \\"services[5]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":\\"SERVICE_BINDING_SERVICE_1\\",\\"environment\\":789}.
|
|
1719
|
+
- \\"services[5]\\" bindings should have a string \\"environment\\" field but got {\\"binding\\":123,\\"service\\":\\"SERVICE_BINDING_SERVICE_1\\",\\"environment\\":789}.
|
|
1720
|
+
- \\"services[6]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":\\"SERVICE_BINDING_ENVIRONMENT_1\\"}.
|
|
1721
|
+
- \\"services[6]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":\\"SERVICE_BINDING_ENVIRONMENT_1\\"}."
|
|
1722
|
+
`);
|
|
1723
|
+
});
|
|
1724
|
+
});
|
|
1725
|
+
|
|
1361
1726
|
describe("unsafe field", () => {
|
|
1362
1727
|
it("should error if unsafe is an array", () => {
|
|
1363
1728
|
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
@@ -1622,14 +1987,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
1622
1987
|
- [1mDeprecation[0m: \\"zone_id\\":
|
|
1623
1988
|
This is unnecessary since we can deduce this from routes directly.
|
|
1624
1989
|
- [1mDeprecation[0m: \\"experimental_services\\":
|
|
1625
|
-
The \\"experimental_services\\" field is no longer supported.
|
|
1626
|
-
\`\`\`
|
|
1627
|
-
[[unsafe.bindings]]
|
|
1628
|
-
name = \\"mock-name\\"
|
|
1629
|
-
type = \\"service\\"
|
|
1630
|
-
service = \\"SERVICE\\"
|
|
1631
|
-
environment = \\"ENV\\"
|
|
1632
|
-
\`\`\`"
|
|
1990
|
+
The \\"experimental_services\\" field is no longer supported. Simply rename the [experimental_services] field to [services]."
|
|
1633
1991
|
`);
|
|
1634
1992
|
});
|
|
1635
1993
|
});
|
|
@@ -1722,6 +2080,8 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
1722
2080
|
cwd: "CWD",
|
|
1723
2081
|
watch_dir: "WATCH_DIR",
|
|
1724
2082
|
},
|
|
2083
|
+
minify: true,
|
|
2084
|
+
node_compat: true,
|
|
1725
2085
|
};
|
|
1726
2086
|
|
|
1727
2087
|
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
@@ -1762,6 +2122,8 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
1762
2122
|
cwd: "ENV_CWD",
|
|
1763
2123
|
watch_dir: "ENV_WATCH_DIR",
|
|
1764
2124
|
},
|
|
2125
|
+
minify: false,
|
|
2126
|
+
node_compat: false,
|
|
1765
2127
|
};
|
|
1766
2128
|
const rawConfig: RawConfig = {
|
|
1767
2129
|
name: "mock-name",
|
|
@@ -1781,6 +2143,8 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
1781
2143
|
cwd: "CWD",
|
|
1782
2144
|
watch_dir: "WATCH_DIR",
|
|
1783
2145
|
},
|
|
2146
|
+
minify: true,
|
|
2147
|
+
node_compat: true,
|
|
1784
2148
|
env: {
|
|
1785
2149
|
ENV1: rawEnv,
|
|
1786
2150
|
},
|
|
@@ -2031,6 +2395,8 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
2031
2395
|
cwd: 1555,
|
|
2032
2396
|
watch_dir: 1666,
|
|
2033
2397
|
},
|
|
2398
|
+
minify: "INVALID",
|
|
2399
|
+
node_compat: "INVALID",
|
|
2034
2400
|
} as unknown as RawEnvironment;
|
|
2035
2401
|
|
|
2036
2402
|
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
@@ -2045,8 +2411,8 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
2045
2411
|
"Processing wrangler configuration:
|
|
2046
2412
|
|
|
2047
2413
|
- \\"env.ENV1\\" environment configuration
|
|
2048
|
-
- Expected \\"route\\" to be either a string, or an object with shape { pattern, zone_id | zone_name }, but got 888.
|
|
2049
|
-
- Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, zone_id | zone_name }, but these weren't valid: [
|
|
2414
|
+
- Expected \\"route\\" to be either a string, or an object with shape { pattern, custom_domain, zone_id | zone_name }, but got 888.
|
|
2415
|
+
- Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, custom_domain, zone_id | zone_name }, but these weren't valid: [
|
|
2050
2416
|
666,
|
|
2051
2417
|
777
|
|
2052
2418
|
].
|
|
@@ -2063,7 +2429,9 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
2063
2429
|
- Expected \\"tsconfig\\" to be of type string but got 123.
|
|
2064
2430
|
- Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got 111.
|
|
2065
2431
|
- Expected \\"main\\" to be of type string but got 1333.
|
|
2066
|
-
- Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\".
|
|
2432
|
+
- Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\".
|
|
2433
|
+
- Expected \\"minify\\" to be of type boolean but got \\"INVALID\\".
|
|
2434
|
+
- Expected \\"node_compat\\" to be of type boolean but got \\"INVALID\\"."
|
|
2067
2435
|
`);
|
|
2068
2436
|
});
|
|
2069
2437
|
|
|
@@ -2285,6 +2653,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
2285
2653
|
})
|
|
2286
2654
|
);
|
|
2287
2655
|
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2656
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
2288
2657
|
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2289
2658
|
"Processing wrangler configuration:
|
|
2290
2659
|
|
|
@@ -2304,7 +2673,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
2304
2673
|
- \\"env.ENV1.durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
|
|
2305
2674
|
- binding should have a string \\"name\\" field.
|
|
2306
2675
|
- binding should have a string \\"class_name\\" field.
|
|
2307
|
-
-
|
|
2676
|
+
- the field \\"script_name\\", when present, should be a string."
|
|
2308
2677
|
`);
|
|
2309
2678
|
});
|
|
2310
2679
|
});
|
|
@@ -2869,14 +3238,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
2869
3238
|
- [1mDeprecation[0m: \\"zone_id\\":
|
|
2870
3239
|
This is unnecessary since we can deduce this from routes directly.
|
|
2871
3240
|
- [1mDeprecation[0m: \\"experimental_services\\":
|
|
2872
|
-
The \\"experimental_services\\" field is no longer supported.
|
|
2873
|
-
\`\`\`
|
|
2874
|
-
[[unsafe.bindings]]
|
|
2875
|
-
name = \\"mock-name\\"
|
|
2876
|
-
type = \\"service\\"
|
|
2877
|
-
service = \\"SERVICE\\"
|
|
2878
|
-
environment = \\"ENV\\"
|
|
2879
|
-
\`\`\`"
|
|
3241
|
+
The \\"experimental_services\\" field is no longer supported. Simply rename the [experimental_services] field to [services]."
|
|
2880
3242
|
`);
|
|
2881
3243
|
});
|
|
2882
3244
|
});
|