【问题标题】:Visual Studio Chutzpah Running test on different projects with AMD modulesVisual Studio Chutzpah 使用 AMD 模块在不同项目上运行测试
【发布时间】:2015-04-17 14:02:01
【问题描述】:

我在一个解决方案下有两个项目,一个是我的主要 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是为了清楚起见,而不是使用真实姓名。

【问题讨论】:

    标签: javascript visual-studio-2013 requirejs amd chutzpah


    【解决方案1】:

    我找到了,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 线束位置模式是自定义的,以便为其提供一个目录,这是我的主项目的根目录。

    那么,请注意正确的配置路径,您最终可能会像我一样苦苦挣扎数小时才能找到解决方案。并彻底阅读documentation(我没有这样做)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-26
      • 2013-02-22
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多