【问题标题】:Problems running tests with Chutzpah when I use the Chutzpah.json file使用 Chutzpah.json 文件时使用 Chutzpah 运行测试时出现问题
【发布时间】:2014-11-03 22:21:52
【问题描述】:

当我提供 Chutzpah.json 文件时,让 Chutzpah 运行我的 typescript 测试时遇到问题。

我的项目如下所示:

我的 Chutzpah.json 文件如下所示:

{
    "Compile": {
        "Mode": "External",
        "ExtensionsWithNoOutput": [ ".d.ts" ]
    },
    "Tests": [
        { "Include": "**/**.ts","Exclude": "**/**.d.ts" }
    ],
    "References": [
        {"Include": "../../hacapp.web/**/*.ts", "Exclude": "../../hacapp.web/**/**.d.ts" }
    ]
}

当我使用这个 Chutzpah.json 文件运行时,会执行 0 个测试。使用这些参数运行命令行运行器的输出:

chutzpah.consle.exe /path \hacapp.web\hacapp.web.Tests\Scrpts\TypescriptTests.ts /trace /debug

is here

生成的 html 文件的内容似乎不包含对 TypescriptTests.js 文件的任何引用:

<head>
    <meta charset="utf-8" />
    <title>QUnit Tests</title>
    <link rel="stylesheet" type="text/css" href="file:///C:/Users/sam/Source/Repos/chutzpah-master/ConsoleRunner/bin/Debug/TestFiles/QUnit/qunit.css"/>
<script type="text/javascript" src="file:///C:/Users/sam/Source/Repos/chutzpah-master/ConsoleRunner/bin/Debug/TestFiles/QUnit/qunit.js"></script>
    <script type="text/javascript" src="file:///C:/Users/sam/Source/Repos/haccpapp/hacapp.web/hacapp.web/scripts/jquery-1.10.2.js"></script>
<script type="text/javascript" src="file:///C:/Users/sam/Source/Repos/haccpapp/hacapp.web/hacapp.web/scripts/knockout-3.0.0.js"></script>
    <script>
        var amdTestPath = "";
        if (window.require && typeof window.require === "function" && amdTestPath !== "") {
            if (window.chutzpah) {
                window.chutzpah.usingModuleLoader = true;
            }

            requirejs.config({
                map: {
                    '*': {

                        }
                }
            });

            window.QUnit.config.autostart = false;
            window.require([amdTestPath], function () {
                console.log("!!_!! Starting QUnit from inline AMD call...");
                if (!window._Chutzpah_covobj_name) {
                    window.QUnit.start();
                }
            });
        }
    </script>
</head> 

如果我随后重命名 Chutzpah.json 文件以使其不再使用,然后再次运行命令行工具,那么这次它将运行测试和this is in the log file,这就是 html 的样子:

<head>
    <meta charset="utf-8" />
    <title>QUnit Tests</title>
    <link rel="stylesheet" type="text/css" href="file:///C:/Users/sam/Source/Repos/chutzpah-master/ConsoleRunner/bin/Debug/TestFiles/QUnit/qunit.css"/>
<script type="text/javascript" src="file:///C:/Users/sam/Source/Repos/chutzpah-master/ConsoleRunner/bin/Debug/TestFiles/QUnit/qunit.js"></script>
    <script type="text/javascript" src="file:///C:/Users/sam/Source/Repos/haccpapp/hacapp.web/hacapp.web/scripts/Workflow/_Chutzpah.1.WFDefinition.js"></script>
<script type="text/javascript" src="file:///C:/Users/sam/Source/Repos/haccpapp/hacapp.web/hacapp.web/scripts/jquery-1.10.2.js"></script>
<script type="text/javascript" src="file:///C:/Users/sam/Source/Repos/haccpapp/hacapp.web/hacapp.web/scripts/knockout-3.0.0.js"></script>
    <script type="text/javascript" src="file:///C:/Users/sam/Source/Repos/haccpapp/hacapp.web/hacapp.web.Tests/Scripts/_Chutzpah.1.TypescriptTests.js"></script>
    <script>
        var amdTestPath = "";
        if (window.require && typeof window.require === "function" && amdTestPath !== "") {
            if (window.chutzpah) {
                window.chutzpah.usingModuleLoader = true;
            }

            requirejs.config({
                map: {
                    '*': {

                        }
                }
            });

            window.QUnit.config.autostart = false;
            window.require([amdTestPath], function () {
                console.log("!!_!! Starting QUnit from inline AMD call...");
                if (!window._Chutzpah_covobj_name) {
                    window.QUnit.start();
                }
            });
        }
    </script>
</head>

<body>
    <h1 id="qunit-header">Unit Tests</h1>
    <h2 id="qunit-banner"></h2>
    <h2 id="qunit-userAgent"></h2>
    <ol id="qunit-tests"></ol>
    <div id="qunit-fixture"></div>
</body>
</html>

我的配置有什么问题?

【问题讨论】:

  • 嗯...好吧,因为我在您的日志中没有看到"!!_!! Starting QUnit from inline AMD call..." 消息,我猜想require() 调用永远不会在您的html 文件中完成(或开始?)。您确定已定义 window.require() 吗?我不熟悉 Chutzpah,它提供这种方法吗?如果没有,我看不出它还会在哪里定义。

标签: typescript qunit chutzpah


【解决方案1】:

更新答案

我根据给出的完整复制更新答案。原始答案保留在下面。

问题在于,默认情况下 chutzpah 会将源目录设置为查找生成的脚本到 chutzpah.json 文件的位置。将其设置为源文件夹和测试文件夹的父文件夹可以解决问题

{
    "Compile": {
        "Mode": "External",
        "Extensions": [ ".ts" ],
        "ExtensionsWithNoOutput": [ ".d.ts" ],
        "SourceDirectory": "../../",
        "OutDirectory": "../../"
    },
    "Tests": [
        { "Include": "*/*.ts","Exclude": "*/*.d.ts" }
    ],
    "References": [
        {"Include": "../../ChutzpaWeb/*/*.ts", "Exclude": "../../ChutzpaWeb/*/*.d.ts" }
    ]
}

原始答案

如果没有完整的重现,我无法确认这是否能解决您的问题,但我确实解决了几个问题。

{
    "Compile": {
        "Mode": "External",
        "Extensions": [ ".ts" ],
        "ExtensionsWithNoOutput": [ ".d.ts" ]
    },
    "Tests": [
        { "Include": "*/*.ts","Exclude": "*/*.d.ts" }
    ],
    "References": [
        {"Include": "../../hacapp.web/*/*.ts", "Exclude": "../../hacapp.web/*/*.d.ts" }
    ]
}
  1. 我将 Extensions 元素添加到您的编译节点,因此 Chutzpah 知道要考虑输入 .ts 文件
  2. 我将 ** 更改为 *。这不会导致您的问题,但不需要 **,因为 * 匹配 1 个或多个字符包括斜杠。

如果有帮助,请告诉我。

【讨论】:

  • 你好。很抱歉花了这么长时间才回复您,但直到现在我还没有时间通过​​创建完整的复制来提供帮助。无论如何,我在this github repository 中创建了该问题的最小重现。它基本上具有相同的结构,如果您打开它并在测试项目中打开 Scripts\CarTests.ts 并在窗口中右键单击并选择“运行 JS 测试”,那么测试将失败。将 Chutzpah.json 重命名为 Chutzpah1.json 并再次运行它们并通过。我看不出是什么问题。任何帮助表示赞赏
  • 如果还有什么需要补充的,请告诉我。并感谢最初的帮助!
  • 感谢一百万!为 +25 付出了很多努力和很长时间,但你让我很开心,现在希望我可以在我的 CI 服务器上运行 JS 测试。
  • 僵尸线程,我知道,但如果 +25 还不够 @SamHolder,你总是可以奖励 Matthew 赏金。 ;^D 看起来确实是一个提供全方位服务的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-11-27
  • 2022-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多