@@ -1823,6 +1823,59 @@ test("runtime source loader supports disabling fallback cdn attempts", async ()
18231823 }
18241824} ) ;
18251825
1826+ test ( "runtime module caches are released across lifecycle cycles" , async ( ) => {
1827+ const runtime = new DefaultRuntimeManager ( {
1828+ remoteFallbackCdnBases : [ ] ,
1829+ remoteFetchRetries : 0 ,
1830+ remoteFetchBackoffMs : 10 ,
1831+ remoteFetchTimeoutMs : 600 ,
1832+ } ) ;
1833+
1834+ const internals = runtime as unknown as {
1835+ createSourceModuleLoader : (
1836+ moduleManifest : RuntimeModuleManifest | undefined ,
1837+ diagnostics : Array < { code ?: string ; message ?: string } > ,
1838+ ) => {
1839+ materializeRemoteModule ( url : string ) : Promise < string > ;
1840+ } ;
1841+ browserModuleUrlCache : Map < string , string > ;
1842+ browserModuleInflight : Map < string , Promise < string > > ;
1843+ browserBlobUrls : Set < string > ;
1844+ } ;
1845+
1846+ const originalFetch = globalThis . fetch ;
1847+ globalThis . fetch = ( async ( _input : RequestInfo | URL ) => {
1848+ return new Response ( "export default 'ok';" , {
1849+ status : 200 ,
1850+ headers : {
1851+ "content-type" : "text/javascript; charset=utf-8" ,
1852+ } ,
1853+ } ) ;
1854+ } ) as typeof fetch ;
1855+
1856+ try {
1857+ for ( let cycle = 0 ; cycle < 3 ; cycle += 1 ) {
1858+ await runtime . initialize ( ) ;
1859+
1860+ const diagnostics : Array < { code ?: string ; message ?: string } > = [ ] ;
1861+ const loader = internals . createSourceModuleLoader ( undefined , diagnostics ) ;
1862+ await loader . materializeRemoteModule (
1863+ `https://ga.jspm.io/npm:lit@3.3.0/index.js?cycle=${ cycle } ` ,
1864+ ) ;
1865+
1866+ assert . ok ( internals . browserModuleUrlCache . size > 0 ) ;
1867+ await runtime . terminate ( ) ;
1868+
1869+ assert . equal ( internals . browserModuleUrlCache . size , 0 ) ;
1870+ assert . equal ( internals . browserModuleInflight . size , 0 ) ;
1871+ assert . equal ( internals . browserBlobUrls . size , 0 ) ;
1872+ }
1873+ } finally {
1874+ globalThis . fetch = originalFetch ;
1875+ await runtime . terminate ( ) ;
1876+ }
1877+ } ) ;
1878+
18261879test ( "runtime enforces moduleManifest for bare component specifiers by default" , async ( ) => {
18271880 const runtime = new DefaultRuntimeManager ( {
18281881 moduleLoader : new MockLoader ( {
0 commit comments