How to start the local server for Cypress testing?

Running a Cypress test server is easy only when you have the right commands handy. Cypress documentation is a pain when it comes to referring them for an issue you are stuck at. Also, I have noticed that the resources on Google related to Cypress are limited. When you search for it, Cypress Official Docs are all over the search. And guess what, they aren’t much help when it comes to real life problems while coding.

Problem

There are cases when you would like to run your tests locally. Way before pushing your code to git, running tests locally can help identify failures.

Solution

Navigate to package.json file in your project folder. Scroll down until you see “scripts”

"scripts": {
    "start": "PORT=4000 react-scripts start",
    "testStarter": "PORT=9000 react-scripts start",
     ...
  },

Script for starting test server is defined here. Look for the correct script defined in your project. For instance, to run a Cypress server, open a new terminal window, navigate to the project folder and type:

yarn testStarter

Now, in an another terminal window or tab, type this command to open Cypress window with tests listed:

For npm users,

npx cypress open

For yarn users,

yarn run cypress open

Click on the test you would like to run locally in your system. The test will run in the browser window and result will be displayed.

Questions?

Hit me up in the comment section if you have any question.

Stay safe & Get Vaccinated! 💪🏻

Published by Jayesh

I code and energize, loves sharing my journey.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s