Show correct stacktrace values ​​in karma tests

Background

  • Typescript

  • Karma / Jasmine

  • Webpack

Application

I have a simple TypeScript application. Also install * .ts tests and karma to run these tests. Broadcast using Webpack.

Here is part of the karma configuration:

... basePath: '', frameworks: ['jasmine','sinon'], files: [ 'src/test/spec/**/*.ts' ], preprocessors: { 'src/**/*.ts': ['webpack', 'sourcemap'] }, webpack: { debug: true, devtool: 'inline-source-map', module: webpackConfig.module, resolve: webpackConfig.resolve }, webpackMiddleware: { quiet: true, stats: { colors: true } } ... 

And setting up the web package

  ... resolve: { extensions: ['.ts', '.js', '.tsx', '.jsx', ''] }, module: { loaders: [{ test: /\.tsx?$/, exclude: /node_modules/, loader: 'ts-loader' } ] } ... 

Everything works fine, tests are written using TypeScript, PhantomJS is used as a browser without a browser. He works.

Problem

But I have problems investigating failed tests, because the stack trace written to the console is incorrect - it always points to the source test file, even the problem occurred in other places.

As an example - I pass my console output after starting karma

  TypeError: 'undefined' is not a constructor (evaluating 'new vRef(this)') at src/test/spec/validations/required.ts:1764 at DataBase (src/test/spec/validations/required.ts:1690) at src/test/spec/validations/required.ts:50 at http://localhost:9880/context.js:151 

where 'src / test / spec / validations / required.ts' is my test file, but stacktrace does go through 3 different files.

How to fix the output to correctly indicate the place of failure? I would really appreciate it if someone could share my configuration or installation problems with me.

+5
source share

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


All Articles