-
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
[7.0.1] Component testing not working with Next.js and future.webpack5 configuration #15864
Comments
I had this same issue - initially fails as can't find webpack. If webpack is added as dependency then it fails as you describe but with debugging on shows a 'compilation must be an instance of Compilation' error. |
Updating this issue to reflect that it's specific to nextjs with the |
@JessicaSachs Even with the future.webpack5 set as false it still won't work. You can't try it in the repo I created to reproduce the problem. @djsilcock Thanks for the quick reply. |
The code for this is done in cypress-io/cypress#15885, but has yet to be released. |
Working through this exact same issue. Is there an estimate on when it will be released? I am pushing to have this be the tool we use to test our components, but without an ETA the team may have me utilize something else. Thanks for the quick responses! |
It occurred to me earlier that a better approach might be instead of trying to extract the nextjs config and the monkeypatched webpack, that it might be easier to use the actual next devserver instead. Will share some code later |
Anything merged into master inside of the I just installed it and can confirm the code is there: const findNextWebpackConfig = require('./findNextWebpackConfig')
module.exports = (on, config) => {
on('dev-server:start', async (options) => {
const webpackConfig = await findNextWebpackConfig(config)
// require('webpack') now points to nextjs bundled version
const { startDevServer } = require('@cypress/webpack-dev-server')
return startDevServer({ options, webpackConfig })
})
config.env.reactDevtools = true
return config
} Please install it and give it a try! Let us know if there is still any problems. |
@lmiller1990 I updated the packages on my example repo (https://github.com/edusig/next-and-cypress-example) to the latest and now I'm getting another error:
Packages versions: I also tested downgrading the @cypress/webpack-dev-server to version 1.1.2 and re-installing html-webpack-plugin and it finally opened, but it stuck loading the first component test file. |
I tried cloning @edusig code and moving around dependencies, making webpack 4, removing flags and i still cant get it to work :( |
I reproduced the problem: #16078 The stack trace comes from in
I will dig deeper. Edit: this problem is unique to the cypress monorepo, since we hoist the dependencies to the root |
Ok, I think the problem is we have
As well as specifying This is proving more complex than expected but I'm working through it and should have something soon. |
Bring your own webpack is exactly what I'm going for. Nextjs seems kind of unique in that they bundle and ship their own webpack implementation. I made this PR: #16108 Basically users need to have either The only real downside here is we require quite a lot of
I don't think this really a major problem. Most templates will specify their I think this solution is a little better in terms of long term maintainability. We are also working on a |
I actually meant that you could supply webpack to webpack-devserver rather than have it
|
Hope I'm not side-tracking this issue - but how do you get it to work with just the webpack version that NextJS is using in your application? I have tried the |
The code for this is done in cypress-io/cypress#16108, but has yet to be released. |
I managed to remove the hard requirement of html-webpack-plugin v4 here. #16108 This should fix the problem - all you'll need to do now is install webpack 5 and html-webpack-plugin 5 and it should work. This should minimize the framework specific concerns from leaking too deeply into Cypress. The above code will go out in the next release. Thanks everyone so far - it's entirely possible that some edge cases are not covered still (nextjs ecosystem is huge), but keep the bug reports coming 👍 I started to use nextjs a little from this - it's really neat, and the DX experience is great! Let's keep this issue open until the code is in the wild and confirmed to be working as expected. |
Next.js just released the new version 10.2 https://nextjs.org/blog/next-10-2 which enables webpack5 by default. Has anyone tried this version with Cypress component testing ? |
@lmiller1990 and @nottyo I have just updated my example repo (https://github.com/edusig/next-and-cypress-example) and it is working perfectly. I also updated Next.js to v10.2.0 and there was no problem running the tests. On other projects, which have a more complex Next.js/Babel/Cypress/Yarn workspaces configuration it seems to be working perfectly as well. Thanks again for all the help and quick resolution :) |
@edusig Thanks I also write a blog post for this https://nottyo.medium.com/component-testing-next-js-application-with-cypress-28fa311adda6 |
There is a PR for detailed docs with information on how to use Cypress with both next.js + webpack 4 and 5 here: cypress-io/cypress-documentation#3883 Incredibly good blog post @nottyo! Seems this is working fine now - I'm sure we will find some edge cases for more complex configurations, if so, please open a discussion. |
Current behavior
Cypress
open-ct
andrun-ct
both get stuck while using:Nextjs: 10.1.3
React: 17.0.2
Cypress: 7.0.1
Webpack: 5.30.0
my next.config.js file:
cypress/plugins/index.js file:
Desired behavior
It should run normally
Test code to reproduce
I have forked this repo and updated the packages and configurations here -> https://github.com/edusig/next-and-cypress-example
Versions
Cypress: 7.0.1
Last working Cypress version: 6.5.0
OS: Manjaro Linux
More information
The text was updated successfully, but these errors were encountered: