console: throw when no such label exists in console.timeEnd

Test included.
This commit is contained in:
Maciej Małecki 2012-04-29 15:17:16 +02:00 committed by Ben Noordhuis
parent 3bcbd14bb1
commit 77c18d1e1b
2 changed files with 14 additions and 1 deletions

View File

@ -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);
};

View File

@ -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');
});