From: Ruben Beltran del Rio Date: Mon, 21 Sep 2020 10:56:00 +0000 (+0200) Subject: Address sonarqube issues with tests X-Git-Url: https://git.r.bdr.sh/rbdr/cologne/commitdiff_plain/8cb82362b1e66cdfadd58cc23587239bfc1df4c9?ds=inline Address sonarqube issues with tests --- diff --git a/test/cologne.js b/test/cologne.js index 3f06763..1fce740 100644 --- a/test/cologne.js +++ b/test/cologne.js @@ -23,7 +23,7 @@ const createDummyLogger = function () { const levelChecker = function (level) { - return (count, log) => (log._level === level ? ++count : count); + return (count, log) => (log._level === level ? count + 1 : count); }; @@ -42,74 +42,74 @@ const co = new Cologne({ ] }); -const logs = ['example1', null, undefined, 1, { example: true }]; +const exampleLogs = ['example1', null, undefined, 1, { example: true }]; /** * TEST: #log() */ -co.log(...logs); +co.log(...exampleLogs); // Calculate values -const valueCheck = dummyLoggerA.values.reduce((count, log) => (typeof log._cologneLog === 'string' ? ++count : count), 0); +const valueCheck = dummyLoggerA.values.reduce((count, log) => (typeof log._cologneLog === 'string' ? count + 1 : count), 0); let levelCheck = dummyLoggerA.values.reduce(levelChecker(6), 0); // Now check the values -Tap.equal(dummyLoggerA.values.length, logs.length, +Tap.equal(dummyLoggerA.values.length, exampleLogs.length, '#log() should send every argument to the loggers'); Tap.similar(dummyLoggerA.values, dummyLoggerB.values, '#log() should send the same arguments to all the loggers'); -Tap.equal(valueCheck, logs.length, +Tap.equal(valueCheck, exampleLogs.length, '#log() should send all objects in cologne log format'); -Tap.equal(levelCheck, logs.length, +Tap.equal(levelCheck, exampleLogs.length, '#log() should default to level 6'); /** * TEST: #debug() */ -co.debug(...logs); +co.debug(...exampleLogs); levelCheck = dummyLoggerA.values.reduce(levelChecker(7), 0); -Tap.equal(levelCheck, logs.length, +Tap.equal(levelCheck, exampleLogs.length, '#debug() should set to level 7'); /** * TEST: #info() */ -co.info(...logs); +co.info(...exampleLogs); levelCheck = dummyLoggerA.values.reduce(levelChecker(6), 0); -Tap.equal(levelCheck, logs.length, +Tap.equal(levelCheck, exampleLogs.length, '#info() should set to level 6'); /** * TEST: #notice() */ -co.notice(...logs); +co.notice(...exampleLogs); levelCheck = dummyLoggerA.values.reduce(levelChecker(5), 0); -Tap.equal(levelCheck, logs.length, +Tap.equal(levelCheck, exampleLogs.length, '#notice() should set to level 5'); /** * TEST: #warn() */ -co.warn(...logs); +co.warn(...exampleLogs); levelCheck = dummyLoggerA.values.reduce(levelChecker(4), 0); -Tap.equal(levelCheck, logs.length, +Tap.equal(levelCheck, exampleLogs.length, '#warn() should set to level 4'); /** * TEST: #error() */ -co.error(...logs); +co.error(...exampleLogs); levelCheck = dummyLoggerA.values.reduce(levelChecker(3), 0); -Tap.equal(levelCheck, logs.length, +Tap.equal(levelCheck, exampleLogs.length, '#error() should set to level 3'); /** @@ -156,7 +156,7 @@ co.removeLogger(dummyLoggerC); Tap.equal(co.loggers.length, 2, '#removeLogger() should do nothing if it can\'t find a logger'); -co.log(...logs); +co.log(...exampleLogs); co.removeLogger(dummyLoggerB); co.log(1); @@ -171,7 +171,7 @@ Tap.notEqual(dummyLoggerB.values.length, dummyLoggerA.values.length, */ co.addLogger(dummyLoggerC); -co.log(...logs); +co.log(...exampleLogs); -Tap.equal(dummyLoggerC.values.length, logs.length, +Tap.equal(dummyLoggerC.values.length, exampleLogs.length, '#addLogger() should add loggers after instance is live'); diff --git a/test/loggers/console.js b/test/loggers/console.js index 3358837..87dbc23 100644 --- a/test/loggers/console.js +++ b/test/loggers/console.js @@ -62,7 +62,7 @@ const logObjectB = { message: 'MessageTwo' }; -const logs = [logObjectA, logObjectB]; +const exampleLogs = [logObjectA, logObjectB]; const regularLogger = new ConsoleLogger({}); const overrideLogger = new ConsoleLogger({ @@ -86,38 +86,38 @@ Tap.equal(regularLogger.console, global.console, logObjectA._level = 5; logObjectB._level = 6; -overrideLogger.log(...logs); // should go to info +overrideLogger.log(...exampleLogs); // should go to info logObjectA._level = 4; logObjectB._level = 4; -overrideLogger.log(...logs); // should go to warn +overrideLogger.log(...exampleLogs); // should go to warn logObjectA._level = 1; logObjectB._level = 3; -overrideLogger.log(...logs); // should go to error +overrideLogger.log(...exampleLogs); // should go to error logObjectA._level = 0; logObjectB._level = 2; -overrideLogger.log(...logs); // should go to error +overrideLogger.log(...exampleLogs); // should go to error logObjectA._level = 7; logObjectB._level = 8; -overrideLogger.log(...logs); // should go to log +overrideLogger.log(...exampleLogs); // should go to log -Tap.equal(dummyConsole.values.log, logs.length, +Tap.equal(dummyConsole.values.log, exampleLogs.length, 'It should send debug messages to console\'s #log'); -Tap.equal(dummyConsole.values.info, logs.length, +Tap.equal(dummyConsole.values.info, exampleLogs.length, 'It should send info and notice messages to console\'s #info'); -Tap.equal(dummyConsole.values.warn, logs.length, +Tap.equal(dummyConsole.values.warn, exampleLogs.length, 'It should send warn messages to console\'s #warn'); -Tap.equal(dummyConsole.values.error, logs.length * 2, +Tap.equal(dummyConsole.values.error, exampleLogs.length * 2, 'It should send error messages to console\'s #error'); /** * TEST: #log() - with formatter */ -formattedLogger.log(...logs); // should go to log +formattedLogger.log(...exampleLogs); // should go to log -Tap.similar(dummyFormatter.values, logs, +Tap.similar(dummyFormatter.values, exampleLogs, 'If available, it should send the objects to the formatter');