gpt4 book ai didi

javascript - mocha-phantomjs 的 mocha init 超时

转载 作者:可可西里 更新时间:2023-11-01 02:23:49 24 4
gpt4 key购买 nike

我有以下 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 本身(来自 mocha 示例):

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 时,出现以下错误:

启动 mocha 失败:初始化超时

我可能在这里遗漏了什么?

我也试过 mocha-phantomjs http://httpjs.herokuapp.com 失败并出现同样的错误。

更新:如果我正在调用 mocha-phantomjs http://localhost:81/client/specs/testrunner.html 我也会在控制台上收到以下错误:

RangeError: Maximum call stack size exceeded.

http://localhost:81/client/lib/chai.js?v=123423553533535:2601
Failed to start mocha: Init timeout

最佳答案

通过 grunt-mocha-phantomjs npm 包运行 mocha-phantomjs 时,我遇到了同样的 Failed to start mocha 错误。找到解决方案 here .

在此重复以供引用:

要使用 mocha-phantomjs 运行,请更改

mocha.run();

if (mochaPhantomJS) {
mochaPhantomJS.run();
}
else {
mocha.run();
}

关于javascript - mocha-phantomjs 的 mocha init 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15657458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com