Suppress stack trace in Karma (AngularJS)

Does anyone know a way to suppress the stack trace given by karma when testing AngularJS? (Either through the configuration option or the plugin).

Ideally, I want my test report to be nothing more than a list of crashes with errors on the same line as a regular resume. I like to write out my test for this module at a time, and then use this as a direct todo list when writing the actual code. So I usually tweak it when testing other things. Instead, I get the lines and lines of the trace and have to scroll around the search for the only line that I care about:

" browser version (os) is my useful FAILED test case "

I tried various karma config logLevel config options , but I still get a trace dump.

Pay attention . I'm not looking for a discussion about the virtues of stack traces. I have a specific question and only care about a specific answer. If you know about a plugin that will provide similar or perhaps better reporting for what I'm looking for, then share it!

+5
source share
2 answers

For quite some time I could find this closed problem in the karma-jasmine project, offering to create a custom reporter locally in the configuration file

var myReporterFactory = function() { this.onRunComplete = function(browser, result) { var TOTAL_FAILED = 'TOTAL: %d FAILED, %d SUCCESS\n'; process.stdout.write( require('util').format(TOTAL_FAILED, result.error, result.success) ); }; return this; }; // ... plugins: [ // other karma plugins ... { 'reporter:myReporter': ['factory', myReporterFactory] }], 

Not sure how close to your actual result you can get ... a rather long shot. Or better, maybe switch to another reporter. Two examples:

+1
source

In karma-test-shim.js you can install ...

 Error.stackTraceLimit = 0; // No Stack trace Error.stackTraceLimit = 2; // Some Stack trace Error.stackTraceLimit = Infinity; // Full stack trace 

Tested by kjhtml reporter ( karm-jasmine-html ).

+1
source

Source: https://habr.com/ru/post/1208492/


All Articles