karma-stacktrace

What
Provides readable mapped stacktrace for failed tests to debug the them in your browser.
Motivation
Test frameworks like QUnit and Jasmine use non-standard stack
property of Error
object to output a stacktrace for failed unit tests. Modern browsers do not apply sourcemaps to Error.prototype.stack
and unmapped stacktrace looks useless.
An example of an unmapped stacktrace:

The framework catches failed tests and reports mapped stacktrace by using stacktrace-js library:

Install
Install with yarn
:
yarn add karma-stacktrace
With npm
:
npm install karma-stacktrace
Karma configuration
Add stacktrace
to the list of frameworks for a corresponding karma configuration:
module.exports = function(config) {
config.set({
frameworks: ['stacktrace'],
});
};
To avoid blocking the main execution thread of a web application Web Workers are used by default for parsing/mapping stacktrace, however you can disable it (you might need it for inline sourcemaps):
module.exports = function(config) {
config.set({
client: {
stacktrace: {
useWorker: false
}
},
});
};
Limitations/Gotchas
- At the moment the framework supports only Jasmine and QUnit testing frameworks.
- The framework attaches isolated reporters to trace mapped stacktrace, it does not affect stacktrace in original messages.
- It is recommended to set
useWorker
option to false
value for inline sourcemaps to get mapped stacktrace.
Examples
See examples folder for details.
Inspired by