我安装了Mocha和Babel,所以在package.json
我有:
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.11.1",
"mocha": "^3.1.2",
"mocha-loader": "^1.0.0",
"react-addons-test-utils": "^15.4.1",
"should": "^11.1.1",
"webpack": "^1.13.3"
}
一个简单的测试开始于:
// import the libraries for testing ..
import Should from 'should';
describe("Bla-bla", function() { ... });
在我的Webpack配置中,我已经设置了预设:
module: {
loaders: [
{
test: /\.(jsx|js)?$/,
exclude: /(node_modules|bower_components)/,
loader: "babel",
query: {
presets: ["es2015", "react"]
}
}
]
},
所以:
如何通过webpack运行测试,所以我自动使用babel?
如果我尝试通过mocha --compilers js:babel-core/register testsfile.js
- 我得到:
import Should from 'should';
^^^^^^
SyntaxError: Unexpected token import
在.babelrc
内添加{ "presets": ["es2015"] }
文件会导致错误消失,但我不想再使用dotfiles文件污染我的环境,而且 - 我想制作{{1}在文件保存时自动运行测试。
PS:另外 - 我尝试了另一个webpack服务器,使用mocha
这样的脚本:
npm
我希望将结果放在不同的网页上,但它只为应用程序本身提供服务,而且没有测试结果。