-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Cypress 10 | SASS Global Style File Imports Within Next.js - Unable To Run Cypress Component Test #22525
Comments
Import scss definitely works, I do it in some projects. We also have tests with Next.js that do it, eg: https://github.com/cypress-io/cypress/tree/develop/system-tests/project-fixtures/next (there is I will look into this. Thanks for sharing a reproduction, that's really useful. I will try to get to this in the next few days. |
We are having what I think is the same issue. Same error message inside cypress, and the terminal output shows this:
Repeated for every component that is loaded. We don't use SASS, but we have a couple global css imports in the style of Currently we are using Cypress 9 and @cypress/react version 5 which are working correctly. Upgrading to Cypress 10 and @cypress/react 6 is causing this issue. Next.js version is 12.1.5, I tried upgrading to Next.js 12.2.0 but no change. |
Not sure what I did, but now all of a sudden it works again |
Having a look now, I ran the reproduction and got:
I guess Next.js has something buried in the webpack config that stops this. Cannot proceed: Bizarrely, I commented out Either way, I think we probably should do some "under the hood" magic to make this a more seamless experience for Next.js users. We can modify the webpack config on the fly like suggested here. I'll mark this as an enhancement. Adding this should be simple, we do similar on the fly mods in the Next.js handler, see here: https://github.com/cypress-io/cypress/blob/develop/npm/webpack-dev-server/src/helpers/nextHandler.ts#L64-L98 |
Interesting, and thanks for looking into this @lmiller1990 So based on the article you had linked, it seems like from my understanding that Next.js only allows for the global CSS files to be imported from within the main Hopefully the enhancement work will allow for imports of global CSS within
|
@Sayvai no problem - we will need to do a hack, but it'll be in the Cypress code base, so you don't need to. I'm pretty swamped, I am not sure if I can do this during the next week or two, but I marked this as "ready for work" so someone at Cypress (or external, if someone is keen) wants to pick it up. If anyone outside Cypress wants to take a stab, ping me and I can point you in the right direction. |
I have an open PR to remove the global style restrictions that Next enforces. There are some binaries you can install from the PR to test it out locally to see if the fix works for you! |
@ZachJW34 - Thank you very much for applying the underlying configuration enhancement 🙌 I hope to test your changes at some point tomorrow, and will report back the status of your changes here 🤞 |
The code for this is done in cypress-io/cypress#22769, but has yet to be released. |
Current behavior
After launching Cypress Component Test application for the
Next.js
project, and importing multiple SASS (.scss
) files from within thecypress/component.ts
file, then i am unable to run a defined component test within the filenews-aggregator-article.cy.tsx
(link to file on repo). On the test rendering panel, only the textCannot GET /__cypress/src/index.html
is rendered out.See the highlighted screenshot below:
Is it not currently possible to import / support SASS style files for component testing? Or am i missing a step? 🤔
If SASS imports are currently not supported, are you able to advise or recommend how I may be able to render the styles within the component test?
Desired behavior
The component test should run within the Cypress Component Test application window, as well as successfully importing and rendering the styles defined within the SASS files (
.scss
)Test code to reproduce
You may reproduce the issue by cloning the project from the repo; nextjs-playground, and then checkout the branch;
cypress-integration
The relevant code files are listed below.
file:
component.ts
:file:
news-aggregator-article.cy.tsx
(component test):Cypress Version
10.2.0
Other
No response
The text was updated successfully, but these errors were encountered: