Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Latest commit

 

History

History
230 lines (164 loc) · 5.24 KB

File metadata and controls

230 lines (164 loc) · 5.24 KB

Cypress Netlify Build Plugin

📚 You will learn

  • How to easily run Cypress on Netlify
  • How to run tests after the deploy
  • How to run tests before the deploy

💡 see github.com/cypress-io/netlify-plugin-cypress


Motivation

Deploying a web application to Netlify is very simple, and adding Cypress E2E to the deploy process via netlify-plugin-cypress is a breeze

Repo github.com/cypress-io/netlify-plugin-cypress


Deploy new site from GitHub

+++ Pick the GitHub repo

+++ Start deploying

+++

You can change the site name

Netlify site name

Yarn users

Netlify automatically detects if you are using package-lock.json or yarn.lock file to pick the right install command.


Use Netlify.toml file

Instead of the deploy settings in Netlify GUI

  • explicit settings
  • tracked in source control

+++ netlify.toml file

[build]
command = "npm run build"
publish = "_site"

+++

Inspect the build log

Netlify deploy log


Let's start testing

$ npm i -D netlify-plugin-cypress
+ [email protected]
[build]
command = "npm run build"
publish = "_site"
[[plugins]]
  package = "netlify-plugin-cypress"

💡 see github.com/cypress-io/netlify-plugin-cypress

+++

Inspect the build log

Cypress tests running on Netlify

+++

Fix the warning

tput: No value for $TERM and no -T specified
[build]
command = "npm run build"
publish = "_site"
[build.environment]
  TERM = "xterm"
[[plugins]]
  package = "netlify-plugin-cypress"

Note that the tests are failing

Netlify tests failed

+++

TODO set up test recording

💡 Tip: see github.com/cypress-io/netlify-plugin-cypress

+++

[build]
command = "npm run build"
publish = "_site"
[build.environment]
  TERM = "xterm"
[[plugins]]
  package = "netlify-plugin-cypress"
  [plugins.inputs]
    record = true

+++

Set CYPRESS_RECORD_KEY on Netlify

+++

Record test run on Netlify


TODO: fix the test

Failed test screenshot

+++

- cy.location('pathname').should('equal', '/README/')
+ cy.location('pathname').should('match', /\/readme\//i)

TODO: set your tag and group names

Tag and group

💡 Tip: see github.com/cypress-io/netlify-plugin-cypress


Why is Netlify deploy green if the E2E tests failed?

Full answer in the webinar "Build, Deploy, and Test" https://cypress.slides.com/cypress-io/build-deploy-and-test

+++

Deploy phases

  • Start
    • preBuild
  • Build
    • postBuild
  • Deploy
    • onSuccess

By default, Cypress tests run in the "onSuccess" step

+++

Enable tests in preBuild

💡 Tip: see github.com/cypress-io/netlify-plugin-cypress

+++

[build]
command = "npm run build"
publish = "_site"
[build.environment]
  TERM = "xterm"
[[plugins]]
  package = "netlify-plugin-cypress"
  [plugins.inputs]
    record = true
  # run Cypress tests before building and deploying
  [plugins.inputs.preBuild]
    enable = true
    # call the same commands as we do locally
    start = 'eleventy --serve'
    wait-on = 'http://localhost:8080'
    record = true

Todo: run all tests pre-deploy and smoke tests after deploy

💡 Tip: see github.com/cypress-io/netlify-plugin-cypress


Netlify Build uses 1 machine

💡 If you need to run lots of tests after deploy you might want to use another CI, for example github.com/bahmutov/netlify-plugin-github-dispatch


GitHub Status Checks

We want Cypress Dashboard to set the status on every pull request.

+++ Cypress GH App repo

+++ Enable Cypress GH App from the project's settings

+++

Open a new pull request

🚨 use your repo and not cypress-io/cypress-workshop-ci-example

+++

See the GitHub status checks

Pull request status checks from CI and from Cypress


⌛️ Review

Jump to: Generic CI, GitHub Action, CircleCI, Netlify Build