<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Amit Kumar Das</title>
    <description>The latest articles on DEV Community by Amit Kumar Das (@amityt).</description>
    <link>https://dev.to/amityt</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F416661%2F4344eb64-0161-4a6c-9d09-e61deaee646f.jpeg</url>
      <title>DEV Community: Amit Kumar Das</title>
      <link>https://dev.to/amityt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amityt"/>
    <language>en</language>
    <item>
      <title>Workflow Creation with Litmus 2.0 Beta</title>
      <dc:creator>Amit Kumar Das</dc:creator>
      <pubDate>Tue, 18 May 2021 09:24:12 +0000</pubDate>
      <link>https://dev.to/litmus-chaos/workflow-creation-with-litmus-2-0-beta-29nc</link>
      <guid>https://dev.to/litmus-chaos/workflow-creation-with-litmus-2-0-beta-29nc</guid>
      <description>&lt;p&gt;With Litmus 2.0 announced, you are no longer confined to perform Chaos Engineering with a terminal in your hand. You now have a control plane to create, schedule and analyze chaos workflows with our upgraded Litmus Portal.&lt;/p&gt;

&lt;p&gt;The new Litmus Portal makes chaos engineering fun and hassle free. With a single click, you can re-run a workflow without configuring it again. Don't want to create a new workflow from scratch, just save one of the existing workflow as a predefined template and much more. In this blog we will go through all the new features that are added to the Portal with the 2.0 update.&lt;/p&gt;

&lt;h3&gt;
  
  
  Before moving ahead, let's know about Litmus. ❓
&lt;/h3&gt;

&lt;p&gt;Litmus is a complete framework to perform chaos engineering in a cloud-native ecosystem.&lt;br&gt;
It is a toolkit to orchastrate chaos on Kubernetes. It allows SRE to inject chaos in the environment and find the bugs and vulnerabilities in the system. Fixing these vulnerebilities will ultimately make the system resilient.&lt;/p&gt;

&lt;p&gt;Chaos experiments are hosted on &lt;a href="//hub.litmuschaos.io"&gt;ChaosHub&lt;/a&gt;. It is a public marketplace where different vendors share their chaos experiments so that their users can use them to increase the resilience of the applications in production.&lt;/p&gt;

&lt;h1&gt;
  
  
  New Upgrades with Litmus 2.0 🚀
&lt;/h1&gt;



&lt;h2&gt;
  
  
  Workflow Creation ✍️
&lt;/h2&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Choose a workflow&lt;/strong&gt; 🎟️&lt;/p&gt;

&lt;p&gt;With the new Litmus Portal, you can choose workflows from 4 different ways.&lt;/p&gt;

&lt;p&gt;a. &lt;strong&gt;Create a new workflow from one of the pre-defined chaos experiment.&lt;/strong&gt; With this option, you can select the pre-defined experiments that executes chaos operations on real-world applications like &lt;code&gt;sock-shop&lt;/code&gt;. Currently there are 3 pre-defined experiments available &lt;code&gt;sock-shop-chaos&lt;/code&gt;,&lt;code&gt;kube-proxy-chaos&lt;/code&gt; and the new &lt;code&gt;podtato-head-chaos&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkmn2nwcrhhc6ic0te8f3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkmn2nwcrhhc6ic0te8f3.png" alt="Screenshot from 2021-05-10 19-37-59" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;b. &lt;strong&gt;Create a new workflow by cloning and existing workflow.&lt;/strong&gt; With this option, you can save an existing workflow as a template from the scheduled workflows. This options saves some time if you don't want to schedule a workflow from scratch.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffu78vfocsdz6khvqp8nl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffu78vfocsdz6khvqp8nl.png" alt="Screenshot from 2021-05-10 19-56-20" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;c. &lt;strong&gt;Create a new workflow using experiments from MyHub.&lt;/strong&gt; With this option, you can create custom experiments from the connected MyHubs. By default , the public Chaos Hub is already installed. You can connect a MyHub with the &lt;a href="https://dev.to/amityt/custom-workflow-with-myhub-using-litmus-portal-359a"&gt;following steps&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvcjlzg10r3rfj3vf5jk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvcjlzg10r3rfj3vf5jk.png" alt="Screenshot from 2021-05-10 19-56-28" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;d. &lt;strong&gt;Import workflow using YAML.&lt;/strong&gt; With this option, you can upload a workflow manifest and tune it according to the use-case and schedule it.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiev5m18507dyl40zmndw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiev5m18507dyl40zmndw.png" alt="Screenshot from 2021-05-10 19-56-35" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Tune Workflow&lt;/strong&gt; 🎯&lt;/p&gt;

