-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Component testing + Next JS using @cypress/react/plugins/next configures the 'pages' directory wrongly #17898
Comments
Was about to create an issue for this as well. I think one of the solutions, like @rafaelchiti mentioned would be to let us pass that configuration to the |
Wow, I've been tracking down the same bug just now and created a Thanks for all the investigation you put into this @rafaelchiti |
I can also confirm that I could avoid the issue by replacing |
Yes, I can take a look later today! |
@rafaelchiti Thanks for all the detail, it's was super helpful. I tested out your repo and confirmed the issue (and the fix by changing |
That sounds great, agree about making it a convention, wouldn't make sense to make it configurable when next js itself doesn't allow configuration for it. Thanks 🙌. |
Any news on this one? |
(I'm not speaking on behalf of the team but just in case this is useful) While the PR gets merged and the release cut, is straightforward to copy paste the files used and modify manually, then you can remove them once the new release is out. You only need to cc the following files (and adjust the import paths):
And then in your plugins file you import the 'injectDevServer' from your cc'ed version (the ...plugins/next/index.js file).
I know is not ideal but will get you going until this gets released. |
That’s what I’ve been using for development purposes but my pipelines break, hence my question 👌 |
This PR will fix the problem and be automatically released via semantic release once it is merged into master. |
The code for this is done in cypress-io/cypress#18009, but has yet to be released. |
This should be fixed now. The latest version of If this is still a problem, we can reopen and look into it again. Thanks! |
The fix for this is inside |
We use semantic release so anything merged into master should be released immediately. It looks like this didn't happen - maybe something failed in CI, so the release didn't go ahead. I will try re-running the master pipeline, which should trigger a release. The standard release cycle for Cypress is every two weeks, so worst case, it'll be out in two weeks. In this case, I'd like this to be released immediately, so I'll look into it. Edit: it looks like the semantic release step is failing. I think we rotated some tokens but this got missed. I'll raise this internally. |
Was this released already? It’s not included in the 8.5.0 release notes |
Seems semantic release is still problematic, so any changes under The 8.5.0 release notes are only for the main Cypress app, everything under |
@AndreSilva1993 @rafaelchiti this change has been released in |
Current behavior
I believe that the internal configuration from the
@cypress/react/plugins/next
configures 'nextjs' to think that the pages directory is the 'root folder of the project' rather than${rootFolder}/pages
.If you look at this line:
![Screen Shot 2021-08-26 at 4 06 35 PM](https://user-images.githubusercontent.com/1154663/130977588-f366adb7-3e97-4bb9-8a13-674b03322c29.png)
https://github.com/cypress-io/cypress/blob/develop/npm/react/plugins/next/findNextWebpackConfig.js#L29
The findNextWebpackConfig util is setting the pagesDir to the root of the project.
Consequences
Because of that I'm seeing that next js webpack config is treating every folder in my root as a 'pages' folder, trying to bundle them as if they were pages. I bumped into this because I started seeing the following error while running component tests:
At first I thought I had some 'export * from ...' inside a 'page' but that was not the case. I found that a file inside
${root}/src/UILibrary/icons
was doingexport * from ...
. And because of how the cypress next plugin is configuring webpack my/src/UILibrary/icons
is being treated as a page by next+webpack.Desired behavior
Not fully certain of the solution. Probably allow to pass that configuration instead of assuming that
pagesDir
isconfig.projectRoot
. So we can do the following inside our plugins config file:Optionally we could have a better default pointing to
${root}/pages
(if it exists) or to${root}/src/pages
(which is the second option that nextjs recognizes as convention.Test code to reproduce
I forked the webpack example from cypress docs and added a
export * from ...
to trigger the error. (this happens in webpack 4 or webpack 5 config the same. I used the webpack 4 because I wanted to use the official example published by cypress with the minimum amount of changes).Here the fork and branch where to try it: https://github.com/rafaelchiti/cypress-component-examples/tree/bug_repro
To see the error make sure you are on that branch
bug_repo
and run:cd nextjs-webpack-4
to focus on the next exampleyarn install --pure-lockfile
DEBUG=* yarn run cypress run-ct
If you don't set a wide debug filter option then the error gets swollen (probably there is a more limited debug config that still prints the error). Then after running that you should find in the terminal an error like:
But if you look in the code there is no
export * from ...
inside the pages directory. But there is though anexport * from ...
inside thesrc/icons
directory (which I added to test the problem).Cypress Version
7.2.0 also tried on 8.3.0
Other
No response
The text was updated successfully, but these errors were encountered: