question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Components testing - Webpack entry feature causes confusion

See original GitHub issue

Current behavior

when loading app’s webpack config cypress will build the app using the entry configuration of webpack. Then the bundled JS is injected in cypress when loading a component.

The issue is that with many default webpack configs will create errors in this configuration because the bundle will be a JS file that tries to render the app in the html. For example ReactDom.render(<App/>, someElement);. That is not a desired behavior for cypress components testing.

Desired behavior

@ZachJW34 proposed:

I think there could be a configuration option that would make sense for this. I imagine most people who provide a custom webpack config would want their apps entrypoint pruned


I would add that I understand the need to give an opportunity to inject global styles and global js stuff globally but I think it should at the minimum be mentioned in the doc and in the getting started guide to make sure people don’t spend a long time figuring out why it’s not working

Test code to reproduce

Clone that repo: https://gitlab.com/souf/react-webpack-playground/-/blob/cypress-webpack-entry/webpack.config.js using branch cypress-webpack-entry.

Run yarn install then yarn cypress:open. Open the component testing for the component App. Observe the error in the console triggering because the app tries to render in cypress’s frame without a match DOM element for the given id.

image

Cypress Version

10.4.0

Other

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ZachJW34commented, Aug 11, 2022

@gsouf we normally recommend importing them into the support file. Some frameworks rely on some entrypoint being injected into the index.html, like a style tag but an equivalency would be to import '../../src/my-styles.css' in cypress/support/component.js

0reactions
cypress-bot[bot]commented, Aug 15, 2022

Released in 10.5.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to Cypress v10.5.0, please open a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack — The Confusing Parts - Medium
When I first saw a Webpack config file, it looked very alien-y and confusing . After playing around with it for some time, ......
Read more >
A Guide to Managing Webpack Dependencies - Toptal
The Webpack module bundler processes JavaScript code and all static assets, such as stylesheets, images, and fonts. However, configuring Webpack and its ...
Read more >
component-driven/cypress-axe - Warnings with Webpack 5
WARNING in ./node_modules/cypress-axe/dist/index.js 16:47-54 Critical dependency: require function is used in a way in which dependencies ...
Read more >
Entry Points - webpack
We will show you the ways you can configure the entry property, in addition ... to the entry property which creates what is...
Read more >
Why doesn't Webpacker use my test config when I run Rails ...
It turns out, even though RAILS_ENV is set to 'test', NODE_ENV is set to 'development' (source) and the webpack config is determined directly ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found