2222'use strict' ;
2323const common = require ( '../common' ) ;
2424const assert = require ( 'assert' ) ;
25+ const util = require ( 'util' ) ;
2526
2627assert . ok ( process . stdout . writable ) ;
2728assert . ok ( process . stderr . writable ) ;
@@ -30,11 +31,17 @@ if (common.isMainThread) {
3031 assert . strictEqual ( typeof process . stdout . fd , 'number' ) ;
3132 assert . strictEqual ( typeof process . stderr . fd , 'number' ) ;
3233}
33- process . once ( 'warning' , common . mustCall ( ( warning ) => {
34- assert ( / n o s u c h l a b e l / . test ( warning . message ) ) ;
35- } ) ) ;
3634
37- console . timeEnd ( 'no such label' ) ;
35+ common . expectWarning (
36+ 'Warning' ,
37+ [
38+ [ 'No such label \'nolabel\' for console.timeEnd()' , common . noWarnCode ] ,
39+ [ 'No such label \'nolabel\' for console.timeLog()' , common . noWarnCode ]
40+ ]
41+ ) ;
42+
43+ console . timeEnd ( 'nolabel' ) ;
44+ console . timeLog ( 'nolabel' ) ;
3845
3946console . time ( 'label' ) ;
4047console . timeEnd ( 'label' ) ;
@@ -47,8 +54,8 @@ assert.throws(() => console.timeEnd(Symbol('test')),
4754 TypeError ) ;
4855
4956
50- // an Object with a custom . inspect() function
51- const custom_inspect = { foo : 'bar' , inspect : ( ) => 'inspect' } ;
57+ // An Object with a custom inspect function.
58+ const custom_inspect = { foo : 'bar' , [ util . inspect . custom ] : ( ) => 'inspect' } ;
5259
5360const strings = [ ] ;
5461const errStrings = [ ] ;
@@ -139,6 +146,12 @@ console.timeEnd();
139146console . time ( NaN ) ;
140147console . timeEnd ( NaN ) ;
141148
149+ console . time ( 'log1' ) ;
150+ console . timeLog ( 'log1' ) ;
151+ console . timeLog ( 'log1' , 'test' ) ;
152+ console . timeLog ( 'log1' , { } , [ 1 , 2 , 3 ] ) ;
153+ console . timeEnd ( 'log1' ) ;
154+
142155console . assert ( false , '%s should' , 'console.assert' , 'not throw' ) ;
143156assert . strictEqual ( errStrings [ errStrings . length - 1 ] ,
144157 'Assertion failed: console.assert should not throw\n' ) ;
@@ -179,9 +192,11 @@ for (const expected of expectedStrings) {
179192}
180193
181194assert . strictEqual ( strings . shift ( ) ,
182- "{ foo: 'bar', inspect: [Function: inspect] }\n" ) ;
195+ "{ foo: 'bar',\n [Symbol(util.inspect.custom)]: " +
196+ '[Function: [util.inspect.custom]] }\n' ) ;
183197assert . strictEqual ( strings . shift ( ) ,
184- "{ foo: 'bar', inspect: [Function: inspect] }\n" ) ;
198+ "{ foo: 'bar',\n [Symbol(util.inspect.custom)]: " +
199+ '[Function: [util.inspect.custom]] }\n' ) ;
185200assert . ok ( strings . shift ( ) . includes ( 'foo: [Object]' ) ) ;
186201assert . strictEqual ( strings . shift ( ) . includes ( 'baz' ) , false ) ;
187202assert . strictEqual ( strings . shift ( ) , 'inspect inspect\n' ) ;
@@ -202,6 +217,14 @@ assert.ok(/^default: \d+\.\d{3}ms$/.test(strings.shift().trim()));
202217assert . ok ( / ^ d e f a u l t : \d + \. \d { 3 } m s $ / . test ( strings . shift ( ) . trim ( ) ) ) ;
203218assert . ok ( / ^ N a N : \d + \. \d { 3 } m s $ / . test ( strings . shift ( ) . trim ( ) ) ) ;
204219
220+ assert . ok ( / ^ l o g 1 : \d + \. \d { 3 } m s $ / . test ( strings . shift ( ) . trim ( ) ) ) ;
221+ assert . ok ( / ^ l o g 1 : \d + \. \d { 3 } m s t e s t $ / . test ( strings . shift ( ) . trim ( ) ) ) ;
222+ assert . ok ( / ^ l o g 1 : \d + \. \d { 3 } m s { } \[ 1 , 2 , 3 ] $ / . test ( strings . shift ( ) . trim ( ) ) ) ;
223+ assert . ok ( / ^ l o g 1 : \d + \. \d { 3 } m s $ / . test ( strings . shift ( ) . trim ( ) ) ) ;
224+
225+ // Make sure that we checked all strings
226+ assert . strictEqual ( strings . length , 0 ) ;
227+
205228assert . strictEqual ( errStrings . shift ( ) . split ( '\n' ) . shift ( ) ,
206229 'Trace: This is a {"formatted":"trace"} 10 foo' ) ;
207230
@@ -212,6 +235,6 @@ common.hijackStderr(common.mustCall(function(data) {
212235
213236 // stderr.write will catch sync error, so use `process.nextTick` here
214237 process . nextTick ( function ( ) {
215- assert . strictEqual ( data . includes ( 'no such label ' ) , true ) ;
238+ assert . strictEqual ( data . includes ( 'nolabel ' ) , true ) ;
216239 } ) ;
217240} ) ) ;
0 commit comments