Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 808
andimeier Avatar asked Sep 10 '14 11:09

andimeier


People also ask

How do I enable debugging logs?

Launch Event Viewer. Select View\Show Analytic and Debug Logs. Navigate to Event Viewer (Local)\Applications and Service Logs\Microsoft\User Experience Virtualization\App Agent. Right-click on Debug under App Agent and select Enable Log.

What is logging in debugging?

A debug log can record database operations, system processes, and errors that occur when executing a transaction or running unit tests. Debug logs can contain information about: Database changes.

How do you debug Jasmine test cases?

The Jasmine test runner is just another web page made with HTML, CSS and JavaScript. This means you can debug it in the browser using the developer tools. Focus the browser window and open the developer tools. In Chrome, Firefox and Edge, you can use the F12 key.


1 Answers

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.

like image 116
SO User Avatar answered Oct 18 '22 15:10

SO User