@@ -342,6 +342,49 @@ describe('Request', () => {
342342 } )
343343} )
344344
345+ describe ( 'util.inspect' , ( ) => {
346+ it ( 'should show a lightweight request summary without creating a native Request' , ( ) => {
347+ const { inspect } = require ( 'node:util' )
348+ const req = newRequest ( {
349+ method : 'GET' ,
350+ url : '/' ,
351+ headers : {
352+ host : 'localhost' ,
353+ } ,
354+ rawHeaders : [ 'host' , 'localhost' ] ,
355+ } as IncomingMessage )
356+
357+ expect ( ( ) => inspect ( req ) ) . not . toThrow ( )
358+ const result = inspect ( req )
359+ expect ( result ) . toContain ( 'Request (lightweight)' )
360+ expect ( result ) . toContain ( 'GET' )
361+ expect ( result ) . toContain ( 'http://localhost/' )
362+ expect ( result ) . toContain ( 'nativeRequest: undefined' )
363+ expect ( req [ abortControllerKey ] ) . toBeUndefined ( )
364+ expect ( req ) . toBeInstanceOf ( global . Request )
365+ } )
366+
367+ it ( 'should include the native Request after cache creation' , ( ) => {
368+ const { inspect } = require ( 'node:util' )
369+ const req = newRequest ( {
370+ method : 'GET' ,
371+ url : '/' ,
372+ headers : {
373+ host : 'localhost' ,
374+ } ,
375+ rawHeaders : [ 'host' , 'localhost' ] ,
376+ } as IncomingMessage )
377+
378+ // Access keepalive to trigger native Request creation via getRequestCache()
379+ req . keepalive
380+
381+ const result = inspect ( req )
382+ expect ( result ) . toContain ( 'Request (lightweight)' )
383+ expect ( result ) . toContain ( 'nativeRequest: Request {' )
384+ expect ( req [ abortControllerKey ] ) . toBeDefined ( )
385+ } )
386+ } )
387+
345388describe ( 'RequestError' , ( ) => {
346389 it ( 'should have a static name property (class name)' , ( ) => {
347390 expect ( RequestError . name ) . toBe ( 'RequestError' )
0 commit comments