@@ -86,24 +86,33 @@ describe('startWasmModuleTracking', () => {
8686 url : 'https://example.com/module.wasm' ,
8787 clone : ( ) => ( { arrayBuffer : ( ) => arrayBufferPromise } ) ,
8888 } as Response
89- const instantiateStreamingSpy = spyOn ( WebAssembly , 'instantiateStreaming' ) . and . resolveTo (
90- { } as WebAssembly . WebAssemblyInstantiatedSource
91- )
92-
93- startWasmModuleTracking ( )
94- let isResolved = false
95- const instantiatePromise = WebAssembly . instantiateStreaming ( response ) . then ( ( ) => {
96- isResolved = true
97- } )
98- await new Promise ( ( resolve ) => setTimeout ( resolve ) )
99-
100- expect ( instantiateStreamingSpy ) . toHaveBeenCalled ( )
101- expect ( isResolved ) . toBe ( false )
102-
103- resolveArrayBuffer ( wasmModule . buffer )
104- await instantiatePromise
105-
106- expect ( getLoadedWasmModules ( ) ) . toEqual ( [ { url : response . url , build_id : 'abcd' } ] )
89+ const originalInstantiateStreaming = WebAssembly . instantiateStreaming
90+ const instantiateStreamingSpy = jasmine . createSpy ( ) . and . resolveTo ( { } )
91+ WebAssembly . instantiateStreaming = instantiateStreamingSpy
92+
93+ const stopTracking = startWasmModuleTracking ( )
94+ try {
95+ let isResolved = false
96+ const instantiatePromise = WebAssembly . instantiateStreaming ( response ) . then ( ( ) => {
97+ isResolved = true
98+ } )
99+ await new Promise ( ( resolve ) => setTimeout ( resolve ) )
100+
101+ expect ( instantiateStreamingSpy ) . toHaveBeenCalled ( )
102+ expect ( isResolved ) . toBe ( false )
103+
104+ resolveArrayBuffer ( wasmModule . buffer )
105+ await instantiatePromise
106+
107+ expect ( getLoadedWasmModules ( ) ) . toEqual ( [ { url : response . url , build_id : 'abcd' } ] )
108+ } finally {
109+ stopTracking ( )
110+ if ( originalInstantiateStreaming ) {
111+ WebAssembly . instantiateStreaming = originalInstantiateStreaming
112+ } else {
113+ delete ( WebAssembly as Partial < typeof WebAssembly > ) . instantiateStreaming
114+ }
115+ }
107116 } )
108117
109118 it ( 'keeps hooks installed until every tracking client stops' , ( ) => {
0 commit comments