karma-stacktrace
Advanced tools
Comparing version 2.0.2 to 2.1.0
@@ -0,0 +0,0 @@ const initializeFramework = require('./lib'); |
@@ -55,11 +55,4 @@ /* eslint-env browser */ | ||
QUnit.log(details => { | ||
const { | ||
result, | ||
name, | ||
source, | ||
module, | ||
message, | ||
expected, | ||
actual | ||
} = details; | ||
const { result, name, source, module, message, expected, actual } = | ||
details; | ||
@@ -160,3 +153,3 @@ if (result || name === 'global failure') { | ||
stackFrames.forEach(s => { | ||
s.toString = function() { | ||
s.toString = function () { | ||
return s.serialized; | ||
@@ -163,0 +156,0 @@ }; |
{ | ||
"name": "karma-stacktrace", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "Provides readable mapped stacktrace for failed tests to debug the them in your browser.", | ||
@@ -37,12 +37,12 @@ "main": "index.js", | ||
"devDependencies": { | ||
"eslint": "^6.5.1", | ||
"karma": "^4.4.1", | ||
"karma-chrome-launcher": "^3.1.0", | ||
"karma-qunit": "^4.0.0", | ||
"karma-webpack": "^4.0.2", | ||
"prettier": "^1.18.2", | ||
"qunit": "^2.9.3", | ||
"serve-static": "^1.14.1", | ||
"webpack": "^4.41.2" | ||
"eslint": "^8.23.0", | ||
"karma": "^6.4.0", | ||
"karma-chrome-launcher": "^3.1.1", | ||
"karma-qunit": "^4.1.2", | ||
"karma-webpack": "^5.0.0", | ||
"prettier": "^2.7.1", | ||
"qunit": "^2.19.1", | ||
"serve-static": "^1.15.0", | ||
"webpack": "^5.74.0" | ||
} | ||
} |
# karma-stacktrace | ||
[![npm](https://img.shields.io/npm/v/karma-stacktrace.svg?style=flat-square)]() | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/sergei-startsev/karma-stacktrace/master/LICENSE) | ||
![actions](https://github.com/sergei-startsev/karma-stacktrace/workflows/Node%20CI/badge.svg) | ||
![npm](https://img.shields.io/npm/v/karma-stacktrace) | ||
![GitHub](https://img.shields.io/github/license/sergei-startsev/karma-stacktrace) | ||
## What | ||
Provides readable mapped stacktrace for failed tests to debug the them in your browser. | ||
Karma framework to provide human-readable mapped stacktraces for failed tests to make debugging easier in your browser. | ||
## Motivation | ||
Test frameworks like [QUnit](https://qunitjs.com/) and [Jasmine](http://jasmine.github.io/) use [non-standard](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack) `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. | ||
Test frameworks like [QUnit](https://qunitjs.com/) and [Jasmine](http://jasmine.github.io/) use [non-standard](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack) `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: | ||
![Original stacktrace](./stacktrace-original.png "Original stacktrace") | ||
![Original stacktrace](./stacktrace-original.png 'Original stacktrace') | ||
The framework catches failed tests and reports mapped stacktrace by using [stacktrace-js](https://www.stacktracejs.com/) library: | ||
![Mapped stacktrace](./stacktrace-mapped.png "Mapped stacktrace") | ||
![Mapped stacktrace](./stacktrace-mapped.png 'Mapped stacktrace') | ||
## Install | ||
## Install | ||
Install with `yarn`: | ||
`yarn add karma-stacktrace` | ||
`yarn add karma-stacktrace` | ||
With `npm`: | ||
`npm install karma-stacktrace` | ||
`npm install karma-stacktrace` | ||
## Karma configuration | ||
Add `stacktrace` to the list of frameworks for a corresponding karma configuration: | ||
Add `stacktrace` to the list of frameworks in your karma configuration: | ||
```js | ||
// karma.conf.js | ||
module.exports = function(config) { | ||
module.exports = function (config) { | ||
config.set({ | ||
//... | ||
frameworks: ['stacktrace'], | ||
frameworks: ['stacktrace'] | ||
//... | ||
@@ -43,7 +49,8 @@ }); | ||
To avoid blocking the main execution thread of a web application [Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) are used by default for parsing/mapping stacktrace, however you can disable it (you might need it for inline sourcemaps): | ||
To avoid blocking the main execution thread [web worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is used by default for parsing/mapping stacktrace, | ||
however you can disable it by setting `useWorker` option to `false`: | ||
```js | ||
// karma.conf.js | ||
module.exports = function(config) { | ||
module.exports = function (config) { | ||
config.set({ | ||
@@ -55,3 +62,3 @@ //... | ||
} | ||
}, | ||
} | ||
//... | ||
@@ -62,12 +69,16 @@ }); | ||
If you use inline sourcemaps (`devtool: 'inline-source-map'`) you need to disable the web worker. | ||
## Limitations/Gotchas | ||
- At the moment the framework supports only [Jasmine](http://jasmine.github.io/) and [QUnit](https://qunitjs.com/) 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. | ||
- The framework supports [Jasmine](http://jasmine.github.io/) and [QUnit](https://qunitjs.com/) testing frameworks. | ||
- The framework **does not affect** stacktrace in original messages, it attaches isolated reporters to trace mapped stacktrace. | ||
- Set `useWorker` option to `false` value for inline sourcemaps to get mapped stacktrace. | ||
## Examples | ||
See [examples](https://github.com/sergei-startsev/karma-stacktrace/tree/master/examples) folder for details. | ||
See the [karma configuration example](https://github.com/sergei-startsev/karma-stacktrace/tree/master/examples) used with webpack 5 configured to emit external sourcemaps (`devtool: 'source-map'`). | ||
## Inspired by | ||
- [sourcemapped-stacktrace](https://github.com/novocaine/sourcemapped-stacktrace) | ||
Sorry, the diff of this file is not supported yet
11560
82
205