Javascript 咕噜摩卡“幻影”超时`
我在grunt做摩卡测试的时候一直收到这个信息Javascript 咕噜摩卡“幻影”超时`,javascript,gruntjs,phantomjs,mocha.js,Javascript,Gruntjs,Phantomjs,Mocha.js,我在grunt做摩卡测试的时候一直收到这个信息 Warning: PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue. 这些测试在浏览器中运行良好,但无法从grunt开始。我一直在使用Grunt插件运行我的浏览器测试,这是GrunFile.js的相关部分 // I've checked if it does server while my tests are runni
Warning: PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue.
这些测试在浏览器中运行良好,但无法从grunt开始。我一直在使用Grunt插件运行我的浏览器测试,这是GrunFile.js的相关部分
// I've checked if it does server while my tests are running & it does
connect: {
test: {
// public is where all my files are, of course
base: 'public',
port: 8080
}
},
mocha: {
client: {
urls: ['http://0.0.0.0:8080/test.html'],
log: true,
}
},
这是test.html
文件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<link rel="stylesheet" href="css/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="js/test.js"></script>
<script>mocha.run();</script>
</body>
</html>
下面是grunt跟踪失败的结果
Running "uglify:dev" (uglify) task
File public/js/main.js created.
File public/js/test.js created.
Running "connect:test" (connect) task
Started connect web server on http://0.0.0.0:8080
Running "mocha:client" (mocha) task
Testing: http://0.0.0.0:8080/test.html
Warning: PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue.
Aborted due to warnings.
测试所需的所有src都放在一个文件中,其中包括我的源代码(及其依赖项)、mocha和测试。mocha.run()
仅在浏览器中运行测试时有效
要在浏览器和grunt中运行测试,请执行以下操作:
将mocha.run()
替换为:
if (window.mochaPhantomJS) {
mochaPhantomJS.run();
}
else {
mocha.run();
}
mocha.run()
仅在浏览器中运行测试时有效
要在浏览器和grunt中运行测试,请执行以下操作:
将mocha.run()
替换为:
if (window.mochaPhantomJS) {
mochaPhantomJS.run();
}
else {
mocha.run();
}
不知道它是否仍然与您相关,但以防其他人面临此问题: 在我的例子中,如果我直接从命令行调用它们,测试运行得非常好,比如:
mochaphantomjs.\test\src\tests.html
。只是grunt mocha
无法运行它们,抛出了这个错误。
转换到固定它为我,无需代码更改。Gruntfile如下所示:
mocha_phantomjs: {
all : ["./test/**/*.html"]
}
(如果您在jshint设置中将
camelcase
设置为true
,则可能必须转义该属性名。)不知道它是否仍然与您相关,但以防其他人遇到此问题:
在我的例子中,如果我直接从命令行调用它们,测试运行得非常好,比如:mochaphantomjs.\test\src\tests.html
。只是grunt mocha
无法运行它们,抛出了这个错误。
转换到固定它为我,无需代码更改。Gruntfile如下所示:
mocha_phantomjs: {
all : ["./test/**/*.html"]
}
(如果您在jshint设置中将
camelcase
设置为true
,则可能必须转义该属性名。)抱歉,但我已经尝试过这个(我想忘了提到它),不幸的是,它对我没有任何改变。抱歉,我已经尝试过这个(我想忘了提到它),不幸的是,我的JSHint设置将camelCase
设置为true
。如何在不更改JSHint设置的情况下使用此Grunt任务?@JN11在mocha_phantomjs之前添加/*JSHint camelcase:false*/
,在上述代码中的}
之后添加/*JSHint camelcase:true*/
。我的JSHint设置已将camelcase
设置为true
。如何在不更改JSHint设置的情况下使用此Grunt任务?@JN11在mocha_phantomjs之前添加/*JSHint camelcase:false*/
,在上述代码中的}
之后添加/*JSHint camelcase:true*/
。