-
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 config with monorepo and rewired cra #22521
Comments
I think you are right, it is not finding Eg: import { defineConfig } from 'cypress'
import defaultConfig from './cypress-webpack.config'
import { devServer } from '@cypress/webpack-dev-server'
export default defineConfig({
component: {
devServer: (devServerOptions) => devServer({
...devServerOptions,
framework: 'react',
webpackConfig: {}, // customize it here!,
}),
supportFile: false
}
}) Where I wrote "customize it here" you could import your config-overrides and do things there. This is how |
Well, i don't wanna create a whole webpack config by myself, because it's too huge - that would be the whole repo of react-scripts. i thing i have some variant's and some test's of them. Also probably there is no way that i can get the config from runtime but i can change the cra's webpack config. after cypress get it? The cra's webpack-config.js are in
|
No way that would be work with cra:
|
@MohoiNad I'd like to pick up investigating this one, but it's been a couple of weeks so please let me know first if you've had and progress in the meantime on your own before I spend much time in it. Mainly I want to figure out
Did you give this a shot? I did pull down your repo a though I got past your error (by setting the NODE_ENV Generally when using the config from
Which could be got around by providing those values, but it feels like that gets a little heavy handed, and it would make more sense if it "just worked" with the existing setup you have for development. |
Unfortunately we have to close this issue due to inactivity. Please comment if there is new information to provide concerning the original issue and we can reopen. |
@MohoiNad hi, have you had a chance to solve this issue? |
@AtofStryker can this issue be reopen? |
Hi,
The general idea was to extend what @marktnoonan did with the config from cra. I just replaced webpack config with required because it have overrides. Then I was figting with the errors in console, not 100% that this config is correct but at least it work |
@this-miguel, can you confirm if the suggested steps from @marktnoonan help at all? |
it didn't work for me. If I understand correctly that can't work because if cypress only takes the webpack config from CRA any customisation done with rewired CRA will not be taken on account. I've been trying something like @MohoiNad but I've not been able to make it work yet |
is anybody working to solve this issue on the cypress team? |
i'm trying to left from cra to nx workspaces. probably https://www.npmjs.com/package/patch-package is looks like the best solution for this issue. i will try to leave a report "how-to" on the week or like so. |
@this-miguel there is no active work happening as of right now internally to make CRA-rewired a first class citizen, but it can be certainly accomplished. This should be do-able in the same way suggested above. If we were to support this as a first class framework, this is how it would be implemented, too. import { defineConfig } from 'cypress'
import defaultConfig from './cypress-webpack.config'
import { devServer } from '@cypress/webpack-dev-server'
export default defineConfig({
component: {
devServer: (devServerOptions) => devServer({
...devServerOptions,
framework: 'react',
webpackConfig: async () => {
// customize it here! your own config, import a rewired one, etc.
const craRewiredConfig = await import('./your-webpack-config.js')
return craRewiredConfig
},
}),
}
}) This is how we implement all the frameworks in Cypress - each one just has a custom config, which goes off to find the correct config depending on the framework (next, vite). Basically, Would this help with your use case? Did you try this -- if so, did you get some kind of error/blocker? |
I share a simple config example that initializes react-app-rewired before import { defineConfig } from 'cypress';
/**
* "Rewire" the webpack config before `loadWebpackConfig` accesses it through `react-scripts`
* @see @cypress/webpack-dev-server/dist/helpers/createReactAppHandler.js:41
*/
process.env.NODE_ENV = 'test';
process.env.BABEL_ENV = 'test';
require('react-app-rewired/config/webpack.config')('development');
export default defineConfig({
component: {
devServer: {
framework: 'create-react-app',
bundler: 'webpack',
},
},
}); @marktnoonan @lmiller1990 Storybook has a nice config option in its CRA preset that makes it possible to use custom package name for export default defineConfig({
component: {
devServer: {
framework: 'create-react-app',
bundler: 'webpack',
scriptsPackageName: 'react-app-rewired', // `scriptsPackageName` defaults to `react-scripts`
},
},
}); Ref: #9688 |
Hi @bencergazda, that's neat - I did not realize you could do it like that. Re: API - I'm working on such a public API right now. This only adds support for libraries right now - think Vue, React, etc - so you can choose the dependencies you support, inject a Right now there's not a way to inject something like you are describing yet, but there will be, I'm trying to figure out the right API to expose. From a user point of view, it'll like be: export default defineConfig({
component: {
devServer: {
framework: 'react-app-rewired',
bundler: 'webpack',
},
},
}); If you've got any ideas, that'd be great - I was thinking something like export default defineComponentFramework({
type: 'react-app-rewired',
name: 'React Rewired',
devServer: async (cypressConfig, bundler) => {
// you can do something different depending on the bundler?
// some frameworks have both Vite and Webpack, etc.
// must return relevant config
// eg return require('react-app-rewired/config/webpack.config')('development');
}
}) Would this work for your use case? |
@lmiller1990 I think that the |
@bencergazda I agree we can give a great UX for fine tuning the config with this new API. There's a lot to consider to make this as robust as possible, we will be exploring it more in our next sprint of work. Follow #25881 If you've got feedback/ideas, you could share them in that issue, too - the more we know about the various use cases, the better! |
Hello Cypress team,
Here's my cypress.config.js that I copied from one of the threads above
config-overrides.js
I have created a question for the same on stackoverflow that also includes my package.json details Can you please help me? I have been stuck on this for days now. |
Are you using Yarn workspaces? Possibly related: timarney/react-app-rewired#618 Best would be a minimal reproduction - can you share a minimal repo? I don't have the bandwidth to manually reproduce your error. Eg - I'll probably get a different |
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
This issue has been closed due to inactivity. |
Current behavior
I have a lerna monorepo with 2 cra's in my repo, where is one a customized by cra-customize and react-app-rewired.
package-a
includes 2 tests.One is cypress, second is @testing-library/react
I feel like config-overrides.js are not wotking with cypess, that's why test in red. Can i somehow override the wepback configuration from cypress to same way?
Maybe new cypress.config.ts can help me?
Desired behavior
Both tests green.
Test code to reproduce
https://github.com/MohoiNad/cypress-issue
Cypress Version
10.2.0
Other
I have some problems with babel if i am using customize-cra config,
The text was updated successfully, but these errors were encountered: