Path is a file error 加载测试与 Karma 和 Webpack
Path is a file error loading tests with Karma and Webpack
我正在尝试在我正在处理的 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)
package.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
这对我有用
我正在尝试在我正在处理的 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)
package.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
这对我有用