Running mocha test inside gradle task

I have a mocha test which I want to run inside gradle task.

When I run it standalone I get a nice output like this: enter image description here

But when I run it through gradle I get output like this: enter image description here

I managed to display characters correctly although without colors. What is bothering me is that the output is not complete. Also output lenght is different each time I run the task. This makes me believe that this happens because test script is ran asynchronously inside node.js

Is there a way to fix this in gradle?