Angularjs – How to add debugging log messages with Karma + angular and how to disable them

angularjskarma-runnerloggingunit testing

When I run angular unit tests with Karma, the output contains:

  • output of Karma's reporter (e.g. 'SUCCESS Module X does this and that')
  • unit test log messages (logged via console.log)

The Karma output does not contain:

  • application log messages (logged via $log) – only if I would log via console.log instead of $log

Is it possible for me to choose the logging "intensity"?

I would like to differentiate between:

Default mode: only display Karma reporter output, but suppress all application logging messages or unit test logging messages.

Unit test debugging mode: display Karma reporter output plus all logging messages (application log messages as well as unit test log messages).

Is it possible to log unit test message in a way so that it can be easily "switched" on and off, to select one of the the use cases above (Default mode vs. Unit test debugging mode)?

My "idea" would be something like that:

Default mode:

karma --log-level=none

Unit test debugging mode:

karma --log-level=debug

Is this possible?

Best Answer

You can create base karma config. Than create two karma config based on base but with overwritten logLevel:

logLevel: config.LOG_DISABLE logLevel: config.LOG_DEBUG.

Then create two separate tasks in your task manager config file, for instance Gruntfile.js using those karma configs.