Visual Studio Chutzpah Run test on various projects with AMD modules

I have two projects under the solution, one is my main web project, say MyProject

and the other is for testing, say MyProject.Tests

.

Solution
    MyProject
    MyProject.Tests

      

I want my JavaScript homeless tests to run to the second. In the first project, all javascript files are in a directory Scripts

, for example:

Scripts/
    Common.js
    Libs/
        jquery/
            jquery.js
        requirejs/
            require.js

      

In a test project, I have a chutzpah.json file for root.

MyProject.Tests
    chutzpah.json
    Tests/
        Specs/
            spec.js

      

The file has the following configuration:

{
    "Framework": "jasmine",
    "TestHarnessReferenceMode": "AMD",
    "TestHarnessLocationMode": "SettingsFileAdjacent",
    "Tests": [ { "Path": "Tests/Specs" } ],
    "AMDBasePath": "../MyProject/Scripts",
    "CodeCoverageExcludes": ["*Common.js"],
    "References": [
        { "Path": "../MyProject/Scripts/Libs/requirejs/require.js" },
        { "Path": "../MyProject/Scripts/Common.js" }
    ]
}

      

But when I try to run the spec file, I get an error.

Spec file:

define(["jquery"], function ($) {
    //code here. Doesn't matter, the error is because of the jquery module
});

      

The error is:

Error: Error opening C:/Users/g.dyrrahitis/Documents/Visual Studio 2013/Projects/MySolution/MyProject.Tests/Scripts/Libs/jquery/jquery.js: The system cannot find the path specified.

      

The thing is, chutzpah is trying to find my jquery module in the test project and not in the main project where it is located.

Why am I getting this behavior and how can I solve it? I've tried for hours now with no luck.

Note

* Names MySolution, MyProject, MyProject.Tests

are used for clarity and not for the use of real names.

+3


source to share


1 answer


I found it, the chutzpah file did not have the correct config options (as expected) for the test harness directory. I need the TestHarnessDirectory

and parameters TestHarnessLocationMode

to explicitly instruct him to look at my main project directory.

This is now the correct option:

{
    "TestHarnessDirectory": "../MyProject",
    "TestHarnessLocationMode": "Custom",
    "TestHarnessReferenceMode": "AMD",

    "Framework": "jasmine",
    "Tests": [ { "Path": "JavaScript/Specs" } ],
    "AMDBasePath": "../MyProject/Scripts",
    "CodeCoverageExcludes": [ "*Common.js" ],
    "References": [
        { "Path": "../MyProject/Scripts/Libs/requirejs/require.js" },
        { "Path": "../MyProject/Scripts/Common.js" }
    ]
}

      



Just need to tell chutzpah that the wiring location mode is normal to provide it with the directory that is the root of my main project.

Beware of correct configuration paths, then you might run into for hours like me to find a solution. And read the documentation carefully (which I haven't done yet).

+3


source







All Articles