Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Jest unit test with TFS 2015

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

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.

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

like image 877
user6376781 Avatar asked May 24 '16 15:05

user6376781


1 Answers

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 tap-xunit

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

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

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

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

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

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

  1. make sure your build's "Variables" include setting the environment variable "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.

like image 158
Leon Avatar answered Nov 04 '22 15:11

Leon