@@ -24,6 +24,7 @@ require('../common');
2424const domain = require ( 'domain' ) ;
2525const http = require ( 'http' ) ;
2626const assert = require ( 'assert' ) ;
27+ const debug = require ( 'util' ) . debuglog ( 'test' ) ;
2728
2829const objects = { foo : 'bar' , baz : { } , num : 42 , arr : [ 1 , 2 , 3 ] } ;
2930objects . baz . asdf = objects ;
@@ -39,7 +40,7 @@ const server = http.createServer(function(req, res) {
3940
4041 dom . on ( 'error' , function ( er ) {
4142 serverCaught ++ ;
42- console . log ( 'horray! got a server error' , er ) ;
43+ debug ( 'horray! got a server error' , er ) ;
4344 // Try to send a 500. If that fails, oh well.
4445 res . writeHead ( 500 , { 'content-type' : 'text/plain' } ) ;
4546 res . end ( er . stack || er . message || 'Unknown error' ) ;
@@ -62,7 +63,7 @@ server.listen(0, next);
6263
6364function next ( ) {
6465 const port = this . address ( ) . port ;
65- console . log ( `listening on localhost:${ port } ` ) ;
66+ debug ( `listening on localhost:${ port } ` ) ;
6667
6768 let requests = 0 ;
6869 let responses = 0 ;
@@ -79,17 +80,17 @@ function next() {
7980 const dom = domain . create ( ) ;
8081 dom . on ( 'error' , function ( er ) {
8182 clientCaught ++ ;
82- console . log ( 'client error' , er ) ;
83+ debug ( 'client error' , er ) ;
8384 req . socket . destroy ( ) ;
8485 } ) ;
8586
8687 const req = http . get ( { host : 'localhost' , port : port , path : p } ) ;
8788 dom . add ( req ) ;
8889 req . on ( 'response' , function ( res ) {
8990 responses ++ ;
90- console . error ( `requests=${ requests } responses=${ responses } ` ) ;
91+ debug ( `requests=${ requests } responses=${ responses } ` ) ;
9192 if ( responses === requests ) {
92- console . error ( 'done, closing server' ) ;
93+ debug ( 'done, closing server' ) ;
9394 // no more coming.
9495 server . close ( ) ;
9596 }
@@ -100,9 +101,9 @@ function next() {
100101 d += c ;
101102 } ) ;
102103 res . on ( 'end' , function ( ) {
103- console . error ( 'trying to parse json' , d ) ;
104+ debug ( 'trying to parse json' , d ) ;
104105 d = JSON . parse ( d ) ;
105- console . log ( 'json!' , d ) ;
106+ debug ( 'json!' , d ) ;
106107 } ) ;
107108 } ) ;
108109 }
@@ -111,5 +112,5 @@ function next() {
111112process . on ( 'exit' , function ( ) {
112113 assert . strictEqual ( serverCaught , 2 ) ;
113114 assert . strictEqual ( clientCaught , 2 ) ;
114- console . log ( 'ok' ) ;
115+ debug ( 'ok' ) ;
115116} ) ;
0 commit comments