Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress the stack trace in Karma (AngularJS)

Does anyone know of a way to suppress the stack trace given by Karma when testing AngularJS? (Either via a config option or plugin).

Ideally I want my test report to be nothing more than a list of single line test case failures with the usual summary. I like writing out my test for a given module in one go and then using this as a straight forward todo list when writing actual code. This is how I usually have it setup when unit testing other stuff. Instead I get lines and lines of a trace and have to scroll around searching for the only line I care about:

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

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

Please note: I am not looking for a debate on the merits of stack traces. I have a specific question and only care about a specific answer. If you know of a plugin that will provide similar or perhaps superior reporting to what I am looking for then please do share!

like image 638
alexborisov Avatar asked Dec 06 '14 13:12

alexborisov


2 Answers

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

Error.stackTraceLimit = 0; // No Stack trace

Error.stackTraceLimit = 2; // Some Stack trace

Error.stackTraceLimit = Infinity; // Full stack trace

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

like image 166
Tony O'Hagan Avatar answered Nov 05 '22 03:11

Tony O'Hagan


Quite some time later, I could only find this closed issue on karma-jasmine project, suggesting to create a custom reporter locally in config 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 one could get ... quite a long shot. Or better maybe switch to a different reporter. Two examples here:

  • karma-mocha-reporter, with its output and maxLogLines options

  • karma-nyan-reporter (!!), as funny as it can sound, with its suppressErrorReport option

like image 28
superjos Avatar answered Nov 05 '22 01:11

superjos