我正在使用webpack和karma-mocha-chai进行Angular项目的单元测试。
设置测试框架我面临以下错误:
karma start
05 06 2016 18:29:04.739:ERROR [config]: Invalid config file!
TypeError: Path must be a string. Received { vendor: [ 'jquery', 'angular' ],
bundle: [ 'babel-polyfill', './src/app.js' ] }
at assertPath (path.js:8:11)
at Object.posix.resolve (path.js:426:5)
at Object.<anonymous> (/Users/samirshah/Desktop/nuskin-chai/karma.conf.js:3:18)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.parseConfig (/usr/local/lib/node_modules/karma/lib/config.js:284:22)
at new Server (/usr/local/lib/node_modules/karma/lib/server.js:57:20)
at Object.exports.run (/usr/local/lib/node_modules/karma/lib/cli.js:243:7)
at Object.<anonymous> (/usr/local/lib/node_modules/karma/bin/karma:3:23)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
weboack.config.js
entry: {
vendor: ["jquery", "angular"],
bundle: ['babel-polyfill', './src/app.js'],
},
的package.json
"scripts": {
"dev": "webpack-dev-server --inline --port 3000 --content-base public/",
"build": "webpack",
"lint": "eslint src/ ; true",
"test": "NODE_ENV = testkarma start"
},
构建和开发工作正常,但单元测试正在抛出错误。我检查过我的karma.conf.js文件没有问题。
答案 0 :(得分:0)
我有同样的问题。在我的业力配置文件中我有这样的事情:
var path = require('path');
var webpackConfig = require('./webpack.config');
var entry = path.resolve(webpackConfig.context, webpackConfig.entry);
...
问题是我的 webpack.config.js 文件中的webpackConfig.entry
是一个对象不是字符串(因此&#34 ;路径必须是字符串&#34; 消息)。
希望它有所帮助,欢呼!