@@ -12,7 +12,8 @@ export const TESTS: Record<string, () => void> = {
1212 testTimers,
1313 testNet,
1414 testTls,
15- testDebug,
15+ testImportDebug,
16+ testRequireDebug,
1617 testHttp,
1718 testHttps,
1819} ;
@@ -212,7 +213,7 @@ export async function testTls() {
212213 assert . strictEqual ( typeof tls . convertALPNProtocols , "function" ) ;
213214}
214215
215- export async function testDebug ( ) {
216+ export async function testImportDebug ( ) {
216217 // @ts -expect-error "debug" is an unenv alias, not installed locally
217218 const debug = ( await import ( "debug" ) ) . default ;
218219 const logs : string [ ] = [ ] ;
@@ -221,13 +222,35 @@ export async function testDebug() {
221222 debug . log = ( ...args : string [ ] ) =>
222223 logs . push ( args . map ( ( arg ) => arg . toString ( ) ) . join ( " " ) ) ;
223224
224- const exampleLog = debug ( "example" ) ;
225- const testLog = exampleLog . extend ( "test" ) ;
225+ // This should log because as `DEBUG` is set to "enabled".
226+ const enabledLog = debug ( "enabled" ) ;
227+ enabledLog ( "This should be logged" ) ;
226228
227- exampleLog ( "This is an example log" ) ;
228- testLog ( "This is a test log" ) ;
229+ // This should not log as `DEBUG` does not contain "enabled:disabled"
230+ const disabledLog = enabledLog . extend ( "disabled" ) ;
231+ disabledLog ( "This should not be logged" ) ;
229232
230- assert . deepEqual ( logs , [ "example This is an example log +0ms" ] ) ;
233+ assert . deepEqual ( logs , [ "enabled This should be logged +0ms" ] ) ;
234+ }
235+
236+ export async function testRequireDebug ( ) {
237+ // eslint-disable-next-line @typescript-eslint/no-require-imports
238+ const debug = require ( "debug" ) ;
239+ const logs : string [ ] = [ ] ;
240+
241+ // Append all logs to the array instead of logging to console
242+ debug . log = ( ...args : string [ ] ) =>
243+ logs . push ( args . map ( ( arg ) => arg . toString ( ) ) . join ( " " ) ) ;
244+
245+ // This should log because as `DEBUG` is set to "enabled".
246+ const enabledLog = debug ( "enabled" ) ;
247+ enabledLog ( "This should be logged" ) ;
248+
249+ // This should not log as `DEBUG` does not contain "enabled:disabled"
250+ const disabledLog = enabledLog . extend ( "disabled" ) ;
251+ disabledLog ( "This should not be logged" ) ;
252+
253+ assert . deepEqual ( logs , [ "enabled This should be logged +0ms" ] ) ;
231254}
232255
233256export async function testHttp ( ) {
0 commit comments