0

I've installed the 2 Chutzpah Visual Studio add-ins (using VS 2015), the Context Menu and Test Explorer extensions. I can right click the test.js file and it runs successfully. I can run the test from Test Explorer and the test runs successfully. The problem is when I right click the test.html file, I get the following errors.

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 ==========

I have used the Chutzpah sample files for testing with the addition of a test to test JQuery is working, here are the files and Chutzpah.json file.

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" }
  ]  
}

My project folder structure:

  • WebApplication1 (Project)
    • Boiler Plate MVC Folders
    • Tests
    • codeSample
      • code.js
      • test.html
      • test.js
    • Framework
      • jquery-3.1.1.js
      • qunit-2.3.2.css
      • qunit-2.3.2.js

Ultimately, I need to update 250 JS tests to run all of them from Visual Studio. Currently, all the tests only run in TeamCity via a script.

Byron
  • 23
  • 5

2 Answers2

1

Chutzpah works best when run directly on a JS file. While Chutzpah does work on HTML files depending on your setup you may need to do more work. In this example since your test is wrapped waiting for document ready my guess is QUnit is starting running before your test registers.

You should just let Chutzpah generate the HTML for you though since that would be less maintenance and more robust.

Matthew Manela
  • 16,572
  • 3
  • 64
  • 66
  • Thanks for the reply. I tried removing the document ready and it didn't help, same error. Our Javascript tests rely heavily on the associated test html so I won't be able to let Chutzpah generate the html. You mentioned more setup may be necessary to run html files. Can you elaborate or can you provide a link to your documentation that explains it? Thanks. – Byron May 19 '17 at 19:46
  • Chutzpah tries to run qunit on its own. I think you may need in your html file to tell qunit to not auto-run: window.QUnit.config.autostart = false; – Matthew Manela May 20 '17 at 03:32
  • adding in the test html file worked to remove the error "Called start() while test already started running". The next error was, " undefined is not an object (evaluating 'QUnit.jsDump.multiline = false')". This error was because I included a version of QUnit (2.3.2) that was not compatible with the version of QUnit that Chutzpah (1.9) uses. I downgraded my QUnit version and it fixed my problem. Thanks – Byron May 22 '17 at 12:56
  • I'm sure you know, but just in case, there are some breaking changes in QUnit 2.x, [link](https://qunitjs.com/upgrade-guide-2.x/) – Byron May 22 '17 at 20:36
  • I moved on from the sample to the real test and files. I've worked through all the errors. Now when I right click and run a html file, there aren't any tests ran according to the output and log file. It reports back, ========== Total Tests: 0 passed, 0 failed, 0 total ==========. I'm not sure if it is a Chutzpah setting or something with PhantomJS? Any ideas of what to check? TIA. – Byron May 22 '17 at 20:40
  • Open up the test harness in the browser (open in browser) and launch browser debugging tools and see what is not working right is a good first step – Matthew Manela Jun 05 '17 at 15:01
0

Hit the same problem after upgrading QUnit and Chutzpah to their currently latest versions (2.3.2 and 4.3.4 respectively).
After much trying ended up reverting to the combination that worked (QUnit 1.18.0 and Chutzpah 4.2.2), which fixed the issue.

z-boss
  • 17,111
  • 12
  • 49
  • 81