&lt;p&gt;A lot of new changes are added in the tune workflow section, these include:&lt;/p&gt;

&lt;p&gt;a. &lt;strong&gt;Workflow Visualisation&lt;/strong&gt; 👀 - Now visualize your workflow even before scheduling it. This feature gives a breif idea about the sturcture of the workflow. You can view the experiments if they are parallel or serial.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkxmahuufltbppbybcgba.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkxmahuufltbppbybcgba.png" alt="Screenshot from 2021-05-10 19-57-16" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
b. &lt;strong&gt;Experiments Table&lt;/strong&gt; 📋 - This table give valuable information about the experiments present in the workflow. It also shows the target applications of each experiments where chaos will be injected.&lt;br&gt;
c. &lt;strong&gt;Sequencing Experiments&lt;/strong&gt; 🔧 - This is one of the major feature we added with the 2.0 update, with this you can tune the sequence of the workflow by dragging and dropping the experiment as shown below. This allows you to sequence your experiments parallel and serial manner. &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2FqQvEywXjVRuz8Nj2rI%2Fgiphy.gif%3Fcid%3D790b761117e521344cc388c6ccc40a68efac4300866e0f4c%26rid%3Dgiphy.gif%26ct%3Dg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2FqQvEywXjVRuz8Nj2rI%2Fgiphy.gif%3Fcid%3D790b761117e521344cc388c6ccc40a68efac4300866e0f4c%26rid%3Dgiphy.gif%26ct%3Dg" alt="Sequencing Experiment" width="480" height="270"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
d. &lt;strong&gt;Tune Experiments&lt;/strong&gt; 🔥 - Our prior focus with the 2.0 update was to make the experiment tuning step hassle free for the user, hence we added the Kubernetes Object integration in this step. With this you can get the cluster details like the available namespaces and the application labels according to the resourse type. This allows you to target the application to inject chaos in a much simpler way.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhug37g3nne338h7y8lsb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhug37g3nne338h7y8lsb.png" alt="Screenshot from 2021-05-10 20-09-37" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;e. &lt;strong&gt;Probes Integration&lt;/strong&gt; ⌚ - Now you can add probes directly from the portal. The probe properties are available dynamically in the portal. Select one probe and add it in your chaos engine to enhance your chaos testing.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbu02pdr745jh3yqtofm7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbu02pdr745jh3yqtofm7.png" alt="Screenshot from 2021-05-10 20-10-26" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;f. &lt;strong&gt;Reliability Score&lt;/strong&gt; 💯 - The look and feel of the reliability score page is also upgraded, it now gives a clearer idea about the weights of the expeiments.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F63qqrnzagfoqnrol45y0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F63qqrnzagfoqnrol45y0.png" alt="Screenshot from 2021-05-10 20-35-31" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;So these were the new changes we have added in the workflow creation steps. Stay tuned, a lot of new features will be available in the coming releases. &lt;/p&gt;

&lt;p&gt;Make sure to try the Litmus Portal 2.0 and give your valuable feedback and suggestion. Don’t forget to checkout our &lt;a href="https://litmuschaos.io/" rel="noopener noreferrer"&gt;Litmus website&lt;/a&gt; and the &lt;a href="https://github.com/litmuschaos/litmus" rel="noopener noreferrer"&gt;Litmus repo&lt;/a&gt;. Do leave a star if you find it interesting. 😊&lt;/p&gt;

&lt;p&gt;Further, feel free to put forward any queries or concerns you have. I would love to address them. I would love to invite you to our slack community for keeping up to date and interacting with our community members, contributors &amp;amp; maintainers.&lt;br&gt;
To join our slack please follow the following steps!&lt;br&gt;
Step 1: Join the Kubernetes slack using the following link: &lt;a href="https://slack.k8s.io/" rel="noopener noreferrer"&gt;https://slack.k8s.io/&lt;/a&gt;&lt;br&gt;
Step 2: Join the #litmus channel on the Kubernetes slack or use this link after joining the Kubernetes slack: &lt;a href="https://slack.litmuschaos.io/" rel="noopener noreferrer"&gt;https://slack.litmuschaos.io/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>litmuschaos</category>
      <category>chaosengineering</category>
      <category>testing</category>
    </item>
    <item>
      <title>Custom Workflow with MyHub using Litmus Portal</title>
      <dc:creator>Amit Kumar Das</dc:creator>
      <pubDate>Thu, 07 Jan 2021 12:04:03 +0000</pubDate>
      <link>https://dev.to/amityt/custom-workflow-with-myhub-using-litmus-portal-359a</link>
      <guid>https://dev.to/amityt/custom-workflow-with-myhub-using-litmus-portal-359a</guid>
      <description>&lt;p&gt;Hello Chaos Engineers,&lt;br&gt;
