Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Karma to show minified code in debug/errors?

I have integrated Karma/Jasmine into my Ionic App following this blog post recommended by the official Ionic Testing Example.

It is working but when I have an error Karma shows me the code in their minified form:

Error: StaticInjectorError(e)[e -> e]:
StaticInjectorError(Platform: core)[e -> e]:
NullInjectorError: No provider for e!

As you can imagine, it is kind of hard to know what "e" is sometimes. Is there a way to change/configure this? I have not found where and in the videos/posts that I saw it is directly in an unminified form.

Jus in case, the complete error:

error properties: Object({ ngTempTokenPath: null, ngTokenPath: [ 'e', 
Function ] })
Error: StaticInjectorError(e)[e -> e]: 
  StaticInjectorError(Platform: core)[e -> e]: 
    NullInjectorError: No provider for e!
    at e.get (http://localhost:9876/base/test-config/karma-test-shim.js:45:135)
    at http://localhost:9876/base/test-config/karma-test-shim.js:52:2430
    at le (http://localhost:9876/base/test-config/karma-test-shim.js:52:2448)
    at e.get (http://localhost:9876/base/test-config/karma-test-shim.js:52:1612)
    at http://localhost:9876/base/test-config/karma-test-shim.js:52:2430
    at le (http://localhost:9876/base/test-config/karma-test-shim.js:52:2448)
    at e.get (http://localhost:9876/base/test-config/karma-test-shim.js:52:1612)
    at oi (http://localhost:9876/base/test-config/karma-test-shim.js:298:681)
    at http://localhost:9876/base/test-config/karma-test-shim.js:298:869
    at si (http://localhost:9876/base/test-config/karma-test-shim.js:298:1053)
    at oi (http://localhost:9876/base/test-config/karma-test-shim.js:298:639)
    at e.get (http://localhost:9876/base/test-config/karma-test-shim.js:313:9035)
    at e.get (http://localhost:9876/base/test-config/karma-test-shim.js:471:6725)
    at Function.e.get (http://localhost:9876/base/test-config/karma-test-shim.js:471:2525)
    at UserContext.<anonymous> (http://localhost:9876/base/test-config/karma-test-shim.js:702:99461)
    at e.invoke (http://localhost:9876/base/test-config/karma-test-shim.js:514:7001)
    at e.onInvoke (http://localhost:9876/base/test-config/karma-test-shim.js:618:2261)
    at e.invoke (http://localhost:9876/base/test-config/karma-test-shim.js:514:6941)
    at t.run (http://localhost:9876/base/test-config/karma-test-shim.js:514:2171)
    at l (http://localhost:9876/base/test-config/karma-test-shim.js:656:1318)
    at UserContext.<anonymous> (http://localhost:9876/base/test-config/karma-test-shim.js:656:1428)
    at <Jasmine>
    at e.invokeTask (http://localhost:9876/base/test-config/karma-test-shim.js:514:7685)
    at t.runTask (http://localhost:9876/base/test-config/karma-test-shim.js:514:2865)
    at m (http://localhost:9876/base/test-config/karma-test-shim.js:514:9934)

./test-config/karma.conf.js

var webpackConfig = require('./webpack.test.js');

module.exports = function (config) {
    var _config = {
        basePath: '../',

        frameworks: ['jasmine'],

        files: [
            './test-config/ssd-refresh-debug.js',
            {
                pattern: './test-config/karma-test-shim.js',
                watched: true
            },
            {
                pattern: './src/assets/**/*',
                watched: false,
                included: false,
                served: true,
                nocache: false
            }
        ],

        proxies: {
            '/assets/': '/base/src/assets/'
        },

        preprocessors: {
            './test-config/karma-test-shim.js': ['webpack', 'sourcemap']
        },

        webpack: webpackConfig,

        webpackMiddleware: {
            stats: 'errors-only'
        },

        webpackServer: {
            noInfo: true
        },

        browserConsoleLogOptions: {
            level: 'log',
            format: '%b %T: %m',
            terminal: true
        },

        coverageIstanbulReporter: {
            reports: ['html', 'lcovonly'],
            fixWebpackSourcePaths: true
        },

        reporters: config.coverage ? ['kjhtml', 'dots', 'coverage-istanbul'] : ['kjhtml', 'dots'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['Chrome'],
        singleRun: false,
    };

    config.set(_config);
};

./test-config/webpack.test.js

var webpack = require('webpack');
var path = require('path');

module.exports = {
  devtool: 'inline-source-map',

  resolve: {
    extensions: ['.ts', '.js']
  },

  module: {
    rules: [{
        test: /\.ts$/,
        loaders: [{
          loader: 'ts-loader'
        }, 'angular2-template-loader']
      },
      {
        test: /.+\.ts$/,
        exclude: /(index.ts|mocks.ts|\.spec\.ts$)/,
        loader: 'istanbul-instrumenter-loader',
        enforce: 'post',
        query: {
          esModules: true
        }
      },
      {
        test: /\.html$/,
        loader: 'html-loader?attrs=false'
      },
      {
        test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
        loader: 'null-loader'
      }
    ]
  },

  plugins: [
    new webpack.ContextReplacementPlugin(
      // The (\\|\/) piece accounts for path separators in *nix and Windows
      /(ionic-angular)|(angular(\\|\/)core(\\|\/)@angular)/,
      root('./src'), // location of your src
      {} // a map of your routes
    )
  ]
};

function root(localPath) {
  return path.resolve(__dirname, localPath);
}

./test-config/karma-test-shim.js

Error.stackTraceLimit = Infinity;

require('core-js/es6');
require('core-js/es7/reflect');

require('zone.js/dist/zone');
require('zone.js/dist/long-stack-trace-zone');
require('zone.js/dist/proxy');
require('zone.js/dist/sync-test');
require('zone.js/dist/jasmine-patch');
require('zone.js/dist/async-test');
require('zone.js/dist/fake-async-test');

var appContext = require.context('../src', true, /\.spec\.ts/);

appContext.keys().forEach(appContext);

var testing = require('@angular/core/testing');
var browser = require('@angular/platform-browser-dynamic/testing');

testing.TestBed.initTestEnvironment(browser.BrowserDynamicTestingModule, browser.platformBrowserDynamicTesting());
like image 722
distante Avatar asked Dec 20 '25 03:12

distante


2 Answers

We encountered a very similiar issue when executing our test cases post updating our webpack version. We fixed it by adding the following property in the webpack.test.js config file

mode:'development'
like image 157
Akshay Nair Avatar answered Dec 22 '25 21:12

Akshay Nair


Disabling the preprocessors Karma configuration in the karma.conf.js did it.

var karmaConfig = {
...

  preprocessors: {
    // 'js/**/*.js': 'coverage' // here disable it
    },
  reporters: ['spec', 'coverage'],


...
like image 30
Melchia Avatar answered Dec 22 '25 20:12

Melchia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!