Visual Studio's Test Runner with Chutzpah won't recognize QUnit tests when using both Requirejs and knockoutjs

孤人 提交于 2019-12-11 01:59:29

问题


I'm trying to get VS 2013 test explorer with Chutzpah to recognize QUnit tests while I'm using require.js in combination with knockoutjs

I've found some good resources listed below but I think I must just have one missing piece.

  • This is what I used to ensure I was using Qunit and require.js together correctly.

  • From this resource, it sounds like I need a Chutzpah.json file as well.

Here is what I can reproduce:

  • If I just use Chutzpah and qunit I can get it to work so I know I have Chutzpah installed correctly for VS test runner.

example: testThatWorks.js

        test("test that shows up in test explorer", function () {
            equal("444test", "444test");
        });
  • If view index.html in a browser it runs my tests with the correct results.
  • If I use the define syntax it also works

example: testThatAlsoWorks.js

define(
function () {

    test("Test that also shows up in test explorer.", function () {
        equal("444test", "444test");
    });

});
  • If I use the require syntax for including any other resource it fails (this loads knockout but doesn't actually use it)

example: testThatDoesn'tWork.js

define(['knockout'],
function (ko) {

    test("Test that doesn't show up in test explorer.", function () {
        equal("444test", "444test");
    });
});

This is what VS 2013 Test explorer shows:

Here is the relevant project setup (there are other files for my real project but I'm trying to keep it simple here):

index.html (think I won't need this once I get it working in VS test runner)
tests
   references
      qunit.css
      qunit.js
      qunit.html
   chutzpah.json
   unittestsmain.js (think I won't need this once I get it working in VS test runner)
   testThatWorks.js
   testThatDoesntWork.js
   testThatAlsoWorks.js
Scripts
   jquery stuff
   require.js stuff
   knockout stuff
   ...

Here is my chutzpah.json

{
   "Framework": "qunit",
   "TestHarnessReferenceMode": "AMD",
   "TestHarnessLocationMode": "SettingsFileAdjacent",
   "References" : [
      {"Path" : "../Scripts/require.js" }
   ]
}

This is the timeout error in the Chutzpah.log file

Error: Error: Timeout occured when executing test file While Running:c:\workingfoldertfs\lesa-it\developers\whitezelb\chutzpahexample\chutzpahexample\chutzpahexample\tests\testthatdoesntwork.js vstest.executionengine.x86.exe Error: 0 : Time:12:45:01.2839495; Thread:34; Message:Headless browser returned with an error: Timeout occured when executing test file


回答1:


My error was caused by not using the correct "paths" for the dependencies. The example I show above works if the testthatdoesntwork.js file is changed to:

define(['../Scripts/knockout-3.1.0'],
function (knockout) {
    test("Test that doesn't show up in test explorer.", function () {
        equal("444test", "444test");
    }); 
});

and the Chutzpah.json file looks like:

{
"Framework": "qunit",
"TestHarnessReferenceMode": "AMD",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"References" : [
     {"Path" : "../Scripts/knockout-3.1.0.js" },
     {"Path" : "../Scripts/require.js" }

]
}

Looking at https://chutzpah.codeplex.com/workitem/214 and https://stackoverflow.com/a/22124292/451736 helped me figure out the problem I was having.

It also appears that the order of the References in the Chutzpah.json file matter because with everything else the same and the json file changed to the below the test doesn't show.

{
"Framework": "qunit",
"TestHarnessReferenceMode": "AMD",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"References" : [
     {"Path" : "../Scripts/require.js"} ,
     {"Path" : "../Scripts/knockout-3.1.0.js"}

]
}


来源:https://stackoverflow.com/questions/24071655/visual-studios-test-runner-with-chutzpah-wont-recognize-qunit-tests-when-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!