我正在尝试使用自耕农设置grunt,phantomjs和mocha的测试环境。问题是当运行测试任务时我收到了以下警告:
Warning: PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue.
但我在index.html文件中调用了mocha.run()
。这是:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Mocha Spec Runner</title>
<link rel="stylesheet" href="bower_components/mocha/mocha.css">
</head>
<body>
<div id="mocha"></div>
<script src="bower_components/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script src="bower_components/chai/chai.js"></script>
<script>
var assert = chai.assert;
var expect = chai.expect;
var should = chai.should();
</script>
<!-- include source files here... -->
<!-- include spec files here... -->
<script src="spec/test.js"></script>
<script>
mocha.run();
</script>
</body>
</html>
我认为我的问题出在我的Grunt文件中,我必须遗漏一些东西。这是我的一些Gruntfile:
connect: {
test: {
options: {
port: 9001,
base: [
'.tmp',
'test',
'<%= yeoman.app %>'
]
}
},
...
mocha: {
test: {
src: ['test/*.html'],
options: {
urls: [ 'http://localhost:9001/test/index.html' ]
}
}
}
...
grunt.registerTask('test', [
'clean:server',
'concurrent:test',
'autoprefixer',
'connect:test',
'mocha' ]);
答案 0 :(得分:8)
我有相同的错误消息然后我意识到在yeoman设置中实际上有两个bower_components目录。
$> ls -la
...
bower_components
...
test/bower_components
当我克隆了一个你生成的应用程序的git repo时,它有以下.gitignore文件
node_modules
dist
.tmp
.sass-cache
bower_components
test/bower_components
所以你需要运行两次......
bower install
进入[root]并进入[root] / test
答案 1 :(得分:0)
尝试设置mocha.test.options.run = true