In this article, we will get to know about one of the salient features of Litmus Portal i.e &lt;strong&gt;My Hub&lt;/strong&gt;. We will go through the steps from connecting a hub to creating a custom workflow. My Hub allows SREs to orchestrate their Litmus Experiments directly from their respective Github repositories. &lt;/p&gt;
&lt;h2&gt;
  
  
  What is Litmus and how we can run chaos experiments using Litmus Portal?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/litmuschaos/litmus/" rel="noopener noreferrer"&gt;Litmus&lt;/a&gt; is an open-source chaos engineering framework that provides tools to set up chaos in Kubernetes to help developers and SREs discover weaknesses and flaws in the application system. It is very easy to use and comes with detailed documentation. It also provides a large collection of chaos experiments, which you can find here. If you want to get started with Litmus Portal and how to create a custom workflow, this article is surely going to help you. You can also join our slack community for an open discussion.&lt;br&gt;
Litmus Portal allows you to create, run and analyze the chaos workflows using a UI console. SREs can invite their team members to work on different projects and analyze the workflows present in the projects. Currently the Litmus Portal is in beta-0 version and lots of improvements are being added on a daily basis. &lt;/p&gt;
&lt;h2&gt;
  
  
  Steps involving the creation of custom workflows using MyHub are :
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Using the Default MyHub:&lt;/strong&gt;&lt;br&gt;
When a user creates a project on Litmus Portal, a default MyHub is provided to the user. It is similar to the &lt;a href="http://hub.litmuschaos.io/" rel="noopener noreferrer"&gt;Litmus ChaosHub&lt;/a&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fubc6b0iy7k8e52wt5l8n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fubc6b0iy7k8e52wt5l8n.png" alt="Screenshot from 2020-12-27 22-25-22"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Connecting a MyHub:&lt;/strong&gt;&lt;br&gt;
Users can connect their chaos hubs from their Github repositories using the github link and the branch name. Once this step is done, the user can view their connected hub in the My Hub section.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwp5j0etzic5g3pca13l4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwp5j0etzic5g3pca13l4.png" alt="Screenshot from 2020-12-29 20-02-48"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7ljhw9ch3pfd6udbramm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7ljhw9ch3pfd6udbramm.png" alt="Screenshot from 2020-12-29 20-04-38"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fs1wmmh7l0p0ecp85p1rw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fs1wmmh7l0p0ecp85p1rw.png" alt="Screenshot from 2020-12-29 20-04-54"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;View charts and experiments:&lt;/strong&gt;&lt;br&gt;
Users can select one of the hubs and view the charts present in the particular hub. The user can view a variety of chaos experiments and these are sorted according to their types like generic, kube-aws etc. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw1d4x5z52akle66bg459.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw1d4x5z52akle66bg459.png" alt="Screenshot from 2020-12-27 22-25-31"&gt;&lt;/a&gt; &lt;br&gt;
The user can then select one of the charts and view the details about the experiments. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhr0c8s5bhy3ti5i79fqp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhr0c8s5bhy3ti5i79fqp.png" alt="Screenshot from 2020-12-27 22-25-36"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frw7yygs97grev7ymg5j9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frw7yygs97grev7ymg5j9.png" alt="Screenshot from 2020-12-27 22-25-48"&gt;&lt;/a&gt;&lt;br&gt;
The user can install the experiment using the experiment link, the user can also setup a service account using the RBAC link and we also provide the link for chaos engine which is highly configurable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Customize your workflows using MyHubs:&lt;/strong&gt;&lt;br&gt;
The users can click the “Create your own workflow” card in the pre-defined templates section to start creating the custom workflows.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5yp2ftt32jn27txy42ll.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5yp2ftt32jn27txy42ll.png" alt="Screenshot from 2020-12-29 21-54-30"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here the user can select a hub and choose the experiment from the different My Hubs present in the project. The user can also specify the namespace where he wants to run the chaos experiment.&lt;br&gt;
After selecting the experiment from the hub, the user can now customize the experiment, the users can now tune the workflow according to their requirement.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The users can edit the appinfo which includes the appns, applabel, appkind.&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;To know more about appns, applable etc, please check the &lt;a href="https://docs.litmuschaos.io/docs/chaosengine/" rel="noopener noreferrer"&gt;Litmus Docs&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fr0y1e5xfgr45bt3czeid.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fr0y1e5xfgr45bt3czeid.png" alt="Screenshot from 2020-12-29 21-54-40"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The users can tune the variables of the chaos engine and add more key value pairs as necessary.&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frngce5yq2iq1cwe5qtzo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frngce5yq2iq1cwe5qtzo.png" alt="Screenshot from 2020-12-29 21-54-43"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once the user has customized the experiment , more experiments can be added to the workflows. The user can also alter the sequence of the experiments in the workflow according to the requirements. Once the user clicks the Finish adding the experiments button, a YAML is generated consisting of the experiment details that the user has selected while configuring the workflow.&lt;/p&gt;

