@@ -873,22 +873,35 @@ test("MiniflareCore: #watcherCallback: re-runs setup for script-providing plugin
873873
874874test ( "MiniflareCore: reload: reloads worker" , async ( t ) => {
875875 const tmp = await useTmp ( t ) ;
876+ const scriptPath = path . join ( tmp , "worker.js" ) ;
876877 const wranglerConfigPath = path . join ( tmp , "wrangler.toml" ) ;
878+ await fs . writeFile (
879+ scriptPath ,
880+ "export default { fetch: (req, env) => new Response(`1:${env.KEY}`) };"
881+ ) ;
877882 await fs . writeFile ( wranglerConfigPath , '[vars]\nKEY = "value1"' ) ;
878- const mf = useMiniflare ( { BindingsPlugin } , { wranglerConfigPath } ) ;
879- let globalScope = await mf . getGlobalScope ( ) ;
880- t . is ( globalScope . KEY , "value1" ) ;
883+ const mf = useMiniflare (
884+ { BindingsPlugin } ,
885+ { modules : true , scriptPath, wranglerConfigPath }
886+ ) ;
887+ let res = await mf . dispatchFetch ( "http://localhost/" ) ;
888+ t . is ( await res . text ( ) , "1:value1" ) ;
881889
882- // Change wrangler config, check not automatically reloaded (watch disabled)
890+ // Change wrangler config and script, check not automatically reloaded
891+ // (note watch is disabled)
892+ await fs . writeFile (
893+ scriptPath ,
894+ "export default { fetch: (req, env) => new Response(`2:${env.KEY}`) };"
895+ ) ;
883896 await fs . writeFile ( wranglerConfigPath , '[vars]\nKEY = "value2"' ) ;
884897 await setTimeout ( 100 ) ;
885- globalScope = await mf . getGlobalScope ( ) ;
886- t . is ( globalScope . KEY , "value1" ) ;
898+ res = await mf . dispatchFetch ( "http://localhost/" ) ;
899+ t . is ( await res . text ( ) , "1: value1" ) ;
887900
888- // Manually reload(), check config reloaded
901+ // Manually reload(), check config and script reloaded
889902 await mf . reload ( ) ;
890- globalScope = await mf . getGlobalScope ( ) ;
891- t . is ( globalScope . KEY , "value2" ) ;
903+ res = await mf . dispatchFetch ( "http://localhost/" ) ;
904+ t . is ( await res . text ( ) , "2: value2" ) ;
892905} ) ;
893906
894907test ( "MiniflareCore: dispatches reload events" , async ( t ) => {
0 commit comments