使用mocha-phantomjs的mocha初始化超时 [英] mocha init timeout with mocha-phantomjs
问题描述
我有以下testrunner.html
:
<html>
<head>
<title>Specs</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="/content/css/mocha.css" />
<script>
function assert(expr, msg) {
if (!expr) throw new Error(msg || 'failed');
}
</script>
<script src="/client/lib/require.js" type="text/javascript" data-main="/client/specs/_runner.js"></script>
</head>
<body>
<div id="mocha"></div>
</body>
</html>
_runner.js
看起来像这样:
// Configure RequireJS
require.config({
baseUrl: '/client',
urlArgs: "v=" + (new Date()).getTime()
});
// Require libraries
require(['require', 'lib/chai', 'lib/mocha'], function (require, chai) {
// Chai
assert = chai.assert;
should = chai.should();
expect = chai.expect;
// Mocha
mocha.setup('bdd');
// Require base tests before starting
require(['specs/stringcalculator.specs'], function (person) {
mocha.setup({ globals: ['hasCert'] });
// Start runner
if (window.mochaPhantomJS) {
mochaPhantomJS.run();
}
else { mocha.run(); }
});
});
StringCalculator.specs.js
是这样的:
define(['app/model/StringCalculator'], function () {
describe("StringCalculator", function () {
describe("when an empty string is passed in", function () {
it("returns 0", function () {
var result = StringCalculator.add("");
assert(result === 0);
});
});
describe("when a number is passed in", function () {
it("returns the number", function () {
var result = StringCalculator.add("2");
assert(result === 2);
});
});
describe("when string is passed in", function () {
it("returns NaN", function () {
var result = StringCalculator.add("a");
assert(isNaN(result));
});
});
describe("when '1,2' is passed in", function () {
it("returns 3", function () {
var result = StringCalculator.add("1,2");
assert(result === 3);
});
});
});
});
这是StringCalculator.js
本身(来自摩卡咖啡样本):
And this is the StringCalculator.js
itself (from the mocha samples):
define([], function() {
window.StringCalculator = StringCalculator = {
add: function(inputString) {
if (inputString === '') {
return 0;
}
var result = 0;
var inputStrings = inputString.split(',');
for (var i = 0; i < inputStrings.length; i++) {
result += parseInt(inputStrings[i]);
}
return result;
}
}
});
在调用testrunner.html
的浏览器中运行规格时,一切正常.
在OS X上运行mocha-phantomjs client/specs/testrunner.html
时,出现以下错误:
When running the specs in a browser calling testrunner.html
, everything works as expected.
When running mocha-phantomjs client/specs/testrunner.html
on OS X, I get the following error:
Failed to start mocha: Init timeout
我在这里可能想念什么?
What may I'm missing here?
我还尝试了mocha-phantomjs http://httpjs.herokuapp.com
,但失败并出现相同的错误.
I also tried mocha-phantomjs http://httpjs.herokuapp.com
which fails with the same error.
更新:
如果我呼叫mocha-phantomjs http://localhost:81/client/specs/testrunner.html
,我也会在控制台上收到以下错误:
Update:
If I'm calling mocha-phantomjs http://localhost:81/client/specs/testrunner.html
I also get the following error on the console:
RangeError: Maximum call stack size exceeded.
http://localhost:81/client/lib/chai.js?v=123423553533535:2601
Failed to start mocha: Init timeout
推荐答案
对我来说,NodeJS 0.10.x似乎无法使用它.切换到NodeJS 0.8.8之后,一切都会按预期进行.
使用mocha-phantomjs和PhantomJS的当前版本,现在一切正常.
Using the current versions of mocha-phantomjs and PhantomJS now everything works fine.
这篇关于使用mocha-phantomjs的mocha初始化超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!