2

I want to log some messages while running a test. The messages are logging just fine with the statement console.log but I want to log the messages in green color so I am writing like below but all of it is coming as text rather than green color.

console.log(`%c ${process.name} completed`, 'color: green');

the output is

%c Process1 completed 'color:green'

expected output is (in green color)

Process1 completed 
Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
Angad
  • 1,144
  • 3
  • 18
  • 39
  • The solution you are trying (CSS) is for browser's console. Testcafe is running in Node and output is shown in terminal, so you need to send special characters to terminal to change color: https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color – Roman Eremin Aug 01 '18 at 09:48
  • Thanks that did it. – Angad Aug 01 '18 at 10:40
  • For some reason Dim doesn't work as per the example given in the link. do you know why? – Angad Aug 01 '18 at 11:28
  • This has no relation to TestCafe, it is just Node code. So you can use any library that helps you deal with terminal colors. Like this one: https://github.com/Marak/colors.js Please note, i did not tried any of these myself - just pointing where to look. There are more packages here https://stackoverflow.com/a/13336745/318097 – Roman Eremin Aug 01 '18 at 18:53

1 Answers1

4

I suggest you use the "colors" Node module. For example:

import Colors from 'colors'

test('My test', async t => {
     console.log("Process1 completed".green);      
});
Marion
  • 1,074
  • 5
  • 10