简体   繁体   English

使用TFS 2015运行Jest单元测试

[英]Run Jest unit test with TFS 2015

Has anyone attempted to integrate jest unit tests with TFS 2015? 有没有人试图将开玩笑单元测试与TFS 2015集成? I tried to use Chutzpah Test Adapter ( https://visualstudiogallery.msdn.microsoft.com/f8741f04-bae4-4900-81c7-7c9bfb9ed1fe?SRC=VSIDE ) however it's not able to recognize jest. 我试图使用Chutzpah测试适配器( https://visualstudiogallery.msdn.microsoft.com/f8741f04-bae4-4900-81c7-7c9bfb9ed1fe?SRC=VSIDE )但是它无法识别开玩笑。 I receive below error: Can't find variable Jest 我收到以下错误: 无法找到变量Jest

When I run the unit tests through "npm test" I get the results. 当我通过“npm test”运行单元测试时,我得到了结果。 However to integrate with TFS 2015 I need a test runner which can run Jest unit test so that I can run the unit tests in conjunction with vstest.console.exe which the TFS 2015 provides so it can manage build results and publish results in the build summary report. 但是为了与TFS 2015集成,我需要一个可以运行Jest单元测试的测试运行器,以便我可以与TFS 2015提供的vstest.console.exe一起运行单元测试,以便它可以管理构建结果​​并在构建中发布结果总结报告。

Any help would be appreciated!! 任何帮助,将不胜感激!!

Any test runner which can run tests using below command should work (considering VS 2015 installed on the system): "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\CommonExtensions\\Microsoft\\TestWindow\\vstest.console.exe" "\\test.js" /UseVsixExtensions:true 任何可以使用以下命令运行测试的测试运行器都应该工作(考虑安装在系统上的VS 2015):“C:\\ Program Files(x86)\\ Microsoft Visual Studio 14.0 \\ Common7 \\ IDE \\ CommonExtensions \\ Microsoft \\ TestWindow \\ vstest.console .exe“”\\ test.js“/ UseVsixExtensions:true

Extending on Merlin's answer , here is how I've implemented publishing jest test results AND code coverage to TFS2015 vNext builds (I am using create-react-app boilerplate): 根据Merlin的回答 ,这里是我如何实现发布jest测试结果和代码覆盖到TFS2015 vNext构建(我正在使用create-react-app样板):

First install required packages on the Server you are running your Agent on: 首先在运行代理的服务器上安装所需的软件包:

npm install -g jest-json-to-tap npm install -g jest-json-to-tap

npm install -g tap-xunit npm install -g tap-xunit

  1. configure jest to output json, by changing in package.json the "test" task to: "test": "react-scripts test --env=jsdom --json", 配置jest输出json,通过将package.json中的“test”任务更改为:“test”:“react-scripts test --env = jsdom --json”,

  2. configure jest options in package.json: "jest": { "coverageReporters": ["cobertura"] } 在package.json中配置jest选项:“jest”:{“coverageReporters”:[“cobertura”]}

  3. created a vNext build (TFS2015v4) with the following tasks: 创建了一个带有以下任务的vNext构建(TFS2015v4):

a. 一个。 "npm" task, command=run, arguments=test -- --coverage | “npm”任务,命令=运行,参数=测试 - --coverage | jest-json-to-tap | jest-json-to-tap | tap-xunit > TEST-result.xml tap-xunit> TEST-result.xml

b. "publish test results" task, format=JUnit “发布测试结果”任务,格式= JUnit

c. C。 "public code coverage results" task, code coverage tool=Cobertura, Summary file=$(Build.Repository.LocalPath)\\coverage\\cobertura-coverage.xml “公共代码覆盖率结果”任务,代码覆盖率工具= Cobertura,摘要文件= $(Build.Repository.LocalPath)\\ coverage \\ cobertura-coverage.xml

  1. make sure your build's "Variables" include setting the environment variable "CI"="true" 确保你的构建的“变量”包括设置环境变量“CI”=“true”

NOTES: - test results will not include times nor assemblies - something to extend for the future... 注意: - 测试结果不包括时间和组件 - 未来可以延伸的东西......

Voila'! 瞧'! Running this build will correctly publish the test results and code coverage stats, as well as report artifacts. 运行此构建将正确发布测试结果和代码覆盖率统计信息,以及报告工件。

I'm not sure about jest, but there's a neat npm package that can convert TAP based results to xUnit XMLformat, and then you can publish that to TFS. 我不确定开玩笑,但是有一个简洁的npm包可以将基于TAP的结果转换为xUnit XMLformat,然后你可以将它发布到TFS。

Take a look at tap-xunit . 看看tap-xunit吧

I had a build environment where javascript testing was done by various tools and frameworks (AVA, Mocha, Jasmine etc). 我有一个构建环境,其中javascript测试由各种工具和框架(AVA,Mocha,Jasmine等)完成。 We decided to export them all to TAP format, run them throw tap-xunit and then publish to TFS. 我们决定将它们全部导出为TAP格式,运行它们抛出tap-xunit然后发布到TFS。

Basically, you need something like this: 基本上,你需要这样的东西:

npm test | tap-xunit > results.xml

You pipe the results to tap-xunit and save them to an XML. 您将结果传递给tap-xunit并将其保存为XML。 This gives you an XML formatted as xUnit that you can publish to TFS. 这为您提供了格式为xUnit的XML,您可以将其发布到TFS。 If you're running TFS 2015, I strongly recommend going with vNext builds, a lot easier to get these running. 如果您正在运行TFS 2015,我强烈建议您使用vNext版本,这样可以更轻松地运行这些版本。 Check the "Publish Test Results" build step. 检查“发布测试结果”构建步骤。

If you are running with XAML build, this link will help you: Javascript Unit Tests on Team Foundation Service with Chutzpah 如果您正在使用XAML构建运行,此链接将帮助您: 使用Chutzpah对Team Foundation Service进行Javascript单元测试

If you are running with vNext build, please try the detail steps mentioned with Jasmine.JS test(also a kind of JavaScript test ) in this blog . 如果您使用的是vNext版本,请尝试在此博客中使用Jasmine.JS测试(也是一种JavaScript测试)中提到的详细步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM