@@ -6396,6 +6396,154 @@ describe("normalizeAndValidateConfig()", () => {
63966396 expect ( result2 . diagnostics . hasWarnings ( ) ) . toBe ( false ) ;
63976397 } ) ;
63986398 } ) ;
6399+
6400+ describe ( "[assets]" , ( ) => {
6401+ it ( "should inherit from top-level assets" , ( ) => {
6402+ const rawConfig : RawConfig = {
6403+ assets : {
6404+ directory : "dist" ,
6405+ binding : "ASSETS" ,
6406+ } ,
6407+ env : {
6408+ ENV1 : { } ,
6409+ } ,
6410+ } ;
6411+
6412+ const { config, diagnostics } = normalizeAndValidateConfig (
6413+ rawConfig ,
6414+ undefined ,
6415+ undefined ,
6416+ { env : "ENV1" }
6417+ ) ;
6418+
6419+ expect ( config ) . toEqual (
6420+ expect . objectContaining ( {
6421+ assets : {
6422+ directory : "dist" ,
6423+ binding : "ASSETS" ,
6424+ } ,
6425+ } )
6426+ ) ;
6427+ expect ( diagnostics . hasErrors ( ) ) . toBe ( false ) ;
6428+ expect ( diagnostics . hasWarnings ( ) ) . toBe ( false ) ;
6429+ } ) ;
6430+
6431+ it ( "should resolve assets in named env with top-level env also including assets" , ( ) => {
6432+ const rawConfig : RawConfig = {
6433+ assets : {
6434+ directory : "dist" ,
6435+ binding : "ASSETS" ,
6436+ } ,
6437+ env : {
6438+ ENV1 : {
6439+ assets : {
6440+ directory : "public" ,
6441+ binding : "ASSETS" ,
6442+ run_worker_first : true ,
6443+ } ,
6444+ } ,
6445+ } ,
6446+ } ;
6447+
6448+ const { config, diagnostics } = normalizeAndValidateConfig (
6449+ rawConfig ,
6450+ undefined ,
6451+ undefined ,
6452+ { env : "ENV1" }
6453+ ) ;
6454+
6455+ expect ( config ) . toEqual (
6456+ expect . objectContaining ( {
6457+ assets : {
6458+ directory : "public" ,
6459+ binding : "ASSETS" ,
6460+ run_worker_first : true ,
6461+ } ,
6462+ } )
6463+ ) ;
6464+ expect ( diagnostics . hasErrors ( ) ) . toBe ( false ) ;
6465+ expect ( diagnostics . hasWarnings ( ) ) . toBe ( false ) ;
6466+ } ) ;
6467+
6468+ it ( "should warn about experimental_serve_directly deprecation from inherited top-level env" , ( ) => {
6469+ const rawConfig : RawConfig = {
6470+ assets : {
6471+ directory : "dist" ,
6472+ binding : "ASSETS" ,
6473+ experimental_serve_directly : false ,
6474+ } ,
6475+ env : {
6476+ ENV1 : { } ,
6477+ } ,
6478+ } ;
6479+
6480+ const { config, diagnostics } = normalizeAndValidateConfig (
6481+ rawConfig ,
6482+ undefined ,
6483+ undefined ,
6484+ { env : "ENV1" }
6485+ ) ;
6486+
6487+ expect ( config ) . toEqual (
6488+ expect . objectContaining ( {
6489+ assets : {
6490+ directory : "dist" ,
6491+ binding : "ASSETS" ,
6492+ experimental_serve_directly : false ,
6493+ } ,
6494+ } )
6495+ ) ;
6496+ expect ( diagnostics . hasErrors ( ) ) . toBe ( false ) ;
6497+ expect ( diagnostics . hasWarnings ( ) ) . toBe ( true ) ;
6498+ expect ( diagnostics . renderWarnings ( ) ) . toMatchInlineSnapshot ( `
6499+ "Processing wrangler configuration:
6500+ - [1mDeprecation[0m: \\"assets.experimental_serve_directly\\":
6501+ The \\"experimental_serve_directly\\" field is not longer supported. Please use run_worker_first.
6502+ Read more: https://developers.cloudflare.com/workers/static-assets/binding/#run_worker_first"
6503+ ` ) ;
6504+ } ) ;
6505+
6506+ it ( "should warn about experimental_serve_directly deprecation from named env" , ( ) => {
6507+ const rawConfig : RawConfig = {
6508+ env : {
6509+ ENV1 : {
6510+ assets : {
6511+ directory : "dist" ,
6512+ binding : "ASSETS" ,
6513+ experimental_serve_directly : false ,
6514+ } ,
6515+ } ,
6516+ } ,
6517+ } ;
6518+
6519+ const { config, diagnostics } = normalizeAndValidateConfig (
6520+ rawConfig ,
6521+ undefined ,
6522+ undefined ,
6523+ { env : "ENV1" }
6524+ ) ;
6525+
6526+ expect ( config ) . toEqual (
6527+ expect . objectContaining ( {
6528+ assets : {
6529+ directory : "dist" ,
6530+ binding : "ASSETS" ,
6531+ experimental_serve_directly : false ,
6532+ } ,
6533+ } )
6534+ ) ;
6535+ expect ( diagnostics . hasErrors ( ) ) . toBe ( false ) ;
6536+ expect ( diagnostics . hasWarnings ( ) ) . toBe ( true ) ;
6537+ expect ( diagnostics . renderWarnings ( ) ) . toMatchInlineSnapshot ( `
6538+ "Processing wrangler configuration:
6539+
6540+ - \\"env.ENV1\\" environment configuration
6541+ - [1mDeprecation[0m: \\"assets.experimental_serve_directly\\":
6542+ The \\"experimental_serve_directly\\" field is not longer supported. Please use run_worker_first.
6543+ Read more: https://developers.cloudflare.com/workers/static-assets/binding/#run_worker_first"
6544+ ` ) ;
6545+ } ) ;
6546+ } ) ;
63996547 } ) ;
64006548} ) ;
64016549
0 commit comments