Visual Studio Chutzpah 运行 使用 AMD 模块在不同项目上进行测试

Visual Studio Chutzpah Running test on different projects with AMD modules

我在一个解决方案下有两个项目,一个是我的主要 Web 项目,比如 MyProject,另一个用于测试目的,比如 MyProject.Tests

Solution
    MyProject
    MyProject.Tests

我想进行 JavaScript 无头测试 运行 第二个。 在第一个项目中,所有 javascript 文件都在 Scripts 目录下,如下所示:

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

在测试项目中,我的 chutzpah.json 文件位于根目录。

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

文件有这样的配置:

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

但是当我尝试 运行 规范文件时出现错误。

规格文件:

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

报错,是这样的:

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.

事情是 chutzpah 试图在测试项目而不是它所在的主项目中找到我的 jquery 模块。

为什么我会遇到这种行为,请问我该如何解决?到目前为止,我已经尝试了几个小时来解决这个问题。

备注

*名称 MySolution, MyProject, MyProject.Tests 是为了清楚起见,而不是使用真名。

我发现了,chutzpah 文件没有正确的测试工具目录配置选项(正如预期的那样)。 我需要 TestHarnessDirectoryTestHarnessLocationMode 选项来明确指示它查看我的主项目目录。

现在这是正确的:

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

只需要告诉chutzpah harness location mode是自定义的,以便为其提供一个目录,这是我的主项目的根目录。

注意正确的配置路径,您可能会像我一样挣扎数小时才能找到解决方案。并通读 documentation(我没有读完)。