@ -5,8 +5,8 @@ const assert = require('assert');
assert . ok ( process . stdout . writable ) ;
assert . ok ( process . stderr . writable ) ;
// Support legacy API
assert . e qual( 'number' , typeof process . stdout . fd ) ;
assert . e qual( 'number' , typeof process . stderr . fd ) ;
assert . strictE qual( 'number' , typeof process . stdout . fd ) ;
assert . strictE qual( 'number' , typeof process . stderr . fd ) ;
assert . doesNotThrow ( function ( ) {
process . once ( 'warning' , common . mustCall ( ( warning ) => {
@ -35,28 +35,28 @@ global.process.stderr.write = function(string) {
errStrings . push ( string ) ;
} ;
// test console.log()
// test console.log() goes to stdout
console . log ( 'foo' ) ;
console . log ( 'foo' , 'bar' ) ;
console . log ( '%s %s' , 'foo' , 'bar' , 'hop' ) ;
console . log ( { slashes : '\\\\' } ) ;
console . log ( custom_inspect ) ;
// test console.info()
// test console.info() goes to stdout
console . info ( 'foo' ) ;
console . info ( 'foo' , 'bar' ) ;
console . info ( '%s %s' , 'foo' , 'bar' , 'hop' ) ;
console . info ( { slashes : '\\\\' } ) ;
console . info ( custom_inspect ) ;
// test console.error()
// test console.error() goes to stderr
console . error ( 'foo' ) ;
console . error ( 'foo' , 'bar' ) ;
console . error ( '%s %s' , 'foo' , 'bar' , 'hop' ) ;
console . error ( { slashes : '\\\\' } ) ;
console . error ( custom_inspect ) ;
// test console.warn()
// test console.warn() goes to stderr
console . warn ( 'foo' ) ;
console . warn ( 'foo' , 'bar' ) ;
console . warn ( '%s %s' , 'foo' , 'bar' , 'hop' ) ;
@ -102,29 +102,31 @@ const expectedStrings = [
] ;
for ( const expected of expectedStrings ) {
assert . e qual( expected + '\n' , strings . shift ( ) ) ; // console.log (stdout)
assert . e qual( expected + '\n' , errStrings . shift ( ) ) ; // console.error (stderr)
assert . strictE qual( expected + '\n' , strings . shift ( ) ) ;
assert . strictE qual( expected + '\n' , errStrings . shift ( ) ) ;
}
for ( const expected of expectedStrings ) {
assert . e qual( expected + '\n' , strings . shift ( ) ) ; // console.info (stdout)
assert . e qual( expected + '\n' , errStrings . shift ( ) ) ; // console.warn (stderr)
assert . strictE qual( expected + '\n' , strings . shift ( ) ) ;
assert . strictE qual( expected + '\n' , errStrings . shift ( ) ) ;
}
assert . equal ( "{ foo: 'bar', inspect: [Function: inspect] }\n" , strings . shift ( ) ) ;
assert . equal ( "{ foo: 'bar', inspect: [Function: inspect] }\n" , strings . shift ( ) ) ;
assert . strictEqual ( "{ foo: 'bar', inspect: [Function: inspect] }\n" ,
strings . shift ( ) ) ;
assert . strictEqual ( "{ foo: 'bar', inspect: [Function: inspect] }\n" ,
strings . shift ( ) ) ;
assert . notEqual ( - 1 , strings . shift ( ) . indexOf ( 'foo: [Object]' ) ) ;
assert . equal ( - 1 , strings . shift ( ) . indexOf ( 'baz' ) ) ;
assert . strictE qual( - 1 , strings . shift ( ) . indexOf ( 'baz' ) ) ;
assert . ok ( /^label: \d+\.\d{3}ms$/ . test ( strings . shift ( ) . trim ( ) ) ) ;
assert . ok ( /^__proto__: \d+\.\d{3}ms$/ . test ( strings . shift ( ) . trim ( ) ) ) ;
assert . ok ( /^constructor: \d+\.\d{3}ms$/ . test ( strings . shift ( ) . trim ( ) ) ) ;
assert . ok ( /^hasOwnProperty: \d+\.\d{3}ms$/ . test ( strings . shift ( ) . trim ( ) ) ) ;
assert . e qual( 'Trace: This is a {"formatted":"trace"} 10 foo' ,
errStrings . shift ( ) . split ( '\n' ) . shift ( ) ) ;
assert . strictE qual( 'Trace: This is a {"formatted":"trace"} 10 foo' ,
errStrings . shift ( ) . split ( '\n' ) . shift ( ) ) ;
assert . e qual( strings . length , 0 ) ;
assert . e qual( errStrings . length , 0 ) ;
assert . strictE qual( strings . length , 0 ) ;
assert . strictE qual( errStrings . length , 0 ) ;
assert . throws ( ( ) => {
console . assert ( false , 'should throw' ) ;