@@ -46,6 +46,7 @@ import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
4646import { SemconvStability } from '@opentelemetry/instrumentation' ;
4747import { extractHostnameAndPort } from '../../src/utils' ;
4848import { AttributeNames } from '../../src/enums/AttributeNames' ;
49+ import { ParsedUrlQuery } from 'node:querystring' ;
4950
5051describe ( 'Utility' , ( ) => {
5152 describe ( 'parseResponseStatus()' , ( ) => {
@@ -80,7 +81,20 @@ describe('Utility', () => {
8081 describe ( 'getRequestInfo()' , ( ) => {
8182 it ( 'should get options object' , ( ) => {
8283 const webUrl = 'http://u:p@google.fr/aPath?qu=ry' ;
83- const urlParsed = url . parse ( webUrl ) ;
84+ const urlParsed = {
85+ protocol : 'http:' ,
86+ slashes : true ,
87+ auth : 'u:p' ,
88+ host : 'google.fr' ,
89+ port : null ,
90+ hostname : 'google.fr' ,
91+ hash : null ,
92+ search : '?qu=ry' ,
93+ query : 'qu=ry' ,
94+ pathname : '/aPath' ,
95+ path : '/aPath?qu=ry' ,
96+ href : 'http://u:p@google.fr/aPath?qu=ry' ,
97+ } ;
8498 const urlParsedWithoutPathname = {
8599 ...urlParsed ,
86100 pathname : undefined ,
@@ -95,7 +109,7 @@ describe('Utility', () => {
95109 host : undefined ,
96110 port : null ,
97111 } ;
98- const whatWgUrl = new url . URL ( webUrl ) ;
112+ const whatWgUrl = new URL ( webUrl ) ;
99113 for ( const param of [
100114 webUrl ,
101115 urlParsed ,
@@ -155,12 +169,44 @@ describe('Utility', () => {
155169 describe ( 'getAbsoluteUrl()' , ( ) => {
156170 it ( 'should return absolute url with localhost' , ( ) => {
157171 const path = '/test/1' ;
158- const result = utils . getAbsoluteUrl ( url . parse ( path ) , { } ) ;
172+ const result = utils . getAbsoluteUrl (
173+ {
174+ protocol : null ,
175+ slashes : null ,
176+ auth : null ,
177+ host : null ,
178+ port : null ,
179+ hostname : null ,
180+ hash : null ,
181+ search : null ,
182+ query : null as unknown as undefined ,
183+ pathname : '/test/1' ,
184+ path : '/test/1' ,
185+ href : '/test/1' ,
186+ } ,
187+ { }
188+ ) ;
159189 assert . strictEqual ( result , `http://localhost${ path } ` ) ;
160190 } ) ;
161191 it ( 'should return absolute url' , ( ) => {
162192 const absUrl = 'http://www.google/test/1?query=1' ;
163- const result = utils . getAbsoluteUrl ( url . parse ( absUrl ) , { } ) ;
193+ const result = utils . getAbsoluteUrl (
194+ {
195+ protocol : 'http:' ,
196+ slashes : true ,
197+ auth : null ,
198+ host : 'www.google' ,
199+ port : null ,
200+ hostname : 'www.google' ,
201+ hash : null ,
202+ search : '?query=1' ,
203+ query : 'query=1' as unknown as ParsedUrlQuery ,
204+ pathname : '/test/1' ,
205+ path : '/test/1?query=1' ,
206+ href : 'http://www.google/test/1?query=1' ,
207+ } ,
208+ { }
209+ ) ;
164210 assert . strictEqual ( result , absUrl ) ;
165211 } ) ;
166212 it ( 'should return default url' , ( ) => {
@@ -258,7 +304,11 @@ describe('Utility', () => {
258304 assert . strictEqual ( utils . isValidOptionsType ( options ) , false ) ;
259305 } ) ;
260306 } ) ;
261- for ( const options of [ 'url' , url . parse ( 'http://url.com' ) , { } ] ) {
307+ for ( const options of [
308+ 'url' ,
309+ url . urlToHttpOptions ( new URL ( 'http://url.com' ) ) ,
310+ { } ,
311+ ] ) {
262312 it ( `should return true with the following value: ${ JSON . stringify (
263313 options
264314 ) } `, ( ) => {
0 commit comments