Skip to content

Commit

Permalink
console: console.time() should not reset a timer when it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed May 3, 2018
1 parent 24a5ac7 commit b9f0272
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ Console.prototype.dir = function dir(object, options) {
Console.prototype.time = function time(label = 'default') {
// Coerces everything other than Symbol to a string
label = `${label}`;
if (this._times.has(label)) {
process.emitWarning(`Label '${label}' already exists for console.time()`);
return;
}
this._times.set(label, process.hrtime());
};

Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ console.timeEnd();
console.time(NaN);
console.timeEnd(NaN);

// make sure calling time twice without timeEnd doesn't reset the timer.
console.time('test');
const time = console._times.get('test');
setTimeout(() => {
assert.deepStrictEqual(console._times.get('test'), time);
common.expectWarning(
'Warning',
'Label \'test\' already exists for console.time()',
common.noWarnCode);
console.time('test');
console.timeEnd('test');
}, 1);


console.assert(false, '%s should', 'console.assert', 'not throw');
assert.strictEqual(errStrings[errStrings.length - 1],
'Assertion failed: console.assert should not throw\n');
Expand Down

0 comments on commit b9f0272

Please sign in to comment.