使用TFS 2015运行Jest单元测试 [英] Run Jest unit test with TFS 2015

查看:130
本文介绍了使用TFS 2015运行Jest单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人尝试将Jest单元测试与TFS 2015集成吗?我尝试使用Chutzpah测试适配器( https://visualstudiogallery .msdn.microsoft.com/f8741f04-bae4-4900-81c7-7c9bfb9ed1fe?SRC = VSIDE ),但是它无法识别笑话.我收到以下错误: 找不到变量Jest

Has anyone attempted to integrate jest unit tests with 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. I receive below error: Can't find variable Jest

当我通过"npm test"运行单元测试时,我得到了结果.但是,要与TFS 2015集成,我需要一个可以运行Jest单元测试的测试运行程序,以便我可以与TFS 2015提供的vstest.console.exe一起运行单元测试,以便它可以管理构建结果​​并在构建中发布结果摘要报告.

When I run the unit tests through "npm test" I get the results. 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.

任何帮助将不胜感激!

任何可以使用以下命令运行测试的测试运行程序都应该起作用(考虑系统上安装的VS 2015): "C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ CommonExtensions \ Microsoft \ TestWindow \ vstest.console.exe""\ test.js"/UseVsixExtensions:true

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

推荐答案

扩展到 Merlin的答案,这是我的方法已实现将发布的测试结果和代码覆盖范围发布到TFS2015 vNext版本(我正在使用create-react-app样板):

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):

首先在运行代理程序的服务器上安装必需的软件包:

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. 通过在package.json中将测试"任务更改为来配置玩笑以输出json: "test":反应脚本测试--env = jsdom --json",

  1. configure jest to output json, by changing in package.json the "test" task to: "test": "react-scripts test --env=jsdom --json",

在package.json中配置笑话选项: 笑话":{"coverageReporters":["cobertura"]}

configure jest options in package.json: "jest": { "coverageReporters": ["cobertura"] }

使用以下任务创建了vNext构建(TFS2015v4):

created a vNext build (TFS2015v4) with the following tasks:

a. "npm"任务,命令=运行,参数=测试---coverage | jest-json-to-tap | tap-xunit> TEST-result.xml

a. "npm" task, command=run, arguments=test -- --coverage | jest-json-to-tap | tap-xunit > TEST-result.xml

b. 发布测试结果"任务,格式= JUnit

b. "publish test results" task, format=JUnit

c. 公共代码覆盖结果"任务,代码覆盖工具= Cobertura,摘要文件= $(Build.Repository.LocalPath)\ coverage \ cobertura-coverage.xml

c. "public code coverage results" task, code coverage tool=Cobertura, Summary file=$(Build.Repository.LocalPath)\coverage\cobertura-coverage.xml

  1. 确保您构建的变量"包括设置环境变量"CI" ="true"

注意: -测试结果将不包括时间或装配-将来会有所扩展...

NOTES: - test results will not include times nor assemblies - something to extend for the future...

Voila'!运行此版本将正确发布测试结果,代码覆盖率统计信息以及报告工件.

Voila'! Running this build will correctly publish the test results and code coverage stats, as well as report artifacts.

这篇关于使用TFS 2015运行Jest单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