【问题标题】:Chutzpah and Jasmine typescript unit testingChutzpah 和 Jasmine 打字稿单元测试
【发布时间】:2018-09-06 12:35:13
【问题描述】:

我试图让 Chutzpah 和 Jasmine 在 Visual Studio 中一起工作,我的最终目标是让单元测试与 TeamCity 集成一起运行。

保存时,所有打字稿代码都会生成一个.js 文件。这也导致 Chutzpah 运行我的测试,到目前为止一切顺利。

我的问题是 Chutzpah 报告 0 个通过、0 个失败和 0 个错误。生成的 Jasmine html 文件正确列出了我的所有测试,但 Chutzpa 似乎没有从 Jasmine 收到任何信息。

跟踪日志的亮点:

Trying to build test context for c:\.....\test.ts
Building test context for c:\.....\test.ts
...framework dependencies / other ok looking things... (~15 lines)
Finished building test context for c:\.....\test.ts
Warning: 0 : Message:Chutzpah determined generated .js files are missing but the compile 
mode is External so Chutzpah can't compile them. Test results may be wrong.

然后它启动 Phantom js 并记录加载/接收资源。我的 test.ts 文件不是列出的资源之一,但站点范围的 .js 是(我检查了站点范围的文件并且我的测试被附加到它)。

Finished test run for c:\......\test.ts in Discovery mode
Cleaning up test context for c:\......\test.ts
Chutzpah run finished with 0 passed, 0 failed and 0 errors
Chutzpah.json file cache cleared
End Test Adapter Discover Tests

chutzpah.json

{
  "Framework": "jasmine",  
  "EnableTestFileBatching": true,
  "Compile": {
    "Mode": "External",
    "Extensions": [ ".ts" ],
    "ExtensionsWithNoOutput": [ ".d.ts" ],
    "Paths": [
      {
        "OutputPath": "../SiteWide.js",
        "SourcePath": "Views"
      }
    ]
  },
  "References": [
    {
      "Path": "../knockout-3.4.2.js",
      "IsTestFrameworkFile": true
    }
  ],
  "Tests": [
    {
      "Includes": [ "*.ts" ],
      "Path": "../Tests/Views"
    }
  ],
  "EnableTracing": true,
  "TraceFilePath": "./trace.log"
}

tests.ts

describe('configuring unit tests for typescript!', () => {
    it('this should pass', () => {
        expect(1).toBe(1);
    });

    it('this should fail', () => {
        expect(1).toBe(0);
    });
});

我对一些事情感到怀疑(跟踪中缺少 .js 文件行 - 但这可能只是由我的单个 js 文件编译步骤引起的?)

也许我的 chutzpah.json 中缺少对 jasmine 的引用?

我不知道为什么 Jasmine 测试有效,但 Chutzpah 没有报告。

【问题讨论】:

    标签: unit-testing typescript jasmine chutzpah


    【解决方案1】:

    也许迟到了…… 但是 chutzpah.json 中的类似内容会有所帮助。

    {
    "Framework": "jasmine",
    "Compile": {
        "Mode": "External",
        "Extensions": [ "*.ts" ],
        "ExtensionsWithNoOutput": [ "*.d.ts" ]
    },
    "References": [
        { "Path": "node_modules/promise-polyfill/dist", "Include": "*.js", "Exclude": "*.d.ts" },
        { "Path": "node_modules/systemjs/dist", "Include": "*.js", "Exclude": "*.d.ts" }
    ],
    "Tests": [
        { "Path": "unittests", "Includes": [ "*.spec.ts" ], "Excludes": [ "*.d.ts" ], "ExpandReferenceComments": "true" }
    ]
    

    }

    在参考资料中拥有与系统相关的文件很重要。您也可以在测试部分尝试“*.spec.js”

    【讨论】:

    • @toby 添加。谢谢
    猜你喜欢
    • 2017-05-14
    • 2017-06-21
    • 2013-11-13
    • 2016-07-18
    • 1970-01-01
    • 2017-07-22
    • 1970-01-01
    • 2019-04-05
    • 2016-05-28
    相关资源
    最近更新 更多