freeCodeCamp/docs/how-to-add-cypress-tests.md
Luis H. Ball Jr bbbc03c379
docs(cypress): create how-to-add-cypress-tests doc (#40262)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2020-11-21 23:34:13 +05:30

1.6 KiB

How to add Cypress tests

When making changes to JavaScript, CSS, or HTML which could change the functionality or layout of a page, it's important to add corresponding Cypress integration tests.

To learn how to write Cypress tests, or 'specs', please see Cypress' official documentation.

Note: When writing tests for freeCodeCamp, remember to add /* global cy */ to the top of the file to avoid ESLint issues.

Where to add a test

  • Cypress tests are in the ./cypress directory.

  • Cypress tests for a curriculum module are in the corresponding curriculum directory, i.e. cypress/integration/learn/responsive-web-design/basic-css/index.js.

How to run tests

1. Ensure that MongoDB and client applications are running

2. Run the cypress tests

To run tests against production builds, replace dev with prd bellow.

  • To run all tests in the ./cypress directory:

    npm run cypress:dev:run
    
  • To run a single test:

    npm run cypress:dev:run -- --spec=cypress/pathToYourSpec/youSpecFileName.js
    
  • To create a development build, start the development server, and run all existing cypress end-to-end tests:

    npm run e2e:dev:run