Test Reporting by MochAwesome

Kishan Chaitanya
3 min readFeb 27, 2020

--

Who doesn't like reporting? Everyone loves ❤️ it right?

When I started to work with Cypress, Mocha, Chai and SuperTest. The test results which Mocha was generating was good but definitely not the best format I was looking for.

So when I was researching the internet for the available reporting libraries which go well for my front-end and back-end testing frameworks, I really found this amazing library called MochAwesome 🔆.

It works well with both front-end and back-end frameworks developed using Mocha.

Lets take some test framework that already has Mocha Tests written for us. In this case I am going to start with my existing API tests which you could also download from below github link.

Once you have cloned the repository, Let’s start installing MochAwesome.

npm install --save-dev mochawesome

Next step is when you are running Mocha for test execution, Simply add this parameter --reporter mochawesometo the Mocha Command.

In this case I am using my package.json, So I ll update to something like this:

"scripts": {    "test": "mocha --reporter mochawesome"}

Now when you run npm test your new reports are generated under the folder name mochawesome-report 💃.

There are 2 files generated

  • HTML
  • JSON

HTML files are easily readable while JSON files are mainly for data generation like KPI metrics. Below is an example how an HTML report looks like

There are several options which you could pass for MochAwesome and that’s a BIG plus since its easy to customize too. Some of the options are:

  • overwrite = true Over write file if an existing file has the same file name has the new one.
  • reportFilename = API_Report File name of the report.
  • reportDir = test/integration Directory where you want the file to be saved.
  • charts = true Display charts for each describe set.
  • code = true Display exact code where there is failure or pass. This really helps for quick overview.
  • timestamp = mmddyyyy_HHMMss File name has the time stamp, So you could see the history results easily over a period of time.

There are a couple of ways you could pass these configs, either by Mocha.opts or through package.json itself.

You could read more on the other available options here

In case , you want to get the source code. Feel free to download it.

--

--

Kishan Chaitanya
Kishan Chaitanya

Written by Kishan Chaitanya

8+ years of professional software development experience focused on scalable web applications.

No responses yet