Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a Mocha test results report of a node applicaton in HTML

When I run the following command on my windows command line mocha --reporter spec > report.html I get something that I cannot really use in my browser.

[0m[0m
[0m  Routes[0m
  [32m  √[0m[90m all GET routes should be bound to a function [0m
  [32m  √[0m[90m all POST routes should be bound to a function [0m
  [32m  √[0m[90m should have one for creating CU [0m

[0m  Database[0m
  [32m  √[0m[90m should be online, connectable and the right one [0m[31m(156ms)[0m

[0m  HTTPS API[0m
[0m    authentication[0m
    [32m  √[0m[90m is mandatory [0m[31m(1109ms)[0m
[0m    entity[0m
    [32m  √[0m[90m lookup should work [0m[31m(172ms)[0m
    [36m  - creation should work[0m

[0m  Website[0m
[0m    pages[0m
    [32m  √[0m[90m should contain quite a few of them [0m
    [32m  √[0m[90m all of them should have internal links to existing pages [0m


[92m [0m[32m 8 passing[0m[90m (2s)[0m
[36m [0m[36m 1 pending[0m

I would like some output as shown in this example http://visionmedia.github.io/mocha/example/tests.html which actually combines documentation together with the test result. Just the test result would be enough for me.

All searches that I do tell me about code coverage to get html, but I don't want that for now. I only need a html report out of Mocha (testing my node application) that I can view in my browser. Of course I can make something myself, but this seems trivial so I expect somebody to have created a custom reporter.

like image 962
Christiaan Westerbeek Avatar asked May 15 '14 20:05

Christiaan Westerbeek


1 Answers

You can use mochawesome. It's efficient and outputs both JSON and elegantly styled HTML reports.

Since most of us have mocha installed globally, it's best to install mochawesome globally as well.

npm install -g mochawesome

and then just run:

mocha --reporter mochawesome

from your test directory.

like image 178
Talha Imam Avatar answered Sep 27 '22 19:09

Talha Imam