@@ -283,6 +283,106 @@ describe("normalizeAndValidateConfig()", () => {
283
283
` ) ;
284
284
} ) ;
285
285
286
+ describe ( "compatibility_date" , ( ) => {
287
+ it ( "should allow valid values" , ( ) => {
288
+ const expectedConfig : RawConfig = {
289
+ compatibility_date : "2024-10-01" ,
290
+ } ;
291
+
292
+ const { config, diagnostics } = normalizeAndValidateConfig (
293
+ expectedConfig ,
294
+ undefined ,
295
+ { env : undefined }
296
+ ) ;
297
+
298
+ expect ( config ) . toEqual ( expect . objectContaining ( expectedConfig ) ) ;
299
+ expect ( diagnostics . hasWarnings ( ) ) . toBe ( false ) ;
300
+ expect ( diagnostics . hasErrors ( ) ) . toBe ( false ) ;
301
+ } ) ;
302
+
303
+ it ( "should error for en-dashes" , ( ) => {
304
+ const expectedConfig : RawConfig = {
305
+ compatibility_date : "2024–10–01" , // en-dash
306
+ } ;
307
+
308
+ const result = normalizeAndValidateConfig ( expectedConfig , undefined , {
309
+ env : undefined ,
310
+ } ) ;
311
+
312
+ expect ( result . config ) . toEqual ( expect . objectContaining ( expectedConfig ) ) ;
313
+ expect ( result . diagnostics . hasWarnings ( ) ) . toBe ( false ) ;
314
+ expect ( result . diagnostics . hasErrors ( ) ) . toBe ( true ) ;
315
+
316
+ expect ( normalizeString ( result . diagnostics . renderErrors ( ) ) )
317
+ . toMatchInlineSnapshot ( `
318
+ "Processing wrangler configuration:
319
+ - \\"compatibility_date\\" field should use ISO-8601 accepted hyphens (-) rather than en-dashes (–) or em-dashes (—)."
320
+ ` ) ;
321
+ } ) ;
322
+
323
+ it ( "should error for em-dashes" , ( ) => {
324
+ const expectedConfig = {
325
+ compatibility_date : "2024—10—01" , // em-dash
326
+ } ;
327
+
328
+ const result = normalizeAndValidateConfig ( expectedConfig , undefined , {
329
+ env : undefined ,
330
+ } ) ;
331
+
332
+ expect ( result . config ) . toEqual ( expect . objectContaining ( expectedConfig ) ) ;
333
+ expect ( result . diagnostics . hasWarnings ( ) ) . toBe ( false ) ;
334
+ expect ( result . diagnostics . hasErrors ( ) ) . toBe ( true ) ;
335
+
336
+ expect ( normalizeString ( result . diagnostics . renderErrors ( ) ) )
337
+ . toMatchInlineSnapshot ( `
338
+ "Processing wrangler configuration:
339
+ - \\"compatibility_date\\" field should use ISO-8601 accepted hyphens (-) rather than en-dashes (–) or em-dashes (—)."
340
+ ` ) ;
341
+ } ) ;
342
+
343
+ it ( "should error for invalid date values" , ( ) => {
344
+ const expectedConfig : RawConfig = {
345
+ compatibility_date : "abc" ,
346
+ } ;
347
+
348
+ const { config, diagnostics } = normalizeAndValidateConfig (
349
+ expectedConfig ,
350
+ undefined ,
351
+ { env : undefined }
352
+ ) ;
353
+
354
+ expect ( config ) . toEqual ( expect . objectContaining ( expectedConfig ) ) ;
355
+ expect ( diagnostics . hasErrors ( ) ) . toBe ( true ) ;
356
+
357
+ expect ( normalizeString ( diagnostics . renderErrors ( ) ) )
358
+ . toMatchInlineSnapshot ( `
359
+ "Processing wrangler configuration:
360
+ - \\"compatibility_date\\" field should be a valid ISO-8601 date (YYYY-MM-DD), but got \\"abc\\"."
361
+ ` ) ;
362
+ } ) ;
363
+
364
+ it ( "should error for dates that are both invalid and include en/em dashes" , ( ) => {
365
+ const expectedConfig = {
366
+ compatibility_date : "2024—100—01" , // invalid date + em-dash
367
+ } ;
368
+
369
+ const result = normalizeAndValidateConfig ( expectedConfig , undefined , {
370
+ env : undefined ,
371
+ } ) ;
372
+
373
+ expect ( result . config ) . toEqual ( expect . objectContaining ( expectedConfig ) ) ;
374
+ expect ( result . diagnostics . hasWarnings ( ) ) . toBe ( false ) ;
375
+ expect ( result . diagnostics . hasErrors ( ) ) . toBe ( true ) ;
376
+
377
+ expect ( normalizeString ( result . diagnostics . renderErrors ( ) ) )
378
+ . toMatchInlineSnapshot ( `
379
+ "Processing wrangler configuration:
380
+ - \\"compatibility_date\\" field should use ISO-8601 accepted hyphens (-) rather than en-dashes (–) or em-dashes (—).
381
+ - \\"compatibility_date\\" field should be a valid ISO-8601 date (YYYY-MM-DD), but got \\"2024—100—01\\"."
382
+ ` ) ;
383
+ } ) ;
384
+ } ) ;
385
+
286
386
describe ( "[site]" , ( ) => {
287
387
it ( "should override `site` config defaults with provided values" , ( ) => {
288
388
const expectedConfig : RawConfig = {
0 commit comments