File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -474,13 +474,15 @@ async function runTests() {
474474 return createMockFetch ( { json : makeConfig ( ) } ) ( url , options ) ;
475475 } ) ;
476476
477- await fetchInstanceInfo ( mockServer as any ) ;
478-
479- const headers = getCapturedOptions ( ) ?. headers as Record < string , string > ;
480- assert . equal ( headers ?. [ 'user-agent' ] , 'SearchBot/2.0' ) ;
481-
482- fetchMocker . restore ( ) ;
483- envManager . restore ( ) ;
477+ try {
478+ await fetchInstanceInfo ( mockServer as any ) ;
479+
480+ const headers = getCapturedOptions ( ) ?. headers as Record < string , string > ;
481+ assert . equal ( headers ?. [ 'user-agent' ] , 'SearchBot/2.0' ) ;
482+ } finally {
483+ fetchMocker . restore ( ) ;
484+ envManager . restore ( ) ;
485+ }
484486 } , results ) ;
485487
486488 await testFunction ( 'config request omits User-Agent header when USER_AGENT is unset' , async ( ) => {
Original file line number Diff line number Diff line change @@ -867,17 +867,19 @@ async function runTests() {
867867 } ) ;
868868
869869 try {
870- await performWebSearch ( mockServer as any , 'test query' ) ;
871- } catch {
872- // expected
873- }
874-
875- const options = getCapturedOptions ( ) ;
876- const headers = options ?. headers as Record < string , string > ;
877- assert . equal ( headers ?. [ 'User-Agent' ] , 'SearchBot/2.0' ) ;
870+ try {
871+ await performWebSearch ( mockServer as any , 'test query' ) ;
872+ } catch {
873+ // expected
874+ }
878875
879- fetchMocker . restore ( ) ;
880- envManager . restore ( ) ;
876+ const options = getCapturedOptions ( ) ;
877+ const headers = options ?. headers as Record < string , string > ;
878+ assert . equal ( headers ?. [ 'User-Agent' ] , 'SearchBot/2.0' ) ;
879+ } finally {
880+ fetchMocker . restore ( ) ;
881+ envManager . restore ( ) ;
882+ }
881883 } , results ) ;
882884
883885 await testFunction ( 'User-Agent header absent when USER_AGENT env var not set' , async ( ) => {
Original file line number Diff line number Diff line change @@ -203,13 +203,15 @@ async function runTests() {
203203 return createMockFetch ( { json : [ 'type' , [ 'typescript' ] ] } ) ( url , options ) ;
204204 } ) ;
205205
206- await performSearchSuggestions ( mockServer as any , 'type' ) ;
207-
208- const headers = getCapturedOptions ( ) ?. headers as Record < string , string > ;
209- assert . equal ( headers ?. [ 'user-agent' ] , 'SearchBot/2.0' ) ;
210-
211- fetchMocker . restore ( ) ;
212- envManager . restore ( ) ;
206+ try {
207+ await performSearchSuggestions ( mockServer as any , 'type' ) ;
208+
209+ const headers = getCapturedOptions ( ) ?. headers as Record < string , string > ;
210+ assert . equal ( headers ?. [ 'user-agent' ] , 'SearchBot/2.0' ) ;
211+ } finally {
212+ fetchMocker . restore ( ) ;
213+ envManager . restore ( ) ;
214+ }
213215 } , results ) ;
214216
215217 await testFunction ( 'autocompleter request omits User-Agent header when USER_AGENT is unset' , async ( ) => {
You can’t perform that action at this time.
0 commit comments