-
Book Overview & Buying
-
Table Of Contents
End-to-End Web Testing with Cypress
By :
scripts is a package.json property that gives a user the ability to run commands via the command line in JavaScript applications. npm scripts can be used to add environment variables to the properties of an application, package applications into production-ready bundles, run tests, or automate any other activity in JavaScript applications. npm scripts can either be used as defined by npmjs.com or customized based on the user's preferences and applications. In this section, we will learn how to write npm scripts to run our Cypress tests, to open our Cypress tests, and even to combine different npm scripts to achieve different results.
To create a scripts command to open Cypress, you need to write the script name then add the command that npm will run when the script is executed. In this case, our command to open Cypress will be embedded in a script called open. We can achieve this by adding the following command to the scripts object in package.json:
"scripts": {
"open": "npx cypress open"
}
To run the open command, you simply need to run the npm run open command, and the test runner should open on the default browser selected in the Cypress test runner.
In this section, we learned what npm scripts are and how to add them to the package.json file. We also learned how we can run the npm scripts that we have added to our package.json file to execute and automate tasks in our projects. Next, we'll learn how to run tests in Cypress.