Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Upgrade Cypress from v9 to v12 #37810

Merged
merged 41 commits into from
Apr 6, 2023
Merged

chore: Upgrade Cypress from v9 to v12 #37810

merged 41 commits into from
Apr 6, 2023

Conversation

LekoArts
Copy link
Contributor

@LekoArts LekoArts commented Mar 30, 2023

Description

This updates our E2E tests from Cypress v9 to v12. Migration guide: https://docs.cypress.io/guides/references/migration-guide

I did also do some other following changes while at it:

  • Upgrade start-server-and-test to v2 (no breaking changes for us)
  • Switch from cypress-image-snapshot to @simonsmith/cypress-image-snapshot because the former isn't compatible with Cypress v12
  • Move Cypress configs to TS
  • Move support/plugins to TS
  • Move Cypress Cloud record keys to env vars
  • Move Cypress Cloud project IDs to config files
  • Add group names to trailing slash test suite

Tests

All tests should still run fully and pass.

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Mar 30, 2023
@LekoArts LekoArts added topic: automation Related to Circle CI, Peril, Renovate, scripts/*, Github Workflows, Github Actions, or Slackbot and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Mar 30, 2023
pieh
pieh previously approved these changes Mar 30, 2023
@@ -1,5 +1,3 @@
import { parseSrcset } from "srcset"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import

@@ -19,13 +19,15 @@
},
"devDependencies": {
"@cypress/snapshot": "^2.1.7",
"@simonsmith/cypress-image-snapshot": "^6.0.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cypress-image-snapshot doesn't work with Cypress 12 and this is a fork

@@ -39,8 +41,8 @@
"test": "cross-env CYPRESS_SUPPORT=y npm run build && npm run start-server-and-test",
"start-server-and-test": "start-server-and-test serve http://localhost:9000 cy:run",
"serve": "gatsby serve",
"cy:open": "cypress open",
"cy:run": "node ../../scripts/cypress-run-with-conditional-record-flag.js --browser chrome"
"cy:open": "cypress open --browser chrome --e2e",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cypress now also has component testing so this tells it to directly open the e2e test suite with the chrome browser

@@ -27,15 +27,18 @@ after(() => {
const errorPlaceholder = `false`
const errorReplacement = `true`

describe(`testing error overlay and ability to automatically recover runtime errors cause by content changes (page queries variant)`, () => {
it(`displays content initially (no errors yet)`, () => {
describe(`testing error overlay and ability to automatically recover runtime errors cause by content changes (page queries variant)`, { testIsolation: false } , () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New default in Cypress 12 is test isolation but these tests kinda rely on them so we opt-out

it(`plain less`, () => {
// we don't want to visit page for each test - we want to visit once and then test HMR
cy.window().then(win => {
cy.spy(win.console, `log`).as(`hmrConsoleLog`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already getting set inside the support/e2e.ts file with the

Cypress.Commands.overwrite("visit")

overwrite

window.notReloaded = true
window.___navigate(`/deep-link-page/`)
})
// just setting some property on the window
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -15,7 +15,7 @@ describe(`Production build tests`, () => {

// we expect 2 `componentDidMount` calls - 1 for initial page and 1 for second page
cy.lifecycleCallCount(`componentDidMount`).should(`equal`, 2)
cy.lifecycleCallCount(`render`).should(`equal`, Cypress.env(`TEST_PLUGIN_OFFLINE`) ? 3 : 2)
cy.lifecycleCallCount(`render`).should(`equal`, 2)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now works 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The paths for the snapshots changed. You can check the E2E test to compare the paths it generates now to this

@@ -10,8 +10,7 @@ const IS_CI = !!(
false
)

const shouldRecord =
!!process.env.CYPRESS_PROJECT_ID && !!process.env.CYPRESS_RECORD_KEY && IS_CI
const shouldRecord = !!process.env.CYPRESS_RECORD_KEY && IS_CI
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

projectId is now mostly in the config file itself, so this had to go

@@ -22,6 +21,10 @@ const cypressArgs = [`run`, ...process.argv.slice(2)]

if (shouldRecord) {
cypressArgs.push(`--record`)

if (process.env.CYPRESS_GROUP_NAME) {
cypressArgs.push(`--group`, process.env.CYPRESS_GROUP_NAME)
Copy link
Contributor Author

@LekoArts LekoArts Apr 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--group alone fails if --record is not also given

@LekoArts LekoArts marked this pull request as ready for review April 6, 2023 07:21
@LekoArts LekoArts requested a review from pieh April 6, 2023 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: automation Related to Circle CI, Peril, Renovate, scripts/*, Github Workflows, Github Actions, or Slackbot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants