{"id":1123,"date":"2023-06-29T05:00:00","date_gmt":"2023-06-29T12:00:00","guid":{"rendered":"https:\/\/www.angulartraining.com\/daily-newsletter\/?p=1123"},"modified":"2023-06-27T11:44:30","modified_gmt":"2023-06-27T18:44:30","slug":"running-unit-tests-on-continuous-integration-servers","status":"publish","type":"post","link":"https:\/\/www.angulartraining.com\/daily-newsletter\/running-unit-tests-on-continuous-integration-servers\/","title":{"rendered":"Running unit tests on continuous integration servers"},"content":{"rendered":"\n<p>We talked about <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/how-to-unit-test-an-angular-service\/\" target=\"_blank\" rel=\"noopener\" title=\"\">unit testing<\/a> a couple of times last week. One of the main benefits of unit tests is that they run quickly and provide immediate feedback. As a result, we get the best return on investment when running those unit tests on a continuous integration (CI) server after each commit.<\/p>\n\n\n\n<p>Two challenges come with running unit tests on a CI server:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The default test runner for Angular projects (Karma) opens a Chrome browser to run the tests, which is challenging on most CI servers (typically Unix based with no UI support).<\/li>\n\n\n\n<li>The <code>ng test<\/code> command doesn&#8217;t stop on its own. It keeps watching the source code for updates and then reruns the tests.<\/li>\n<\/ol>\n\n\n\n<p>Fortunately for us, there is a single command that addresses both problems:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-36.png\" alt=\"\" class=\"wp-image-1124\" width=\"681\" height=\"33\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-36.png 681w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-36-300x15.png 300w\" sizes=\"auto, (max-width: 681px) 100vw, 681px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>Running the command will result in a single test run (thanks to <code>--watch false<\/code>) and will run in a UI-less way (thanks to <code>--browsers ChromeHeadless<\/code>). That&#8217;s all your CI server needs to do.<\/p>\n\n\n\n<p>If you&#8217;re using an older version of Angular, this <a href=\"https:\/\/blog.angulartraining.com\/how-to-running-angular-tests-on-continuous-integration-servers-ad492219c08c\" target=\"_blank\" rel=\"noopener\" title=\"\">old tutorial of mine<\/a> might help you configure Karma accordingly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We talked about unit testing a couple of times last week. One of the main benefits of unit tests is that they run quickly and provide immediate feedback. As a result, we get the best return on investment when running those unit tests on a continuous integration (CI) server after each commit. Two challenges come [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,17],"tags":[],"class_list":["post-1123","post","type-post","status-publish","format-standard","hentry","category-testing","category-tools"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/comments?post=1123"}],"version-history":[{"count":2,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1123\/revisions"}],"predecessor-version":[{"id":1126,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1123\/revisions\/1126"}],"wp:attachment":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/media?parent=1123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/categories?post=1123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/tags?post=1123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}