如何防止在 karma runner 中加载图像
How to prevent loading images in karma runner
如何配置karma在测试时停止加载图片?我试图在我的 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
也许还有其他解决方案可以防止加载图片?最大的问题不是警告消息,而是当业力试图从我的本地服务器获取图像时出现的错误
proxies
配置看起来不正确。尝试这样的事情:
...
proxies: {
'/front-end2/assets/img/': '/base/assets/img/'
},
...
简要说明:
/front-end2/assets/img/
与正在提出的请求有关;
/assets/img/
与 files
配置中的模式相关;和
/base/
是 Karma 服务于 files
的路径。
如何配置karma在测试时停止加载图片?我试图在我的 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
也许还有其他解决方案可以防止加载图片?最大的问题不是警告消息,而是当业力试图从我的本地服务器获取图像时出现的错误
proxies
配置看起来不正确。尝试这样的事情:
...
proxies: {
'/front-end2/assets/img/': '/base/assets/img/'
},
...
简要说明:
/front-end2/assets/img/
与正在提出的请求有关;/assets/img/
与files
配置中的模式相关;和/base/
是 Karma 服务于files
的路径。