From 30cddeb138f65b0264fa50a745f114450995fa4f Mon Sep 17 00:00:00 2001 From: Marie Terrier Date: Sat, 10 Nov 2018 16:50:50 +0100 Subject: [PATCH] console: fix and test console.timeLog() using the default label --- lib/console.js | 4 ++-- test/parallel/test-console.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/console.js b/lib/console.js index 39e55c202c4f4b..db22ee846f4df3 100644 --- a/lib/console.js +++ b/lib/console.js @@ -260,7 +260,7 @@ Console.prototype.timeEnd = function timeEnd(label = 'default') { } }; -Console.prototype.timeLog = function timeLog(label, ...data) { +Console.prototype.timeLog = function timeLog(label = 'default', ...data) { // Coerces everything other than Symbol to a string label = `${label}`; timeLogImpl(this, 'timeLog', label, data); @@ -268,7 +268,7 @@ Console.prototype.timeLog = function timeLog(label, ...data) { }; // Returns true if label was not found -function timeLogImpl(self, name, label = 'default', data) { +function timeLogImpl(self, name, label, data) { const time = self._times.get(label); if (!time) { process.emitWarning(`No such label '${label}' for console.${name}()`); diff --git a/test/parallel/test-console.js b/test/parallel/test-console.js index 5ecc0bd834bde4..19dc0c177aa807 100644 --- a/test/parallel/test-console.js +++ b/test/parallel/test-console.js @@ -45,6 +45,10 @@ common.expectWarning( ['Count for \'noLabel\' does not exist', common.noWarnCode], ['No such label \'noLabel\' for console.timeLog()', common.noWarnCode], ['No such label \'noLabel\' for console.timeEnd()', common.noWarnCode], + ['Count for \'default\' does not exist', common.noWarnCode], + ['No such label \'default\' for console.timeLog()', common.noWarnCode], + ['No such label \'default\' for console.timeEnd()', common.noWarnCode], + ['Label \'default\' already exists for console.time()', common.noWarnCode], ['Label \'test\' already exists for console.time()', common.noWarnCode] ] ); @@ -56,6 +60,17 @@ console.timeEnd('noLabel'); console.time('label'); console.timeEnd('label'); +// Test using the default label +// on console.time(), console.countReset(), console.timeLog(), console.timeEnd() +console.countReset(); +console.timeLog(); +console.timeEnd(); + +console.time(); +console.time(); +console.timeLog(); +console.timeEnd(); + // Check that the `Error` is a `TypeError` but do not check the message as it // will be different in different JavaScript engines. assert.throws(() => console.time(Symbol('test')),