&lt;p&gt;Here in this custom workflow, I have selected two experiemnts &lt;code&gt;generic/pod-delete&lt;/code&gt; and &lt;code&gt;generic/pod-cpu-hog&lt;/code&gt;. The generated YAML comprising these two experiment is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  name: custom-chaos-workflow-1609259040
  namespace: litmus
spec:
  arguments:
    parameters:
      - name: adminModeNamespace
        value: litmus
  entrypoint: custom-chaos
  securityContext:
    runAsNonRoot: true
    runAsUser: 1000
  serviceAccountName: argo-chaos
  templates:
    - name: custom-chaos
      steps:
        - - name: install-chaos-experiments
            template: install-chaos-experiments
        - - name: pod-delete
            template: pod-delete
        - - name: pod-cpu-hog
            template: pod-cpu-hog
        - - name: revert-chaos
            template: revert-chaos
    - name: install-chaos-experiments
      container:
        args:
          - kubectl apply -f
            https://github.com/litmuschaos/chaos-charts/raw/master/charts/generic/pod-delete/experiment.yaml
            -n {{workflow.parameters.adminModeNamespace}} | kubectl apply -f
            https://github.com/litmuschaos/chaos-charts/raw/master/charts/generic/pod-cpu-hog/experiment.yaml
            -n {{workflow.parameters.adminModeNamespace}} | sleep 30
        command:
          - sh
          - -c
        image: lachlanevenson/k8s-kubectl
    - name: pod-delete
      inputs:
        artifacts:
          - name: pod-delete
            path: /tmp/chaosengine-pod-delete.yaml
            raw:
              data: |
                apiVersion: litmuschaos.io/v1alpha1
                kind: ChaosEngine
                metadata:
                  name: pod-delete
                  namespace: "{{workflow.parameters.adminModeNamespace}}"
                spec:
                  appinfo:
                    appns: default
                    applabel: app=nginx
                    appkind: deployment
                  annotationCheck: "false"
                  engineState: active
                  chaosServiceAccount: litmus-admin
                  monitoring: false
                  jobCleanUpPolicy: delete
                  experiments:
                    - name: pod-delete
                      spec:
                        components:
                          env:
                            - name: TOTAL_CHAOS_DURATION
                              value: "30"
                            - name: CHAOS_INTERVAL
                              value: "10"
                            - name: FORCE
                              value: "false"
      container:
        args:
          - -file=/tmp/chaosengine-pod-delete.yaml
          - -saveName=/tmp/engine-name
        image: litmuschaos/litmus-checker:latest
    - name: pod-cpu-hog
      inputs:
        artifacts:
          - name: pod-cpu-hog
            path: /tmp/chaosengine-pod-cpu-hog.yaml
            raw:
              data: |
                apiVersion: litmuschaos.io/v1alpha1
                kind: ChaosEngine
                metadata:
                  name: pod-cpu-hog
                  namespace: "{{workflow.parameters.adminModeNamespace}}"
                spec:
                  annotationCheck: "false"
                  engineState: active
                  appinfo:
                    appns: default
                    applabel: app=nginx
                    appkind: deployment
                  chaosServiceAccount: litmus-admin
                  monitoring: false
                  jobCleanUpPolicy: delete
                  experiments:
                    - name: pod-cpu-hog
                      spec:
                        components:
                          env:
                            - name: CPU_CORES
                              value: "1"
                            - name: TOTAL_CHAOS_DURATION
                              value: "60"
      container:
        args:
          - -file=/tmp/chaosengine-pod-cpu-hog.yaml
          - -saveName=/tmp/engine-name
        image: litmuschaos/litmus-checker:latest
    - name: revert-chaos
      container:
        args:
          - kubectl delete chaosengines --all -n
            {{workflow.parameters.adminModeNamespace}}
        command:
          - sh
          - -c
        image: lachlanevenson/k8s-kubectl 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the user can run the workflow and see the results in the analytics section. Once the workflow execution is completed , the user can view the workflow in a graphical format that consists of all useful informations like the nodes, step groups etc.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Foffs8jzykv3ltx8xgx2l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Foffs8jzykv3ltx8xgx2l.png" alt="Screenshot from 2021-01-07 11-24-59"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Now you are not limited to some predefined workflows, even if you are beginner. You are getting your own chaos template that it highly customisable. Using the Public Hub and your own My Hub, you get all the chaos experiments at one place. You can play around with all the configuration from the UI and check the changes that are happening in the workflow. &lt;/p&gt;

