如何防止在业力跑步者中加载图像

时间:2016-09-03 17:54:08

标签: unit-testing karma-runner karma-mocha

如何配置业力以在测试时停止加载图像?我试图在我的karma.config.js中使用来自here的解决方案:

var webpack = require('webpack');

module.exports = function (config) {
   config.set({
      browsers: [ 'Chrome' ],
      singleRun: true,
      frameworks: [ 'mocha' ],
      files: [
         'tests.webpack.js',
         {pattern: './assets/img/signup.png', watched: false, included: false, served: true},
      ],
      proxies: {
         '/assets/img/signup.png': '/assets/img/signup.png'
      },
      preprocessors: {
         'tests.webpack.js': [ 'webpack', 'sourcemap' ]
      },
      reporters: ['mocha'],
      mochaReporter: {},
      webpack: {
         devtool: 'inline-source-map',
         module: {
            loaders: [
               {
                  test: /\.js$/,
                  exclude: /node_modules/,
                  loader: 'babel-loader',
                  query: {
                     cacheDirectory: true,
                     plugins: ['transform-decorators-legacy' ],
                     presets: ['airbnb', 'es2015', 'stage-1', 'react']
                  }
               }
            ]
         },
         externals: {
            'cheerio': 'window',
            'react/addons': true,
            'react/lib/ExecutionEnvironment': true,
            'react/lib/ReactContext': true
         }
      },
      webpackServer: {
         noInfo: true //please don't spam the console when running in karma!
      }
   });
};

但这对我不起作用。我仍然得到错误:

[web-server]: 404: /front-end2/assets/img/signup.png

也许还有其他解决方案来阻止加载图片?最大的问题不是警告信息,而是当业力试图从我的本地服务器获取图像时出现的错误

1 个答案:

答案 0 :(得分:1)

proxies配置看起来不正确。尝试这样的事情:

...
proxies: {
    '/front-end2/assets/img/': '/base/assets/img/'
},
...

简要说明:

  • /front-end2/assets/img/与正在提出的请求有关;
  • /assets/img/files配置中的模式相关联;和
  • /base/是Karma为files提供服务的路径。