gpt4 book ai didi

karma-runner - 路径是使用 Karma 和 Webpack 加载测试的文件错误

转载 作者:行者123 更新时间:2023-12-04 05:09:52 26 4
gpt4 key购买 nike

我正在尝试在我正在处理的 webpack 项目上设置 Karma 测试运行器。我有一些我试图包含的测试文件,但 Karma 不断给我 Error: Path is a file '/_karma_webpack_/app/w/tests/components' .为什么MemoryFileSystem此消息失败?感谢所有帮助。

我的 karma.conf.js:

    //Require webpack config rather than duplicating it
var webpackConfig = require('./webpack.config');
webpackConfig.devtool = 'inline-source-map';

module.exports = function(config) {
config.set({
basePath:'',
browsers: ['Chrome_without_sandbox'], // Note: PhantomJS has too outdated WebKit, pre ES5, to work with Browserify
singleRun: true,
customLaunchers: {
Chrome_without_sandbox: {
base: 'Chrome',
flags: ['--no-sandbox'] // w/ sandbox it fails under Docker
}
},
frameworks: ['mocha'],
files: ['./app/w/tests/**/*-test.js'],
webpack: webpackConfig,
webpackMiddleware: {
noInfo: true
},
preprocessors: {
'./app/w/tests/**/*-test.js' : ['webpack']
}
});
};

我尝试使用 require.context 加载文件并将它们捆绑在一起,但结果是一样的..所以我认为问题可能出在 MemoryFileSystem期望作为输入。

webpack.config.js
var webpack = require('webpack');
var bower_dir = __dirname + '/bower_components';
var config = {
//devtool: 'cheap-module-eval-source-map',
devtool: 'eval',
entry: {
app: ['webpack/hot/dev-server', './app/w/scripts/app.js']
},
resolve: { alias: {} },
output: {
path: './app/w/dist',
filename: 'app.js',
publicPath: '/dist/'
},
module: {
noParse: [],
loaders: [
{ test: /\.js$/, loader: 'eslint!babel?optional[]=runtime', exclude: /node_modules/},
{ test: /\.json$/, loader: 'json'},
{ test: /\.png$/, loader: "url?limit=10000&mimetype=image/png" },
{ test: /\.woff$/, loader: "url?limit=10000&mimetype=application/font-woff" },
{ test: /\.ttf$/, loader: "url?limit=10000&mimetype=application/octet-stream" },
{ test: /\.eot$/, loader: "file" },
{ test: /\.svg$/, loader: "url?limit=10000&mimetype=image/svg+xml" },
{ test: /\.less/, loader: 'style!css!less'}

]
},
plugins: new webpack.optimize.UglifyJsPlugin({
minimize: true,
sourceMap: false,
})
};

module.exports = config;

错误日志:
ERROR [karma]: [Error: Path is a file '/_karma_webpack_/app/w/tests/components']
Error: Path is a file '/_karma_webpack_/app/w/tests/components'
at MemoryFileSystem.mkdirpSync (/Users/magnuslien/Documents/internprosjekter/woop-frontend/node_modules/karma-webpack/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:116:10)
at MemoryFileSystem.(anonymous function) [as mkdirp] (/Users/magnuslien/Documents/internprosjekter/woop-frontend/node_modules/karma-webpack/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:193:34)
at Tapable.<anonymous> (/Users/magnuslien/Documents/internprosjekter/woop-frontend/node_modules/webpack/lib/Compiler.js:244:27)
at /Users/magnuslien/Documents/internprosjekter/woop-frontend/node_modules/webpack/node_modules/async/lib/async.js:187:20
at /Users/magnuslien/Documents/internprosjekter/woop-frontend/node_modules/webpack/node_modules/async/lib/async.js:239:13
at _arrayEach (/Users/magnuslien/Documents/internprosjekter/woop-frontend/node_modules/webpack/node_modules/async/lib/async.js:91:13)
at _each (/Users/magnuslien/Documents/internprosjekter/woop-frontend/node_modules/webpack/node_modules/async/lib/async.js:82:13)
at Object.async.forEachOf.async.eachOf (/Users/magnuslien/Documents/internprosjekter/woop-frontend/node_modules/webpack/node_modules/async/lib/async.js:238:9)
at Object.async.forEach.async.each (/Users/magnuslien/Documents/internprosjekter/woop-frontend/node_modules/webpack/node_modules/async/lib/async.js:215:22)
at Tapable.emitFiles (/Users/magnuslien/Documents/internprosjekter/woop-frontend/node_modules/webpack/lib/Compiler.js:234:20)

包.json
 "devDependencies": {
"babel-loader": "^5.3.2",
"browserify": "^11.0.1",
"karma": "^0.12.31",
"karma-chrome-launcher": "^0.2.0",
"karma-mocha": "^0.2.0",
"karma-sourcemap-loader": "^0.3.5",
"karma-webpack": "^1.7.0",
"mocha": "^2.2.5",
"proxyquireify": "^3.0.0",
"webpack": "^1.11.0",
"webpack-dev-server": "^1.10.1"
}

最佳答案

我有同样的问题。

不知何故, webpack.config.js 不允许有入口应用程序。

添加
webpackConfig.entry = {};
就在这条线之下
webpackConfig.devtool = 'inline-source-map';在你的 karma.conf.js 中

这对我有用

关于karma-runner - 路径是使用 Karma 和 Webpack 加载测试的文件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32201797/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com