<?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: Syond</title>
    <description>The latest articles on DEV Community by Syond (@syond).</description>
    <link>https://dev.to/syond</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%2F1094991%2F27b64f1a-1107-4c2f-88f6-2fc436aeb349.jpeg</url>
      <title>DEV Community: Syond</title>
      <link>https://dev.to/syond</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/syond"/>
    <language>en</language>
    <item>
      <title>How to integrate Cypress (with GUI) on Vue project using Docker</title>
      <dc:creator>Syond</dc:creator>
      <pubDate>Sat, 03 Jun 2023 21:56:18 +0000</pubDate>
      <link>https://dev.to/syond/how-to-integrate-cypress-on-vue-project-with-docker-521n</link>
      <guid>https://dev.to/syond/how-to-integrate-cypress-on-vue-project-with-docker-521n</guid>
      <description>&lt;p&gt;Hey! How are you ? I hope you doing well :)&lt;/p&gt;

&lt;p&gt;This time I will show you how to run Cypress inside a Docker container (with GUI option), so you can make your e2e tests without need to install Cypress dependencies (browsers) in your host machine!&lt;/p&gt;




&lt;h2&gt;
  
  
  Pre-requisits:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Docker&lt;/li&gt;
&lt;li&gt;X11 server&lt;/li&gt;
&lt;li&gt;Vue project&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I recommend you to use Linux. If you are using Windows I recommend you to use WSL2.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's do this!
&lt;/h2&gt;




&lt;h2&gt;
  
  
  Step 1 - Create docker-compose file for your project
&lt;/h2&gt;

&lt;p&gt;Go to root project folder and create a file called: &lt;code&gt;docker-compose.yml&lt;/code&gt;. Copy/paste this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.8'
services:
  app:
    image: node:20.1.0
    container_name: vue-project
    working_dir: /vue-app
    volumes:
      - ./:/vue-app
    command: bash -c
      " npm install
      &amp;amp;&amp;amp; npm run dev"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code creates a container with Node 20 for your Vue project.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;command&lt;/code&gt;: this option runs &lt;code&gt;npm install&lt;/code&gt; and &lt;code&gt;npm run dev&lt;/code&gt; after. Make sure you have &lt;code&gt;dev&lt;/code&gt; script on your &lt;em&gt;package.json&lt;/em&gt; or just change the script here for your context.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 - Create docker-compose file for Cypress
&lt;/h2&gt;

&lt;p&gt;Go to root project folder and create a file called: &lt;code&gt;docker-compose-e2e.yml&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Put this code into this file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.8'
services:
  cypress:
    image: cypress/included
    working_dir: /e2e
    container_name: vue-project-e2e
    entrypoint: "cypress open --project ."
    volumes:
      - ./tests/e2e:/e2e
      - /tmp/.X11-unix:/tmp/.X11-unix
    environment:
      - DISPLAY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code create Cypress service with official Cypress Docker image that you can find on &lt;a href="https://hub.docker.com/"&gt;https://hub.docker.com/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;entrypoint: "cypress open --project ."&lt;/code&gt;: It means this container will run this command when startup. Basically this command run Cypress inside the current folder.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;- ./tests/e2e:/e2e&lt;/code&gt;: Creates a volume only for e2e tests folder. This is important because the code above will break without this. You can change the volume name on your host machine as you want.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;- /tmp/.X11-unix:/tmp/.X11-unix&lt;/code&gt;: This is the basic GUI structure for Linux to make the connection between container and host for Cypress GUI can works.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;- DISPLAY&lt;/code&gt;: It's Cypress enviroment variable for display GUI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 - Running Cypress with GUI
&lt;/h2&gt;

&lt;p&gt;Run this command:&lt;br&gt;
&lt;code&gt;docker compose -f docker-compose.yml -f docker-compose-e2e.yml up --exit-code-from cypress&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can put this into your &lt;em&gt;package.json&lt;/em&gt; to make easy to use.&lt;/p&gt;

&lt;p&gt;Now you are ready to create your own E2E tests. I will not cover Cypress configuration this time, maybe later if you like this post! ;)&lt;/p&gt;




&lt;p&gt;Nice, right ?! :)&lt;br&gt;
If you like this tutorial, please like, follow, and comment.&lt;/p&gt;

&lt;p&gt;Thank you and I see you next time! ;)&lt;/p&gt;

</description>
      <category>vue</category>
      <category>docker</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
