medikoo/cli-color

Using cli-color as in a module

NetForces opened this issue · 2 comments

Here is a very simple example:

File node_functions.js:

var clc = require('/usr/lib/node_modules/cli-color');

module.exports = {
  pass: function () {
    console.log(clc.bgGreen.white.bold("PASS"))
  },
  fail: function () {
    console.log(clc.bgRed.white.bold("FAIL"))
  }
};

File test.js:

var tools = require('node_functions.js');
console.log(tools.fail());

The expected result would be simply the word FAIL in bold white over red backgroud.

However the result is:

conferences ssh 2015-06-29 14-07-38

I have no idea where the "undefined" comes from.

Running cli-color@1.0.0 with node v0.10.39

It comes from console.log(tools.fail()), it logs result of tools.fail() call which returns undefined.

Doh !

Changed the module for:

var clc = require('/usr/lib/node_modules/cli-color');

module.exports = {
  pass: function () {
    return(clc.bgGreen.white.bold("PASS"));
  },
  fail: function () {
    return(clc.bgRed.white.bold("FAIL"));
  }
};

Works great. Thanks.