&lt;p&gt;Feel free to check out our ongoing project - &lt;a href="https://github.com/litmuschaos/litmus/tree/master/litmus-portal" rel="noopener noreferrer"&gt;Litmus Portal&lt;/a&gt; and do let us know if you have any suggestions or feedback regarding the same. You can always submit a PR if you find any required changes. &lt;/p&gt;

&lt;p&gt;Make sure to reach out to us if you have any feedback or queries. Hope you found the blog informative!&lt;/p&gt;

&lt;p&gt;If chaos engineering is something that excites you or if you want know more about cloud native chaos engineering, don’t forget to checkout our &lt;a href="https://litmuschaos.io/" rel="noopener noreferrer"&gt;Litmus website&lt;/a&gt;, &lt;a href="https://hub.litmuschaos.io/" rel="noopener noreferrer"&gt;ChaosHub&lt;/a&gt; and the &lt;a href="https://github.com/litmuschaos/litmus" rel="noopener noreferrer"&gt;Litmus repo&lt;/a&gt;. Do leave a star if you find it insightful. 😊&lt;/p&gt;

&lt;p&gt;I would love to invite you to our community to stay connected with us and get your Chaos Engineering doubts cleared.&lt;br&gt;
To join our slack please follow the following steps!&lt;br&gt;
&lt;strong&gt;Step 1:&lt;/strong&gt; Join the Kubernetes slack using the following link: &lt;a href="https://slack.k8s.io/" rel="noopener noreferrer"&gt;https://slack.k8s.io/&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Step 2:&lt;/strong&gt; Join the &lt;code&gt;#litmus&lt;/code&gt; channel on the Kubernetes slack or use this link after joining the Kubernetes slack: &lt;a href="https://slack.litmuschaos.io/" rel="noopener noreferrer"&gt;https://slack.litmuschaos.io/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cheers! &lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>litmuschaos</category>
      <category>workflow</category>
      <category>chaosengineering</category>
    </item>
    <item>
      <title>Test Driven Development using Cypress</title>
      <dc:creator>Amit Kumar Das</dc:creator>
      <pubDate>Fri, 21 Aug 2020 14:54:45 +0000</pubDate>
      <link>https://dev.to/amityt/test-driven-development-using-cypress-298k</link>
      <guid>https://dev.to/amityt/test-driven-development-using-cypress-298k</guid>
      <description>&lt;p&gt;In this blog, we will be discussing test-driven development with Cypress along with some of the best practices for unit testing. As frontend developers, our main objective is to create different UI screens that include the development of various functional and reusable components. But one thing that most of us do not put into practice, maybe because we don’t understand its importance is testing, especially front-end unit testing. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Unit Testing?&lt;/strong&gt;&lt;br&gt;
First things first! Let’s understand what unit testing is.&lt;br&gt;
Unit testing makes sure that the basic building blocks of the project including methods, UI elements, etc. are working properly. In React components, it lets the developer know if they are being rendered properly, whether the props are being passed to the components in a proper state, etc. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why is it important?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In a bigger project, as the number of components increases, unit testing becomes the savior for the developers. We can test individual code before the complete integration and get faster feedback on the working of components without impacting the other sections of the project!&lt;/li&gt;
&lt;li&gt;Inculcating the practice of writing unit tests, not only makes us think harder about the problem but also helps us discover the edges cases which in turn makes us write better quality of code.&lt;/li&gt;
&lt;li&gt;Since the bugs are found in the starting phase, it reduces the overhead of fixing it in later stages, which would be a daunting task for us as developers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;So, we’ll be talking about the Cypress testing we do in Litmus.&lt;/strong&gt; &lt;br&gt;
Litmus is an open-source chaos engineering framework that provides tools to set up chaos in Kubernetes in order to help developers and SREs discover weaknesses in the application deployment. It is very easy to use and comes with detailed documentation. It also provides a large collection of chaos experiments, which you can find &lt;a href="https://dev.to/uditgaurav/get-started-with-litmuschaos-in-minutes-4ke1"&gt;here&lt;/a&gt;. If you want to get started with Litmus, this article is surely going to help you. You can also join our slack community for an open discussion. Currently, we are developing the &lt;a href="https://github.com/litmuschaos/litmus/tree/master/litmus-portal" rel="noopener noreferrer"&gt;Litmus Portal&lt;/a&gt; which provides console and UI experience for managing, monitoring, and events around chaos workflows using the React and Typescript for the frontend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Cypress?&lt;/strong&gt;&lt;br&gt;
Cypress is a Javascript-based testing framework that is built on top of Mocha which itself is a full-featured Javascript testing framework. It also includes cross-browser testing that makes it more preferable to use. &lt;br&gt;
As mentioned in the official &lt;a href="https://docs.cypress.io/guides/overview/why-cypress.html" rel="noopener noreferrer"&gt;documentation of Cypress&lt;/a&gt;, Cypress facilitates a developer to write all types of tests :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unit tests&lt;/li&gt;
&lt;li&gt;Integration tests&lt;/li&gt;
&lt;li&gt;End to End tests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why Cypress?&lt;/strong&gt;&lt;br&gt;
Before jumping into its implementation let’s get to know why did we choose Cypress for unit testing. So the primary reasons are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With in-browser execution, it is incredibly fast!&lt;/li&gt;
&lt;li&gt;We didn’t have to worry about its setup as it is very easy to use and provides very good and detailed documentation.&lt;/li&gt;
&lt;li&gt;It also boasts about a growing community.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Some of the best practices that we have followed while doing unit testing are:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Used unique &lt;code&gt;“data-cy”&lt;/code&gt; attributes to make it easier in targeting the elements, targeting the elements using a tag, id or class should be prevented as these are highly subject to change.
For example:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button id="main" class="btn btn-large" name="submission"
  role="button" data-cy="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
  cy.get('[data-cy=submit]').click()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Maintained well defined and clean folder structure. All the tests are stored in &lt;code&gt;cypress/components&lt;/code&gt; in the &lt;code&gt;litmus-portal/frontend&lt;/code&gt; directory. &lt;/li&gt;
