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:
example: testThatWorks.js
test("test that shows up in test explorer", function () {
equal("444test", "444test");
});
example: testThatAlsoWorks.js
define(
function () {
test("Test that also shows up in test explorer.", function () {
equal("444test", "444test");
});
});
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
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"}
]
}