@@ -42,6 +42,10 @@ export default {
4242return await testSqlite ( ) ;
4343case "/test-http" :
4444return await testHttp ( ) ;
45+ case "/test-debug-import" :
46+ return await testDebugImport ( ) ;
47+ case "/test-debug-require" :
48+ return await testDebugRequire ( ) ;
4549}
4650
4751return new Response (
@@ -55,6 +59,8 @@ export default {
5559<a href="test-crypto">node:crypto</a>
5660<a href="test-sqlite">node:sqlite</a>
5761<a href="test-http">node:http</a>
62+ <a href="test-debug-import">debug (import)</a>
63+ <a href="test-debug-require">debug (require)</a>
5864` ,
5965{ headers : { "Content-Type" : "text/html; charset=utf-8" } }
6066) ;
@@ -281,3 +287,67 @@ async function testHttp() {
281287
282288return new Response ( "OK" ) ;
283289}
290+
291+ async function testDebugImport ( ) {
292+ const debug = ( await import ( "debug" ) ) . default ;
293+ const capturedLogs : string [ ] = [ ] ;
294+
295+ // Override debug.log to capture output for verification
296+ debug . log = ( ...args : string [ ] ) => {
297+ capturedLogs . push ( args . join ( " " ) ) ;
298+ } ;
299+
300+ // Test different namespaces based on DEBUG env var: "example:*,test"
301+ const testNamespace = debug ( "test" ) ; // Should log (matches "test")
302+ const exampleNamespace = debug ( "example" ) ; // Should NOT log (doesn't match "example:*")
303+ const exampleFooNamespace = debug ( "example:foo" ) ; // Should log (matches "example:*")
304+
305+ testNamespace ( "Test import message 1" ) ;
306+ exampleNamespace ( "Example import message (should not appear)" ) ;
307+ exampleFooNamespace ( "Example foo import message" ) ;
308+
309+ if ( testNamespace . enabled ) {
310+ testNamespace ( "Test import enabled message" ) ;
311+ }
312+
313+ // Strip timestamps from captured logs, keeping namespace and message
314+ // Format: "2025-08-14T20:09:49.769Z test Test import message 1"
315+ const logsWithoutTimestamp = capturedLogs . map ( ( log ) => {
316+ const parts = log . split ( " " ) ;
317+ return parts . slice ( 1 ) . join ( " " ) ; // Remove timestamp, keep namespace + message
318+ } ) ;
319+
320+ return Response . json ( logsWithoutTimestamp ) ;
321+ }
322+
323+ async function testDebugRequire ( ) {
324+ const debug = require ( "debug" ) ;
325+ const capturedLogs : string [ ] = [ ] ;
326+
327+ // Override debug.log to capture output for verification
328+ debug . log = ( ...args : string [ ] ) => {
329+ capturedLogs . push ( args . join ( " " ) ) ;
330+ } ;
331+
332+ // Test different namespaces based on DEBUG env var: "example:*,test"
333+ const testNamespace = debug ( "test" ) ; // Should log (matches "test")
334+ const exampleNamespace = debug ( "example" ) ; // Should NOT log (doesn't match "example:*")
335+ const exampleFooNamespace = debug ( "example:foo" ) ; // Should log (matches "example:*")
336+
337+ testNamespace ( "Test require message 1" ) ;
338+ exampleNamespace ( "Example require message (should not appear)" ) ;
339+ exampleFooNamespace ( "Example foo require message" ) ;
340+
341+ if ( testNamespace . enabled ) {
342+ testNamespace ( "Test require enabled message" ) ;
343+ }
344+
345+ // Strip timestamps from captured logs, keeping namespace and message
346+ // Format: "2025-08-14T20:09:49.769Z test Test require message 1"
347+ const logsWithoutTimestamp = capturedLogs . map ( ( log ) => {
348+ const parts = log . split ( " " ) ;
349+ return parts . slice ( 1 ) . join ( " " ) ; // Remove timestamp, keep namespace + message
350+ } ) ;
351+
352+ return Response . json ( logsWithoutTimestamp ) ;
353+ }
0 commit comments