&lt;li&gt;We have added logs wherever it is required to make the debugging easy.&lt;/li&gt;
&lt;li&gt;We have tried to limit one assert per method to avoid confusion in case of failure.&lt;/li&gt;
&lt;li&gt;Each of the tests is independent of each other so that the tests can be executed in any order and failure of one test case doesn’t affect others.&lt;/li&gt;
&lt;li&gt;We have kept each of the tests short and simple to enhance readability and understanding.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since the project is using Typescript in the frontend, we have written all the tests in the same. &lt;br&gt;
So, now we’ll be setting up cypress along with a small react app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React app&lt;/li&gt;
&lt;li&gt;Custom components&lt;/li&gt;
&lt;li&gt;Cypress&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Installing cypress&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install cypress using npm
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  npm install cypress
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Install cypress using yarn
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  yarn add cypress 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Once Cypress is successfully installed, you can try it out by running these commands.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Open Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open cypress using npm
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  npx cypress open
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Open cypress using yarn
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  yarn run cypress open 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Setting up Cypress in the react app with Typescript for the unit-test:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Install Cypress React Unit Test Plugin&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev cypress cypress-react-unit-test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configure your tsconfig.json by adding these&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
   "compilerOptions": {
       "target": "es5",
       "lib": ["dom", "dom.iterable", "esnext"],
       "types": ["node", "cypress"]
   },
   "include": ["src", "cypress/component/*.tsx"]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configure your cypress.json by adding these&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
   "experimentalComponentTesting": true,
   "componentFolder": "cypress/component",
   "specFiles": "*spec.*",
   "defaultCommandTimeout": 4000,
   "execTimeout": 200000,
   "taskTimeout": 200000
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure you specify the folder that contains the test cases, here the test scripts are present in the &lt;code&gt;cypress/components&lt;/code&gt; folder.&lt;br&gt;
These timeouts can be checked &lt;a href="https://docs.cypress.io/guides/references/configuration.html#Timeouts" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Inside your Cypress folder add the following export statements inside &lt;code&gt;plugin/index.js&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) =&amp;gt; {
   require("cypress-react-unit-test/plugins/react-scripts")(on, config);
   // IMPORTANT to return the config object
   // with the any changed environment variables
   return config;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this file, we have exported a function. Cypress is going to call this function, pass the project’s configuration, and enable it to bind to the events exposed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Writing your first unit test in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So we have created this basic react app in which the user will enter a value between 1-10 using an InputField and the progress bar will change its color accordingly, it also has a semi-circular progress bar that takes input and changes according to the value entered. We have used these components in the Litmus Portal as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case :&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the entered value is between 1-3, the progress bar color will change to red.&lt;/li&gt;
&lt;li&gt;If the entered value is between 4-6, the progress bar color will change to yellow.&lt;/li&gt;
&lt;li&gt;If the entered value is between 7-10, the progress bar color will change to green.&lt;/li&gt;
&lt;li&gt;In case of the semicircular progress bar, it will take an input between 1-100 and display the result accordingly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The landing page of our react app looks like this.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Famityt%2Fimage%2Fupload%2Fv1597931707%2Fezgif-7-e0ee4eb39be8_gak888.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Famityt%2Fimage%2Fupload%2Fv1597931707%2Fezgif-7-e0ee4eb39be8_gak888.gif" alt="Home Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s write some unit tests for these components:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Linear ProgressBar&lt;/strong&gt;&lt;br&gt;
For this component we’ll perform few tests, for example :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The length of the stroke according to the value&lt;/li&gt;
&lt;li&gt;The color progress bar when the value is 2&lt;/li&gt;
&lt;li&gt;The color progress bar when the value is 6 &lt;/li&gt;
&lt;li&gt;The color progress bar when the value is 8&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The test script for this component looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// &amp;lt;reference types="Cypress" /&amp;gt;
import React from "react";
import { mount } from "cypress-react-unit-test";
import LinearProgressBar from "../../src/components/ProgressBar/LinearProgressBar";

describe("Linear Progressbar Testing", () =&amp;gt; {
 it("Progressbar stroke for value 2", () =&amp;gt; {
   mount(&amp;lt;LinearProgressBar value={2} /&amp;gt;);
   cy.get(".rc-progress-line-path").should(
     "have.css",
     "stroke-dasharray",
     "20px, 100px"
   );
 });
 it("Progressbar stroke for value 8", () =&amp;gt; {
   mount(&amp;lt;LinearProgressBar value={8} /&amp;gt;);
   cy.get(".rc-progress-line-path").should(
     "have.css",
     "stroke-dasharray",
     "80px, 100px"
   );
   cy.get(".rc-progress-line-path").should("have.attr", "stroke", "#109B67");
 });
 it("Progressbar stroke for value 6", () =&amp;gt; {
   mount(&amp;lt;LinearProgressBar value={6} /&amp;gt;);
   cy.get(".rc-progress-line-path").should(
     "have.css",
     "stroke-dasharray",
     "60px, 100px"
   );
   cy.get(".rc-progress-line-path").should("have.attr", "stroke", "#F6B92B");
 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;describe()&lt;/code&gt;: This function is used to describe the test suite for the corresponding component as “Linear Progressbar Testing” &lt;br&gt;
&lt;code&gt;it()&lt;/code&gt;: Inside that, we have specified the particular test names like “Progressbar stroke for value 2” using this function.&lt;/p&gt;

&lt;p&gt;Note: &lt;code&gt;describe()&lt;/code&gt; and &lt;code&gt;it()&lt;/code&gt; are some of the test interfaces provided by Mocha.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe("Linear Progressbar Testing", () =&amp;gt; {
 it("Progressbar stroke for value 2", () =&amp;gt; {
   mount(&amp;lt;LinearProgressBar value={2} /&amp;gt;);
   cy.get(".rc-progress-line-path").should(
     "have.css",
     "stroke-dasharray",
     "20px, 100px"
   );
 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;mount()&lt;/code&gt;: This function mounts the component for testing. &lt;br&gt;
We have added the props that the components take i.e value={2} here.&lt;br&gt;
Once the component has been mounted/rendered properly we can check different properties of the component, like in this case, we are checking for the width of the progress bar when the value is 2 with the help of should(“have.css”, “css-property”, “css-value”)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Once the test succeeds , we get the following results in the browser:&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Famityt%2Fimage%2Fupload%2Fv1597931901%2FA_cptlpq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Famityt%2Fimage%2Fupload%2Fv1597931901%2FA_cptlpq.png" alt="Cypress Test 1 Linear Progressbar"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Similarly, in the next test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mount(&amp;lt;LinearProgressBar value={8} /&amp;gt;);
   cy.get(".rc-progress-line-path").should(
     "have.css",
     "stroke-dasharray",
     "80px, 100px"
   );
   cy.get(".rc-progress-line-path").should("have.attr", "stroke", "#109B67");
 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are re-mounting the component with a different prop ie value as 8.&lt;br&gt;
Once it is done, we can check the width of the progress bar and can check if the correct color is being displayed, in this case &lt;code&gt;“#109B67”&lt;/code&gt; as the value is above 7.&lt;br&gt;
This can be done using &lt;code&gt;should(“have.attr”,” stroke”,”#109B67”)&lt;/code&gt;, here we are checking if the color of stroke is according to the use-case i.e &lt;code&gt;Green / #109B67&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Famityt%2Fimage%2Fupload%2Fv1597932696%2FB_jwyg1g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Famityt%2Fimage%2Fupload%2Fv1597932696%2FB_jwyg1g.png" alt="Cypress Test 2 Linear Progress Bar"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Semi-Circular ProgressBar&lt;/strong&gt;&lt;br&gt;
The test script for this component looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// &amp;lt;reference types="Cypress" /&amp;gt;

import React from "react";
import { mount } from "cypress-react-unit-test";
import SemiCircularProgressBar from "../../src/components/ProgressBar/SemiCircularProgressBar";

// Test Suite -
// Progress Bar props -&amp;gt; value = 50, 10, 100
describe("Semi Circular Progress Bar has appropriate values", () =&amp;gt; {
 [50, 10, 100].map((i) =&amp;gt; {
   it(`Value is equal to ${i}`, () =&amp;gt; {
     const wrapper = &amp;lt;SemiCircularProgressBar value={i} /&amp;gt;;
     mount(wrapper);
     cy.get("[data-cy=progressValue]").then((value) =&amp;gt; {
       expect(value[0].innerText).to.equal(`${i}%`);
     });
   });
 });
});

// Test Suite - Icon has the correct src
describe("Icons have a correct path", () =&amp;gt; {
 it("Progress Bar icon has a correct source", () =&amp;gt; {
   const wrapper = &amp;lt;SemiCircularProgressBar value={40} /&amp;gt;;
   mount(wrapper);
   cy.get("[data-cy=progressIcon]")
     .should("have.attr", "src")
     .should("include", "./icons/graph.svg");
 });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this component we are performing four tests. Three tests to check if the proper values are being passed in the props and the last test is to check if the image is taken from the correct source.&lt;/p&gt;

&lt;p&gt;Here we are using an array of values that is being mapped with the component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[50, 10, 100].map((i) =&amp;gt; {
   it(`Value is equal to ${i}`, () =&amp;gt; {
     const wrapper = &amp;lt;SemiCircularProgressBar value={i} /&amp;gt;;
     mount(wrapper);
     cy.get("[data-cy=progressValue]").then((value) =&amp;gt; {
       expect(value[0].innerText).to.equal(`${i}%`);
     });
   });
 });

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are using &lt;code&gt;"[data-cy=progressValue]"&lt;/code&gt; to easily target the element for which we are writing the test cases. We can then make sure that the correct value is being displayed in the component as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Famityt%2Fimage%2Fupload%2Fv1597932939%2FC_fms7dd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Famityt%2Fimage%2Fupload%2Fv1597932939%2FC_fms7dd.png" alt="Test 1 Semi Circular Progress Bar"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Famityt%2Fimage%2Fupload%2Fv1597933056%2FD_snopmj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Famityt%2Fimage%2Fupload%2Fv1597933056%2FD_snopmj.png" alt="Test 2 Semi Circular Progress Bar"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it("Progress Bar icon has a correct source", () =&amp;gt; {
   const wrapper = &amp;lt;SemiCircularProgressBar value={40} /&amp;gt;;
   mount(wrapper);
   cy.get("[data-cy=progressIcon]")
     .should("have.attr", "src")
     .should("include", "./icons/graph.svg");
 });

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly, in these test cases, we are checking if the source of the image is correct with the &lt;code&gt;should()&lt;/code&gt; attribute that we discussed above.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;So these were some of the basic examples of unit testing we did with Cypress. If you wish, you can also add more test suites &lt;a href="https://github.com/litmuschaos/litmus/tree/master/litmus-portal/frontend/cypress/component" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Feel free to check out our ongoing project - &lt;a href="https://github.com/litmuschaos/litmus/tree/master/litmus-portal" rel="noopener noreferrer"&gt;Litmus Portal&lt;/a&gt; and do let us know if you have any suggestions or feedback regarding the same. You can always submit a PR if you find any required changes. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This blog is also contributed by:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/saranya-jena-7aa24912b/" rel="noopener noreferrer"&gt;Saranya Jena&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/vedant-shrotria-09a0ab188/" rel="noopener noreferrer"&gt;Vedant Shrotria&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Since this is our first blog, would love to know your views and suggestions. Feel free to reach out to us if you have any queries. Hope you found it insightful!&lt;/p&gt;

&lt;p&gt;Last but not the least, if chaos engineering is something that excites you or if you want know more about cloud native chaos engineering, don’t forget to checkout our &lt;a href="https://litmuschaos.io/" rel="noopener noreferrer"&gt;Litmus website&lt;/a&gt; and the &lt;a href="https://github.com/litmuschaos/litmus" rel="noopener noreferrer"&gt;Litmus repo&lt;/a&gt;. Do leave a star if you find it interesting. 😊&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>testing</category>
      <category>litmuschaos</category>
      <category>react</category>
    </item>
  </channel>
</rss>
