Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
console: throw when no such label exists in console.timeEnd
Browse files Browse the repository at this point in the history
Test included.
  • Loading branch information
mmalecki authored and bnoordhuis committed Apr 29, 2012
1 parent 3bcbd14 commit 77c18d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/console.js
Expand Up @@ -49,7 +49,11 @@ exports.time = function(label) {


exports.timeEnd = function(label) {
var duration = Date.now() - times[label];
var time = times[label];
if (!time) {
throw new Error('No such label: ' + label);
}
var duration = Date.now() - time;
exports.log('%s: %dms', label, duration);
};

Expand Down
9 changes: 9 additions & 0 deletions test/simple/test-console.js
Expand Up @@ -50,3 +50,12 @@ assert.equal('foo bar hop\n', strings.shift());
assert.equal("{ slashes: '\\\\\\\\' }\n", strings.shift());

process.stderr.write('hello world');

assert.throws(function () {
console.timeEnd('no such label');
});

assert.doesNotThrow(function () {
console.time('label');
console.timeEnd('label');
});

0 comments on commit 77c18d1

Please sign in to comment.