<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>teamcity Archives - Yumasoft</title>
	<atom:link href="https://blog.yumasoft.pl/tag/teamcity/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.yumasoft.pl/tag/teamcity/</link>
	<description>Software development blog</description>
	<lastBuildDate>Tue, 13 Jul 2021 03:01:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://blog.yumasoft.pl/wp-content/uploads/2021/05/cropped-yumasoft_icon_transparent-32x32.png</url>
	<title>teamcity Archives - Yumasoft</title>
	<link>https://blog.yumasoft.pl/tag/teamcity/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How To Configure Jest Tests on TeamCity</title>
		<link>https://blog.yumasoft.pl/2021/07/how-to-configure-jest-tests-on-teamcity/</link>
					<comments>https://blog.yumasoft.pl/2021/07/how-to-configure-jest-tests-on-teamcity/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Mon, 12 Jul 2021 10:30:00 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jest]]></category>
		<category><![CDATA[jest teamcity]]></category>
		<category><![CDATA[jest teamcity reporter]]></category>
		<category><![CDATA[teamcity]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tests]]></category>
		<category><![CDATA[typescript]]></category>
		<guid isPermaLink="false">https://blog.yumasoft.pl/?p=381</guid>

					<description><![CDATA[<p>If you are using jest to write JavaScript/TypeScript tests like this one: and you&#8217;re looking for how to show their results in TeamCity as follows: Then this article will help you configure that ? Prerequisites To run jest tests on TeamCity, you need to use jest as your testing framework of course ? If you&#8230;</p>
<p>The post <a rel="nofollow" href="https://blog.yumasoft.pl/2021/07/how-to-configure-jest-tests-on-teamcity/">How To Configure Jest Tests on TeamCity</a> appeared first on <a rel="nofollow" href="https://blog.yumasoft.pl">Yumasoft</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">If you are using <code>jest</code> to write JavaScript/TypeScript tests like this one:</p>



<script src="https://gist.github.com/dsibinski/5266776ab31d225e6dc97278d4f5f02f.js"></script>



<p class="wp-block-paragraph">and you&#8217;re looking for how to show their results in TeamCity as follows:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img fetchpriority="high" decoding="async" width="696" height="314" src="https://blog.yumasoft.pl/wp-content/uploads/2021/07/TeamCity_jest_tests_result-1.png" alt="Jest tests on TeamCity - sample output" class="wp-image-387" srcset="https://blog.yumasoft.pl/wp-content/uploads/2021/07/TeamCity_jest_tests_result-1.png 696w, https://blog.yumasoft.pl/wp-content/uploads/2021/07/TeamCity_jest_tests_result-1-300x135.png 300w" sizes="(max-width: 696px) 100vw, 696px" /></figure></div>



<p class="wp-block-paragraph">Then this article will help you configure that ?</p>



<span id="more-381"></span>



<h2 class="wp-block-heading">Prerequisites</h2>



<p class="wp-block-paragraph">To run <code>jest</code> tests on TeamCity, you need to use <a href="https://www.npmjs.com/package/jest">jest</a> as your testing framework of course ? If you use TypeScript &#8211; which I <a href="https://blog.yumasoft.pl/2021/06/migrating-javascript-react-app-to-typescript/">definitely recommend</a> &#8211; <a href="https://www.npmjs.com/package/ts-jest">ts-jest</a> package will also be useful.</p>



<p class="wp-block-paragraph">Having these packages installed, your basic <code>jest.config.js</code> file should look similar to this:</p>



<script src="https://gist.github.com/dsibinski/adb20170c230f922b2ebf0f0b90b7975.js"></script>



<p class="wp-block-paragraph">You should also have a <code>test</code> script defined in <code>scripts</code> section of your <code>package.json</code> file:</p>



<script src="https://gist.github.com/dsibinski/751a5df5169684cc44eb3d4497e3bb2a.js"></script>



<p class="wp-block-paragraph">With this setup, you are able to execute your tests with <code>npm test</code> command and see the results in the console:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="781" height="272" src="https://blog.yumasoft.pl/wp-content/uploads/2021/07/jest_tests_results_console.png" alt="Jest tests output in VS Code" class="wp-image-391" srcset="https://blog.yumasoft.pl/wp-content/uploads/2021/07/jest_tests_results_console.png 781w, https://blog.yumasoft.pl/wp-content/uploads/2021/07/jest_tests_results_console-300x104.png 300w, https://blog.yumasoft.pl/wp-content/uploads/2021/07/jest_tests_results_console-768x267.png 768w" sizes="(max-width: 781px) 100vw, 781px" /></figure></div>



<p class="wp-block-paragraph">Such tests results are however not recognized in any way by <a href="https://www.jetbrains.com/teamcity/">TeamCity</a> build server. Let&#8217;s see how to configure that.</p>



<h2 class="wp-block-heading">Installing TeamCity reporter</h2>



<p class="wp-block-paragraph">In order to see the tests results in TeamCity, we need the <code>npm test</code> command to produce a different output when run on TC server. This output must be compatible with <a href="https://www.jetbrains.com/help/teamcity/service-messages.html#Reporting+Tests">TeamCity&#8217;s service messages</a>.</p>



<p class="wp-block-paragraph">Fortunately, you don&#8217;t need to implement it by yourself ?</p>



<p class="wp-block-paragraph">First, install <a href="https://www.npmjs.com/package/jest-teamcity">jest-teamcity</a> npm package to your project. Next, add <code>jest-teamcity</code> to <code>reporters</code> configuration option in your <code>jest.config.js</code> file:</p>



<script src="https://gist.github.com/dsibinski/7e9a94a8374d5901d452844e8a4fc9d5.js"></script>



<h2 class="wp-block-heading">Adding TeamCity build step</h2>



<p class="wp-block-paragraph">Next, login to your TeamCity server. You need to know the location of <code>npm.cmd</code> file on your TeamCity server. It should be in NodeJS installation catalog. In our case, the path to the file is <code>C:\Dev\nodejs\npm.cmd</code>. </p>



<p class="wp-block-paragraph">Now, go to TeamCity web administration interface and create a new build configuration or edit a current one. Then, add a new build step:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="618" height="212" src="https://blog.yumasoft.pl/wp-content/uploads/2021/07/TeamCity_add_new_step.png" alt="TeamCity - adding a new build step button" class="wp-image-393" srcset="https://blog.yumasoft.pl/wp-content/uploads/2021/07/TeamCity_add_new_step.png 618w, https://blog.yumasoft.pl/wp-content/uploads/2021/07/TeamCity_add_new_step-300x103.png 300w" sizes="(max-width: 618px) 100vw, 618px" /></figure></div>



<p class="wp-block-paragraph">Configure the new step as follows:</p>



<ul class="wp-block-list"><li><strong>Runner type</strong>: <em>Command line</em></li><li><strong>Step name</strong>: <em>Jest JS tests</em></li><li><strong>Execute step</strong>: <em>If all previous steps finished successfully</em> (or anything else you prefer)</li><li><strong>Working directory</strong>: name of the catalog in your web app where you normally run <code>npm test</code></li><li><strong>Run</strong>: <em>Custom script</em></li><li><strong>Custom script</strong>: <em>&#8220;your_path_to_nodejs\npm.cmd&#8221; run test</em>, for example: <em>&#8220;C:\Dev\nodejs\npm.cmd&#8221; run test</em></li><li><strong>Format stderr output as</strong>: <em>error</em></li></ul>



<p class="wp-block-paragraph">If everything is configured correctly, during the next build you should see <code>jest</code> tests output recognized and nicely reported by TeamCity:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="696" height="314" src="https://blog.yumasoft.pl/wp-content/uploads/2021/07/TeamCity_jest_tests_result-2.png" alt="Jest tests on TeamCity - jest tests results in a build" class="wp-image-394" srcset="https://blog.yumasoft.pl/wp-content/uploads/2021/07/TeamCity_jest_tests_result-2.png 696w, https://blog.yumasoft.pl/wp-content/uploads/2021/07/TeamCity_jest_tests_result-2-300x135.png 300w" sizes="auto, (max-width: 696px) 100vw, 696px" /></figure></div>



<p class="wp-block-paragraph">If that&#8217;s not the case, make sure that <code>TEAMCITY_VERSION</code> environment variable is set on your TeamCity machine. That&#8217;s how <code>jest-teamcity</code> reporter recognizes when to output standard <code>jest</code> output and when to use TeamCity&#8217;s service messages format.</p>



<h2 class="wp-block-heading">Debugging jest tests on TeamCity locally</h2>



<p class="wp-block-paragraph">If you run <code>npm test</code> locally, you will see that the output is still normal, not the TeamCity format. That&#8217;s correct, because as we said before, the <code>TEAMCITY_VERSION</code> environment variable must exist in order to see TeamCity-formatted output. Normally we don&#8217;t want to see TeamCity-formatted tests output locally, of course ?</p>



<p class="wp-block-paragraph">It means that if you want to debug this configuration locally and actually see the TC tests output on your dev machine, you need to define such environment variable locally.</p>



<p class="wp-block-paragraph">In order to do that in Windows, go to <code>Edit the system environment variables</code>, click on <code>Evironment Variables...</code> and add a new one in <code>System variables</code> section. Call this variable <code>TEAMCITY_VERSION</code> and give it some value, for example <code>2021.1</code>:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="653" height="168" src="https://blog.yumasoft.pl/wp-content/uploads/2021/07/TeamCity_version_evironment_variable.png" alt="Adding new system environment variable called &quot;TEAMCITY_VERSION&quot; with value of &quot;2021.1&quot;, so the jest reporter can output TeamCity-formatted result" class="wp-image-396" srcset="https://blog.yumasoft.pl/wp-content/uploads/2021/07/TeamCity_version_evironment_variable.png 653w, https://blog.yumasoft.pl/wp-content/uploads/2021/07/TeamCity_version_evironment_variable-300x77.png 300w" sizes="auto, (max-width: 653px) 100vw, 653px" /></figure></div>



<p class="wp-block-paragraph">If you&#8217;re on another operating system, add the environment variable according to your system&#8217;s requirements.</p>



<p class="wp-block-paragraph">Next, restart Visual Studio Code or the console tool you are using and execute <code>npm test</code> again. Now you should see the tests results output in TeamCity format:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="214" src="https://blog.yumasoft.pl/wp-content/uploads/2021/07/npm_test_jest_teamcity_format-1024x214.png" alt="TeamCity-formatted jest tests results in VS Code console" class="wp-image-397" srcset="https://blog.yumasoft.pl/wp-content/uploads/2021/07/npm_test_jest_teamcity_format-1024x214.png 1024w, https://blog.yumasoft.pl/wp-content/uploads/2021/07/npm_test_jest_teamcity_format-300x63.png 300w, https://blog.yumasoft.pl/wp-content/uploads/2021/07/npm_test_jest_teamcity_format-768x161.png 768w, https://blog.yumasoft.pl/wp-content/uploads/2021/07/npm_test_jest_teamcity_format.png 1127w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure></div>



<h2 class="wp-block-heading">Jest tests in TeamCity &#8211; summary</h2>



<p class="wp-block-paragraph">I hope you found this piece of advice useful. At Yumasoft, we value tests a lot, both backend and frontend ones. However, the tests which are not run automatically are worth nothing. That&#8217;s why we always have all of our tests run automatically as part of our CI process (TeamCity in the sample project&#8217;s case).</p>
<p>The post <a rel="nofollow" href="https://blog.yumasoft.pl/2021/07/how-to-configure-jest-tests-on-teamcity/">How To Configure Jest Tests on TeamCity</a> appeared first on <a rel="nofollow" href="https://blog.yumasoft.pl">Yumasoft</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.yumasoft.pl/2021/07/how-to-configure-jest-tests-on-teamcity/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
