51

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.

Amit Erandole
  • 11,995
  • 23
  • 65
  • 103
  • Related to http://stackoverflow.com/questions/16684582/generate-jasmine-report-using-karma-runner/16865197?noredirect=1#comment24382342_16865197 – Tomas Romero Jun 03 '13 at 18:17

4 Answers4

59

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.

benshope
  • 2,936
  • 4
  • 27
  • 39
  • 12
    Install karma-spec-reporter via `npm install karma-spec-reporter --save-dev`. Hope that helps someone as it was unclear to me how to use. – Anson Kao Feb 13 '15 at 17:42
  • 8
    thanks @AnsonKao also need to specify `karma-spec-reporter` in plugins section of `karma.conf` – ak85 Jan 23 '16 at 05:57
55

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.

Community
  • 1
  • 1
Matt
  • 33,328
  • 25
  • 83
  • 97
  • Hi @Matt, I follow the instructions, but when I run ng test I saw the same interface, what did you do to get the format that you shows in the image – Quethzel Diaz Aug 06 '19 at 19:31
  • Hm, I had to remove the 'progress' from my reporters array. This is what I use now: reporters: ['kjhtml', 'spec'], Then I can see both in the console and in the Chrome that is launched the tests passing – Tore Aurstad Jan 08 '22 at 16:50
9

Use this plugin with karma 0.9.0 or later

https://github.com/mlex/karma-spec-reporter

Satshabad
  • 121
  • 5
1

You could add logs to your test spec. Check out log4js-node:

https://github.com/nomiddlename/log4js-node

grant
  • 4,325
  • 2
  • 24
  • 20