Testing makes everything better. Learn how to use Cypress for your Drupal website.
CC-BY 3.0 US
$ npm install cypress --save-dev

$ npx cypress open

If you don’t include tests in your Drupal development, chances are it’s because you think it adds complexity and expense without benefit. Cypress is an open source tool with many benefits:
Your project has at least this basic structure:

cypress/
node_modules/
vendor/
web/
.editorconfig
.gitattributes
composer.json
composer.lock
cypress.config.js
package-lock.json
package.json

This article originally appeared on the Aten blog and is republished with permission.

{
"name": "cypress",
"version": "1.0.0",
"description": "Installs Cypress in a test project.",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC"
}

In a separate window, a browser opens to the Create your first spec page:
This article covers three topics to help you start testing your Drupal project using Cypress:
Initialize your project using the command npm init. Answer the questions that Node.js asks you, and then you will have a package.json file that looks something like this:
For the purposes of this tutorial I’m assuming that you have built a local dev environment for your Drupal project using the `drupal/recommended-project` project. Although details on creating such a project are outside of the scope of this piece, I recommend Getting Started with Lando and Drupal 9.
Cypress Testing for Drupal Websites webinar, particularly the section on fixtures that begins at 18:33. That webinar goes into greater detail about some interesting use cases, including an Ajax-enabled form. Once you start using it, feel free to use or fork Aten’s public repository of Cypress Testing for Drupal.

Happy testing!


vendor/
web/
.editorconfig
.gitattributes
composer.json
composer.lock

The cypress.io site has complete installation instructions for various environments. For this article, I installed Cypress using npm.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.

Similar Posts