alexborisov
alexborisov

Reputation: 61

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!

Upvotes: 6

Views: 1484

Answers (3)

docsa
docsa

Reputation: 61

Quick and dirty solution :

in karma-jasmine-html-reporter jasmine.css file add display:none to class .jasmine-stack-trace

Upvotes: 0

Tony O'Hagan
Tony O'Hagan

Reputation: 22692

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.

Upvotes: 2

superjos
superjos

Reputation: 12695

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:

Upvotes: 1

Related Questions