Transcripted Summary

Hey, hello everyone. Welcome back.

In this video we are going to see about different types of Mocha reporters.



In general, Mocha reporters are mostly terminal based.

There are different types of reporters available as part of Mocha, of which, spec and dot matrix are the commonly used reporter types.

Spec is the default reporter.

The spec reporter outputs a hierarchical view according to the test cases.

The dot matrix reporter is a series of characters which represent the test cases.

Failures are highlighted in the red exclamation mark, the pending tests with the blue comma and the slow tests as a yellow color.

There are other types that are available like NYAN, TAP, Landing Strip, List, Progress, JSON, Json Stream.


# Using Mocha Reporters

Let's see these type of reporters in action.

Just for the demo purpose, I have added a few more test cases with another mathematical operations test suite.

Now let's see the first type of reporter, which is nothing but the spec.

In order to get a custom report, we need to execute this command


mocha test/ --reporter spec

with the type of report after the word “reporter”.



This is one type of reporter.

Now let's try to get the dot matrix reporter.

All you need to do is just change the parameter of the reporter type from “spec” to “dot”:


mocha test/ --reporter dot

Now you will be able to see dots coming by.



There is a comma that is coming over there, and there is an exclamation that is coming over here, and a comma again, which means:

  • The dots that you see here in the green color are the test cases that are passing.

  • The commas that you see here in blue color are the test cases that are pending.

  • The one with exclamation mark in red color is nothing but the failure test case.

Now let's see another type called NYAN.

To get this report, we use:


mocha test/ --reporter nyan



Here you will be able to see a different type of reporter, but the test output remains the same for all the reporters.

Let’s look at the JSON reporter.

Now if I want to take the report in a JSON format, all I need to do is just change the reporter type to JSON


mocha test/ --reporter dot

and hit Enter.

Basically, what happens here is, you will not be able to see the progress of the test case.



Rather, after the execution, you will be able to see the JSON String containing all the test reports over here.

That's it everyone.

Thank you so much for watching this course.



I hope you enjoyed.

I would like to thank Angie Jones and Liran Barokas from Applitools for giving me this opportunity.

You can find me on LinkedIn or Twitter.

Thank you and all the best.



Resources



© 2024 Applitools. All rights reserved. Terms and Conditions Privacy Policy GDPR