我正在尝试使用 yeoman 设置带有 grunt、phantomjs 和 mocha 的测试环境。问题是在运行测试任务时我收到以下警告:
Warning: PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue.
但我正在打电话
mocha.run()
在我的 index.html 文件中。这里是:<!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>
我想我的问题出在我的 Gruntfile 里面,我一定是遗漏了什么。这是我的一些 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' ]);
最佳答案
我有同样的错误消息,然后我意识到在自耕农设置中实际上有两个 bower_components 目录。
$> ls -la
...
bower_components
...
test/bower_components
当我克隆了一个 yo 生成的应用程序的 git repo 时,它具有以下 .gitignore 文件
node_modules
dist
.tmp
.sass-cache
bower_components
test/bower_components
所以你需要运行两次......
bower install
一次进入 [root],一次进入 [root]/test
关于gruntjs - 使用 grunt、phantomjs 和 mocha 设置测试环境失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21501320/