@@ -3327,3 +3327,62 @@ test("Miniflare: custom Node outbound service", async (t) => {
33273327 `Response from custom Node outbound service. The value of "custom-header" is "foo".`
33283328 ) ;
33293329} ) ;
3330+
3331+ test ( "Miniflare: MINIFLARE_WORKERD_CONFIG_DEBUG controls workerd config file creation" , async ( t ) => {
3332+ const originalEnv = process . env . MINIFLARE_WORKERD_CONFIG_DEBUG ;
3333+ const configFilePath = "workerd-config.json" ;
3334+
3335+ // Clean up any existing config file
3336+ if ( existsSync ( configFilePath ) ) {
3337+ await fs . unlink ( configFilePath ) ;
3338+ }
3339+
3340+ t . teardown ( async ( ) => {
3341+ if ( originalEnv === undefined ) {
3342+ delete process . env . MINIFLARE_WORKERD_CONFIG_DEBUG ;
3343+ } else {
3344+ process . env . MINIFLARE_WORKERD_CONFIG_DEBUG = originalEnv ;
3345+ }
3346+ if ( existsSync ( configFilePath ) ) {
3347+ await fs . unlink ( configFilePath ) ;
3348+ }
3349+ } ) ;
3350+
3351+ // ensure the config file is not created without the flag
3352+ delete process . env . MINIFLARE_WORKERD_CONFIG_DEBUG ;
3353+ let mf = new Miniflare ( {
3354+ modules : true ,
3355+ script : `export default {
3356+ fetch() {
3357+ return new Response("Hello World");
3358+ }
3359+ }` ,
3360+ } ) ;
3361+ // Trigger workerd config serialization by dispatching a request
3362+ let response = await mf . dispatchFetch ( "http://localhost" ) ;
3363+ // seems like miniflare doesn't like it if you don't read the response
3364+ await response . text ( ) ;
3365+ t . false (
3366+ existsSync ( configFilePath ) ,
3367+ "config file should not be created when MINIFLARE_WORKERD_CONFIG_DEBUG is not set"
3368+ ) ;
3369+ await mf . dispose ( ) ;
3370+
3371+ // ensure the config file is created with the flag
3372+ process . env . MINIFLARE_WORKERD_CONFIG_DEBUG = configFilePath ;
3373+ mf = new Miniflare ( {
3374+ modules : true ,
3375+ script : `export default {
3376+ fetch() {
3377+ return new Response("Hello World");
3378+ }
3379+ }` ,
3380+ } ) ;
3381+ response = await mf . dispatchFetch ( "http://localhost" ) ;
3382+ await response . text ( ) ;
3383+ t . true (
3384+ existsSync ( configFilePath ) ,
3385+ "workerd-config.json should be created when MINIFLARE_WORKERD_CONFIG_DEBUG=true"
3386+ ) ;
3387+ await mf . dispose ( ) ;
3388+ } ) ;
0 commit comments