-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
next js component tests config is using framework.react
instead of next
which causes dev server errors for server components
#21768
Comments
react
instead of next
which causes dev server errors for server components
As a workaround for now, I ended up with the following:
then the trick is to not impot anything next related in test itself.
Finally in test
I haven't tested it deep yet, but at least I am able to see component is rendered now |
Also experiencing the exact same issue reported by @tar-aldev using the out-of-the-box Component testing generator for NextJs. Followed the docs and Juri's video and configuration is otherwise the same. |
Hey, thanks for reporting there are a few things to unpack here related to generating a cypress config for a library created with I think we need to fix the error generated by importing the style. Everything else should be working as expected.
This might seem to work for your test but it creates new issues as you have completely removed the If you want to add the router to your library you need to ensure Cypress is configured to test it. |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
When generating cypress component test config for next using
nx generate @nx/next:cypress-component-configuration
it creates the following cypress.config.ts
It works fine for client components, but when trying to test server components (even if they have no specific features), webpack dev server gives errors like:
Expected Behavior
Should be able to use generated cypress config to run component tests for both client and server components.
Should be able to stub next specific features (like router)
GitHub Repo
https://github.com/tar-aldev/next-nx-cypress
Steps to Reproduce
nx generate @nx/next:cypress-component-configuration
Using reproduction repo:
npx nx component-test test-lib --watch=true
HelloServer
Nx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
Using
I tried based on this example repo https://github.com/mike-plummer/nextjs-cypress-ct-example/tree/main
If you clone that repo everything is working fine there. So it's not a cypress problem or next problem.
I can also see in cypress docs, that they set framework as
next
https://docs.cypress.io/guides/component-testing/react/overview#NextjsIf I check nx source code https://github.com/nrwl/nx/blob/master/packages/next/plugins/component-testing.ts#L158 I see that
framework
is set toreact
there.Could it be a problem?
When I try to change generate config to
When I run it though, it gives another error
UPD:
The above error was caused by this import in libs/cypress/support/component.ts
After removing it, the error is gone
UPD 2:
while it works for smth simple, it fails for simple things, like when importing an interface
UPD 3:
Tried using it like this
Unfortunately, it fails with a weird error
So it's kind of broken it seems:
when using OOTB
nxComponentTestingPreset
it fails when there is any server component.when trying to extend it to specify
next
asframework
it fails with sourcemap problems.The text was updated successfully, but these errors were encountered: