cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.09k stars 3.19k forks source link

feat: support Next 15 for Cypress Component Testing #30654

Closed AtofStryker closed 10 hours ago

AtofStryker commented 2 days ago

Additional details

Adds Next.js 15 support, which depends on React 19 RC support in #30651. Main changes here are to scaffolding.

System Testing is somewhat limited

Unfortunately, testing Next.js 15 inside the monorepo is somewhat difficult since the installed version in the system-tests projects is React 19, but the monorepo root is react 18. To get around this, we usually use a webpack alias to resolve the react version. However, this doesn't work for cypress/react (as cli/react/dist) since we reference it via import { mount } from "cypress/react", which is an esm style import through webpack which doesn't apply the aliases since the aliases point to CJS references. To get around this, we use a require() statement on the import so everything points to react 19 and we can test Next.js 15. This is only a problem due to our monorepo setup. In the wild, Next.js 15 works fine with ESM imports and can be tested via installing the built binaries against a create-next-app (as seen in https://github.com/cypress-io/cypress-component-testing-apps/pull/37).

Using Next.js 15 with the built binary from this branch

Testing the build binaries works as expected against Next.js 15 create-next-app. This works OOTB since the ReactDOM.render() changes merged upstream into cypress/react in #30590, so no custom test harness is needed 🎉

Steps to test

Highly recommend creating a Next.js 15 project with create-next-app and installing the build binaries and setting up component testing.

How has the user experience changed?

Users can now use Cypress Component Testing With Next.js 15 in Cypress 14

PR Tasks

cypress[bot] commented 2 days ago

cypress    Run #58560

Run Properties:  status check passed Passed #58560  •  git commit 41c9e19f09: feat: support next 15 [run ci]
Project cypress
Branch Review feat/support_next_15
Run status status check passed Passed #58560
Run duration 26m 21s
Commit git commit 41c9e19f09: feat: support next 15 [run ci]
Committer AtofStryker
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 3
Tests that did not run due to a developer annotating a test with .skip  Pending 1326
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 29324
View all changes introduced in this branch ↗︎
UI Coverage  46.07%
  Untested elements 187  
  Tested elements 164  
Accessibility  92.56%
  Failed rules  3 critical   8 serious   2 moderate   2 minor
  Failed elements 892