|
22 | 22 | 'use strict'; |
23 | 23 | const common = require('../common'); |
24 | 24 | const assert = require('assert'); |
| 25 | +const util = require('util'); |
25 | 26 |
|
26 | 27 | assert.ok(process.stdout.writable); |
27 | 28 | assert.ok(process.stderr.writable); |
@@ -30,11 +31,17 @@ if (common.isMainThread) { |
30 | 31 | assert.strictEqual(typeof process.stdout.fd, 'number'); |
31 | 32 | assert.strictEqual(typeof process.stderr.fd, 'number'); |
32 | 33 | } |
33 | | -process.once('warning', common.mustCall((warning) => { |
34 | | - assert(/no such label/.test(warning.message)); |
35 | | -})); |
36 | 34 |
|
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'); |
38 | 45 |
|
39 | 46 | console.time('label'); |
40 | 47 | console.timeEnd('label'); |
@@ -47,8 +54,8 @@ assert.throws(() => console.timeEnd(Symbol('test')), |
47 | 54 | TypeError); |
48 | 55 |
|
49 | 56 |
|
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' }; |
52 | 59 |
|
53 | 60 | const strings = []; |
54 | 61 | const errStrings = []; |
@@ -139,6 +146,12 @@ console.timeEnd(); |
139 | 146 | console.time(NaN); |
140 | 147 | console.timeEnd(NaN); |
141 | 148 |
|
| 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 | + |
142 | 155 | console.assert(false, '%s should', 'console.assert', 'not throw'); |
143 | 156 | assert.strictEqual(errStrings[errStrings.length - 1], |
144 | 157 | 'Assertion failed: console.assert should not throw\n'); |
@@ -179,9 +192,11 @@ for (const expected of expectedStrings) { |
179 | 192 | } |
180 | 193 |
|
181 | 194 | assert.strictEqual(strings.shift(), |
182 | | - "{ foo: 'bar', inspect: [Function: inspect] }\n"); |
| 195 | + "{ foo: 'bar',\n [Symbol(util.inspect.custom)]: " + |
| 196 | + '[Function: [util.inspect.custom]] }\n'); |
183 | 197 | assert.strictEqual(strings.shift(), |
184 | | - "{ foo: 'bar', inspect: [Function: inspect] }\n"); |
| 198 | + "{ foo: 'bar',\n [Symbol(util.inspect.custom)]: " + |
| 199 | + '[Function: [util.inspect.custom]] }\n'); |
185 | 200 | assert.ok(strings.shift().includes('foo: [Object]')); |
186 | 201 | assert.strictEqual(strings.shift().includes('baz'), false); |
187 | 202 | assert.strictEqual(strings.shift(), 'inspect inspect\n'); |
@@ -202,6 +217,14 @@ assert.ok(/^default: \d+\.\d{3}ms$/.test(strings.shift().trim())); |
202 | 217 | assert.ok(/^default: \d+\.\d{3}ms$/.test(strings.shift().trim())); |
203 | 218 | assert.ok(/^NaN: \d+\.\d{3}ms$/.test(strings.shift().trim())); |
204 | 219 |
|
| 220 | +assert.ok(/^log1: \d+\.\d{3}ms$/.test(strings.shift().trim())); |
| 221 | +assert.ok(/^log1: \d+\.\d{3}ms test$/.test(strings.shift().trim())); |
| 222 | +assert.ok(/^log1: \d+\.\d{3}ms {} \[ 1, 2, 3 ]$/.test(strings.shift().trim())); |
| 223 | +assert.ok(/^log1: \d+\.\d{3}ms$/.test(strings.shift().trim())); |
| 224 | + |
| 225 | +// Make sure that we checked all strings |
| 226 | +assert.strictEqual(strings.length, 0); |
| 227 | + |
205 | 228 | assert.strictEqual(errStrings.shift().split('\n').shift(), |
206 | 229 | 'Trace: This is a {"formatted":"trace"} 10 foo'); |
207 | 230 |
|
@@ -212,6 +235,6 @@ common.hijackStderr(common.mustCall(function(data) { |
212 | 235 |
|
213 | 236 | // stderr.write will catch sync error, so use `process.nextTick` here |
214 | 237 | process.nextTick(function() { |
215 | | - assert.strictEqual(data.includes('no such label'), true); |
| 238 | + assert.strictEqual(data.includes('nolabel'), true); |
216 | 239 | }); |
217 | 240 | })); |