Tracing errors using karma + babel + webpack with bundles

牧云@^-^@ 提交于 2019-12-24 13:05:46

问题


Using karma + babel + webpack to run ES6 unit tests. I use a webpack bundle to locate and transpile the ES6. It all works, but whenever there is an error in any test file I get messages with no indication where the error originated, like

Uncaught TypeError: Cannot read property 'querySelector' of null
at /pth/to/test.bundle.js:13256

It's always /pth/to/test.bundle.js:xxxx. Any idea how to make it show more useful messages?

Here's my config

module.exports = function(config) {
  config.set({
    browsers: ["Chrome"],
    files: [
      {
        pattern: "test.bundle.js",
        watched: false
      }],
    frameworks: ["jasmine-jquery", "jasmine-ajax", "jasmine"],
    preprocessors: {,
        "test.bundle.js": ["webpack"]
    },
    reporters: ["dots"],
    singleRun: false,
    webpack: {
        module: {
            loaders: [{
                  test: /\.js/,
                  exclude: /node_modules/,
                  loader: "babel-loader?cacheDirectory&optional[]=runtime"
                }]
        },
        watch: true
    },
    webpackServer: {
        noInfo: true
    }
  });
};

And my test.bundle.js

var context = require.context("./src", true, /.+(-helpers|\.test)\.js$/);
context.keys().forEach(context);

回答1:


Set devtool to eval in webpack. It works for me. Will give you correct file name with line no. Read more here http://webpack.github.io/docs/configuration.html#devtool

webpack: {
    devtool: 'eval',
    module: {
        loaders: [{
              test: /\.js/,
              exclude: /node_modules/,
              loader: "babel-loader?cacheDirectory&optional[]=runtime"
            }]
    },
    watch: true
},


来源:https://stackoverflow.com/questions/32625884/tracing-errors-using-karma-babel-webpack-with-bundles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!