@@ -165,68 +165,110 @@ describe("normalizeAndValidateConfig()", () => {
165
165
` ) ;
166
166
} ) ;
167
167
168
- it ( "should override `migrations` config defaults with provided values" , ( ) => {
169
- const expectedConfig : RawConfig = {
170
- migrations : [
171
- {
172
- tag : "TAG" ,
173
- new_classes : [ "CLASS_1" , "CLASS_2" ] ,
174
- renamed_classes : [
175
- {
176
- from : "FROM_CLASS" ,
177
- to : "TO_CLASS" ,
178
- } ,
179
- ] ,
180
- deleted_classes : [ "CLASS_3" , "CLASS_4" ] ,
181
- } ,
182
- ] ,
183
- } ;
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
+ } ;
184
185
185
- const { config, diagnostics } = normalizeAndValidateConfig (
186
- expectedConfig ,
187
- undefined ,
188
- { env : undefined }
189
- ) ;
186
+ const { config, diagnostics } = normalizeAndValidateConfig (
187
+ expectedConfig ,
188
+ undefined ,
189
+ { env : undefined }
190
+ ) ;
190
191
191
- expect ( config ) . toEqual ( expect . objectContaining ( expectedConfig ) ) ;
192
- expect ( diagnostics . hasErrors ( ) ) . toBe ( false ) ;
193
- expect ( diagnostics . hasWarnings ( ) ) . toBe ( false ) ;
194
- } ) ;
192
+ expect ( config ) . toEqual ( expect . objectContaining ( expectedConfig ) ) ;
193
+ expect ( diagnostics . hasErrors ( ) ) . toBe ( false ) ;
194
+ expect ( diagnostics . hasWarnings ( ) ) . toBe ( false ) ;
195
+ } ) ;
195
196
196
- it ( "should error on invalid `migrations` values" , ( ) => {
197
- const expectedConfig = {
198
- migrations : [
199
- {
200
- tag : 111 ,
201
- new_classes : [ 222 , 333 ] ,
202
- renamed_classes : [
203
- {
204
- from : 444 ,
205
- to : 555 ,
206
- } ,
207
- ] ,
208
- deleted_classes : [ 666 , 777 ] ,
209
- } ,
210
- ] ,
211
- } ;
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
+ } ;
212
213
213
- const { config, diagnostics } = normalizeAndValidateConfig (
214
- expectedConfig as unknown as RawConfig ,
215
- undefined ,
216
- { env : undefined }
217
- ) ;
214
+ const { config, diagnostics } = normalizeAndValidateConfig (
215
+ expectedConfig as unknown as RawConfig ,
216
+ undefined ,
217
+ { env : undefined }
218
+ ) ;
218
219
219
- expect ( config ) . toEqual ( expect . objectContaining ( expectedConfig ) ) ;
220
- expect ( diagnostics . hasWarnings ( ) ) . toBe ( false ) ;
221
- expect ( diagnostics . renderErrors ( ) ) . toMatchInlineSnapshot ( `
222
- "Processing wrangler configuration:
223
- - Expected \\"migrations[0].tag\\" to be of type string but got 111.
224
- - Expected \\"migrations[0].new_classes.[0]\\" to be of type string but got 222.
225
- - Expected \\"migrations[0].new_classes.[1]\\" to be of type string but got 333.
226
- - Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
227
- - Expected \\"migrations[0].deleted_classes.[0]\\" to be of type string but got 666.
228
- - Expected \\"migrations[0].deleted_classes.[1]\\" to be of type string but got 777."
229
- ` ) ;
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
+ } ) ;
230
272
} ) ;
231
273
232
274
describe ( "site" , ( ) => {
0 commit comments