@@ -270,7 +270,10 @@ describe("autoconfig (deploy)", () => {
270270 },
271271 "assets": {
272272 "directory": "dist"
273- }
273+ },
274+ "compatibility_flags": [
275+ "nodejs_compat"
276+ ]
274277 }
275278
276279 🛠️ Configuring project for Fake
@@ -288,7 +291,10 @@ describe("autoconfig (deploy)", () => {
288291 },
289292 "assets": {
290293 "directory": "dist"
291- }
294+ },
295+ "compatibility_flags": [
296+ "nodejs_compat"
297+ ]
292298 }
293299 "
294300 ` ) ;
@@ -440,7 +446,10 @@ describe("autoconfig (deploy)", () => {
440446 },
441447 "assets": {
442448 "directory": "dist"
443- }
449+ },
450+ "compatibility_flags": [
451+ "nodejs_compat"
452+ ]
444453 }
445454 "
446455 ` ) ;
@@ -455,7 +464,10 @@ describe("autoconfig (deploy)", () => {
455464 },
456465 "assets": {
457466 "directory": "dist"
458- }
467+ },
468+ "compatibility_flags": [
469+ "nodejs_compat"
470+ ]
459471 }
460472 "
461473 ` ) ;
@@ -595,5 +607,151 @@ describe("autoconfig (deploy)", () => {
595607 `[Error: The detected framework ("Some Unsupported Framework") cannot be automatically configured.]`
596608 ) ;
597609 } ) ;
610+
611+ describe ( "nodejs_compat compatibility flag" , ( ) => {
612+ it ( "should add nodejs_compat when framework specifies no compatibility flags" , async ( ) => {
613+ mockConfirm ( {
614+ text : "Do you want to modify these settings?" ,
615+ result : false ,
616+ } ) ;
617+ mockConfirm ( {
618+ text : "Proceed with setup?" ,
619+ result : true ,
620+ } ) ;
621+
622+ await run . runAutoConfig ( {
623+ projectPath : process . cwd ( ) ,
624+ workerName : "my-worker" ,
625+ configured : false ,
626+ outputDir : "dist" ,
627+ framework : {
628+ id : "no-flags-framework" ,
629+ name : "No Flags Framework" ,
630+ autoConfigSupported : true ,
631+ configure : async ( ) => ( {
632+ wranglerConfig : {
633+ // No compatibility_flags specified
634+ assets : { directory : "dist" } ,
635+ } ,
636+ } ) ,
637+ isConfigured : ( ) => false ,
638+ } ,
639+ packageManager : NpmPackageManager ,
640+ } ) ;
641+
642+ const wranglerConfig = JSON . parse ( readFileSync ( "wrangler.jsonc" ) ) ;
643+ expect ( wranglerConfig . compatibility_flags ) . toEqual ( [ "nodejs_compat" ] ) ;
644+ } ) ;
645+
646+ it ( "should preserve other compatibility flags while adding nodejs_compat" , async ( ) => {
647+ mockConfirm ( {
648+ text : "Do you want to modify these settings?" ,
649+ result : false ,
650+ } ) ;
651+ mockConfirm ( {
652+ text : "Proceed with setup?" ,
653+ result : true ,
654+ } ) ;
655+
656+ await run . runAutoConfig ( {
657+ projectPath : process . cwd ( ) ,
658+ workerName : "my-worker" ,
659+ configured : false ,
660+ outputDir : "dist" ,
661+ framework : {
662+ id : "other-flags-framework" ,
663+ name : "Other Flags Framework" ,
664+ autoConfigSupported : true ,
665+ configure : async ( ) => ( {
666+ wranglerConfig : {
667+ compatibility_flags : [ "global_fetch_strictly_public" ] ,
668+ assets : { directory : "dist" } ,
669+ } ,
670+ } ) ,
671+ isConfigured : ( ) => false ,
672+ } ,
673+ packageManager : NpmPackageManager ,
674+ } ) ;
675+
676+ const wranglerConfig = JSON . parse ( readFileSync ( "wrangler.jsonc" ) ) ;
677+ expect ( wranglerConfig . compatibility_flags ) . toEqual ( [
678+ "global_fetch_strictly_public" ,
679+ "nodejs_compat" ,
680+ ] ) ;
681+ } ) ;
682+
683+ it ( "should not duplicate nodejs_compat if already present" , async ( ) => {
684+ mockConfirm ( {
685+ text : "Do you want to modify these settings?" ,
686+ result : false ,
687+ } ) ;
688+ mockConfirm ( {
689+ text : "Proceed with setup?" ,
690+ result : true ,
691+ } ) ;
692+
693+ await run . runAutoConfig ( {
694+ projectPath : process . cwd ( ) ,
695+ workerName : "my-worker" ,
696+ configured : false ,
697+ outputDir : "dist" ,
698+ framework : {
699+ id : "nodejs-compat-framework" ,
700+ name : "Nodejs Compat Framework" ,
701+ autoConfigSupported : true ,
702+ configure : async ( ) => ( {
703+ wranglerConfig : {
704+ compatibility_flags : [ "nodejs_compat" ] ,
705+ assets : { directory : "dist" } ,
706+ } ,
707+ } ) ,
708+ isConfigured : ( ) => false ,
709+ } ,
710+ packageManager : NpmPackageManager ,
711+ } ) ;
712+
713+ const wranglerConfig = JSON . parse ( readFileSync ( "wrangler.jsonc" ) ) ;
714+ expect ( wranglerConfig . compatibility_flags ) . toEqual ( [ "nodejs_compat" ] ) ;
715+ } ) ;
716+
717+ it ( "should replace nodejs_als with nodejs_compat" , async ( ) => {
718+ mockConfirm ( {
719+ text : "Do you want to modify these settings?" ,
720+ result : false ,
721+ } ) ;
722+ mockConfirm ( {
723+ text : "Proceed with setup?" ,
724+ result : true ,
725+ } ) ;
726+
727+ await run . runAutoConfig ( {
728+ projectPath : process . cwd ( ) ,
729+ workerName : "my-worker" ,
730+ configured : false ,
731+ outputDir : "dist" ,
732+ framework : {
733+ id : "nodejs-als-framework" ,
734+ name : "Nodejs Als Framework" ,
735+ autoConfigSupported : true ,
736+ configure : async ( ) => ( {
737+ wranglerConfig : {
738+ compatibility_flags : [ "nodejs_als" , "some_other_flag" ] ,
739+ assets : { directory : "dist" } ,
740+ } ,
741+ } ) ,
742+ isConfigured : ( ) => false ,
743+ } ,
744+ packageManager : NpmPackageManager ,
745+ } ) ;
746+
747+ const wranglerConfig = JSON . parse ( readFileSync ( "wrangler.jsonc" ) ) ;
748+ // nodejs_als should be removed, nodejs_compat should be added, some_other_flag preserved
749+ expect ( wranglerConfig . compatibility_flags ) . toEqual ( [
750+ "some_other_flag" ,
751+ "nodejs_compat" ,
752+ ] ) ;
753+ expect ( wranglerConfig . compatibility_flags ) . not . toContain ( "nodejs_als" ) ;
754+ } ) ;
755+ } ) ;
598756 } ) ;
599757} ) ;
0 commit comments