Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a list of passing tests from karma runner suite?

When I run karma on my webapp, I only get generic messages like tests passed - is there a way to get a list of passing tests? How do I get more verbose output?

I cannot find this anywhere in the documentation.

like image 411
Amit Erandole Avatar asked Jun 03 '13 13:06

Amit Erandole


People also ask

How does Karma test Runner work?

Karma is essentially a tool which spawns a web server that executes source code against test code for each of the browsers connected. The results of each test against each browser are examined and displayed via the command line to the developer such that they can see which browsers and tests passed or failed.

How do you use karma testing?

By installing Karma globally, you'll have access to the “karma” command no matter your current location. To verify whether the installation was successful, just run “karma –version” and you should see the current version number. You're also going to need specific plugins, depending on the other testing tools you use.

What is singleRun in karma?

The property singleRun controls how Karma executes, if set to true , Karma will start, launch configured browsers, run tests and then exit with a code of either 0 or 1 depending on whether or not all tests passed.

What is karma config file?

Overview. In order to serve you well, Karma needs to know about your project in order to test it and this is done via a configuration file. The easiest way to generate an initial configuration file is by using the karma init command. This page lists all of the available configuration options.


2 Answers

I know how this can be done!

Karma's terminal output comes from objects called Reporters. Karma ships with some built-in Reporters (they can be found in karma/lib/reporters). Karma is also able to use custom Reporters.

You can specify which reporters are used in your project's karma.config.js file.

For example, the 'dots' reporter just prints a dot when each test passes:

reporters: ['dots'], 

The 'progress' reporter prints more than dots:

reporters: ['progress'], 

The custom reporter karma-spec-reporter prints the name of each test when the test succeeds or fails (but not much else):

reporters: ['spec'], 

You may want to roll your own reporter, since karma-junit-reporter, karma-spec-reporter, and the included reporters may not meet your needs.

I am guessing that customizing karma-spec-reporter is the best option in this case, since it already prints a line when a test succeeds.

If you are looking for something even more simple to work from, here is a custom reporter that I built. It reports passing and failing tests with no terminal colors.

like image 153
benshope Avatar answered Oct 05 '22 13:10

benshope


I recommend the Karma Spec Reporter. This will give you a pretty unit test report like this.

Karma unit test spec

How to use it:

  1. Install the Karma Spec Reporter

On the command line in your project,

npm install karma-spec-reporter --save-dev

  1. Add Karma Spec Reporter to the configuration

In karma.conf.js,

...   config.set({   ...     reporters: ["spec"],     specReporter: {       maxLogLines: 5,         // limit number of lines logged per test       suppressErrorSummary: true,  // do not print error summary       suppressFailed: false,  // do not print information about failed tests       suppressPassed: false,  // do not print information about passed tests       suppressSkipped: true,  // do not print information about skipped tests       showSpecTiming: false // print the time elapsed for each spec     },     plugins: ["karma-spec-reporter"],   ... 

That is all. Enjoy.

like image 26
Matt Avatar answered Oct 05 '22 13:10

Matt