Writing Mocha results/reports to a database

180 views
Skip to first unread message

Alexander Mills

unread,
Dec 9, 2015, 6:49:41 PM12/9/15
to Mocha
I asked this question on StackOverflow just now:


My questions are- 

(1) can we configure Mocha to write test results to a DB? 
(2) Is there a Mocha reporter that handles this already?

Or should I write this functionality myself somehow?

My ideal scenario is to write test results to MongoDB, so that a web UI can read and display the results.

thanks

-alex

Vlad GURDIGA

unread,
Dec 10, 2015, 3:40:24 AM12/10/15
to Mocha
Hi Alex! 8-)

There was recent thread that I think may be relate: Storing mocha reports on disk. In short, the approach that Gaurang took was to redirect mocha’s output to an XML file, and then process it. If you want to try a custom reporter, here is the wiki with an example: https://github.com/mochajs/mocha/wiki/Third-party-reporters.

Good luck! :)

Hal Armstrong

unread,
Nov 10, 2019, 1:19:49 AM11/10/19
to Mocha
Adding onto Vlad's answer (in a way) I faced a similar need.
  • Using the spec reporter as a baseline, I customized it a bit for two output streams (instead of just the console):
    • One output stream went to the console in real time (with nice colors so I could see what was going on)
    • I made a parallel stream bound for an XML file as well.  The XML output also had database keys to associate with my test plans.  After some formal test was done, I would import the XML into my database (Rational DOORS at the time) using the keys for association.
    • The same thing could have been done with JSON, but XML was the path of least resistance for me in my environment.
I hope the "divide and conquer" concept helps you find a solution to your export needs.

Hal Armstrong (Panasonic Avionics)
Reply all
Reply to author
Forward
0 new messages