Chutzpah, Error: Called start() while test already started running, when I "Run JS Tests" on a simple html file

Chutzpah, Error: Called start() while test already started running, when I "Run JS Tests" on a simple html file

我已经安装了 2 个 Chutzpah Visual Studio 插件(使用 VS 2015)、上下文菜单和测试资源管理器扩展。我可以右键单击 test.js 文件并成功 运行s。我可以 运行 来自测试资源管理器的测试和测试 运行 成功。问题是当我右键单击 test.html 文件时,出现以下错误。

Error: Error: Called start() while test already started running at start in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 2679) at startQUnit (line 12) at onPageLoaded (line 16) (line 18) While Running:C:\Users\byron\documents\visual studio 2015\Projects\WebApplication1\WebApplication1\Tests\codeSample\test.html ------ Test started: File: C:\Users\byron\documents\visual studio 2015\Projects\WebApplication1\WebApplication1\Tests\codeSample\test.html ------ Error: TypeError: undefined is not an object (evaluating 'QUnit.jsDump.multiline = false') at log in undefined (line 88) at runLoggingCallbacks in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 1036) at logAssertion in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 1701) at pushResult in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 1672) at pushFailure in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 1685) at run in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 1430) in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 1620) at advance in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 1105) at begin in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 2796) in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 2756) While Running:C:\Users\byron\documents\visual studio 2015\Projects\WebApplication1\WebApplication1\Tests\codeSample\test.html Error: TypeError: undefined is not an object (evaluating 'QUnit.jsDump.multiline = false') at log in undefined (line 88) at runLoggingCallbacks in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 1036) at logAssertion in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 1701) at pushResult in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 1672) at pushFailure in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 1685) at pushFailure in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 1822) at onError in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 2560) at onerror in file:///C:/Users/byron/documents/visual%20studio%202015/Projects/WebApplication1/WebApplication1/Tests/Framework/qunit-2.3.2.js (line 3844) While Running:C:\Users\byron\documents\visual studio 2015\Projects\WebApplication1\WebApplication1\Tests\codeSample\test.html Error: Timeout occurred when executing test file While Running:C:\Users\byron\documents\visual studio 2015\Projects\WebApplication1\WebApplication1\Tests\codeSample\test.html ========== Total Tests: 0 passed, 0 failed, 0 total ==========

我已经使用 Chutzpah 示例文件进行测试,并添加了一个测试来测试 JQuery 是否有效,这里是文件和 Chutzpah.json 文件。

test.html

    <html>
<head>
    <link rel="stylesheet" href="../Framework/qunit-2.3.2.css" type="text/css" />

    <script type="text/javascript" src="../Framework/jquery-3.1.1.js"></script>
    <script type="text/javascript" src="../Framework/qunit-2.3.2.js"></script>
    <script type="text/javascript" src="code.js"></script>
    <script type="text/javascript" src="test.js"></script>
</head>
<body>
<h1 id="qunit-header">Unit Tests</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests">
</ol>
<div id="qunit-fixture">test markup, will be hidden</div>
</body>
</html>

test.js

/// <reference path="code.js"/>

QUnit.module("test");

$(document).ready(function() {
    QUnit.test("will add 5 to number",
        function() {
            var res = mathLib.add5(10);

            QUnit.assert.equal(res, 15, "should add 5");
        });

QUnit.test("test jquery",
    function() {
        var result = $("#qunit-fixture");
        QUnit.assert.ok(result.length > 0);
    });
});

code.js

var mathLib = {
    add5: function (a) {
        return a + 5;
    }
}

Chutzpah.json

{
  "RootReferencePathMode": "SettingsFileDirectory",
  "References": [
    { "Path": "Framework" }
  ]  
}

我的项目文件夹结构:

最终,我需要将 250 个 JS 测试从 Visual Studio 更新到 运行。目前,所有测试仅通过脚本在 TeamCity 中 运行。

当 运行 直接在 JS 文件上时,Chutzpah 效果最佳。虽然 Chutzpah 确实可以处理 HTML 文件,但取决于您的设置,您可能需要做更多的工作。在此示例中,因为您的测试已包装等待文档准备就绪,所以我猜测 QUnit 在您的测试注册之前 运行ning 开始。

不过,您应该让 Chutzpah 为您生成 HTML,因为那样会减少维护工作,而且更加健壮。

将 QUnit 和 Chutzpah 升级到当前最新版本(分别为 2.3.2 和 4.3.4)后遇到同样的问题。
经过多次尝试最终恢复到有效的组合(QUnit 1.18.0 和 Chutzpah 4.2.2),这解决了问题。