Cypress component testing - multiple issues
See original GitHub issueCurrent Behavior
The following currently seems to not be supported in the component testing configuration preset when running nx g @nrwl/react:cypress-component-configuration
:
- React SVGR
- Tailwind / PostCSS
@testing-library/cypress
Expected Behavior
The issues above are supported OOTB in React apps/libs, so they should probably be supported here as well.
Steps to Reproduce
- Create a workspace @ v14.5.0 with a React library
- Add tailwind & PostCSS configuration
- Add a
styles.css
file that imports tailwind stuff (base, components & utils) - Run
nx g @nrwl/react:cypress-component-configuration
with the relevant lib - Add
import @testing-library/cypress/add-commands
tocomponent.ts
- Add
import '../../src/styles.css
tocomponent.ts
- Run
nx component-test --watch
Result:
- With testing library, you should see the error
exports is not defined
- With the CSS file, you should see errors related to the tailwind usage
Hereβs a repo with the reproduction - https://github.com/danr-za/cypress-ct-nx
Failure Logs
Environment
Node : 16.13.0
OS : darwin x64
yarn : 3.2.2
nx : 14.5.0
@nrwl/angular : Not Found
@nrwl/cypress : 14.5.0
@nrwl/detox : Not Found
@nrwl/devkit : 14.5.0
@nrwl/eslint-plugin-nx : 14.5.0
@nrwl/express : Not Found
@nrwl/jest : 14.5.0
@nrwl/js : 14.5.0
@nrwl/linter : 14.5.0
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : 14.5.0
@nrwl/nx-cloud : 14.2.0
@nrwl/nx-plugin : Not Found
@nrwl/react : 14.5.0
@nrwl/react-native : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : 14.5.0
@nrwl/web : 14.5.0
@nrwl/workspace : 14.5.0
typescript : 4.7.4
---------------------------------------
Community plugins:
nx-stylelint: 13.5.2
Issue Analytics
- State:
- Created a year ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Component Testing FAQ | Cypress Documentation
Cypress supports multiple frameworks and development servers for component testing.
Read more >How Cypress Component Testing changed our workflow (and ...
A component test running in Cypress with the Command Log on the left and the Component Under Test on the right. Maintenance troubles...
Read more >Introducing the Cypress Component Test Runner
Our Component Test Runner executes your component tests in the browser as a user would by simulating real interactions by using Cypress's robustΒ ......
Read more >Writing and Organizing Tests - Cypress Documentation
To start writing tests for your app, follow our guides for writing your first Component or End-to-End test. Needing a low code approach...
Read more >Cypress Component Testing
Cypress Component Testing provides a component workbench for you to quickly build and test components from multiple front-end UI libraries β no matter....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@danr-za working on a fix for this now. got a PoC working levering
@nrwl/web:webpack
which would provide a more robust experience for component testing and have it working with your example repo you provided (thank you for providing it!). I hope to have a PR up some time before the end of the week.https://user-images.githubusercontent.com/23272162/186254995-5e7f3e32-db71-420c-b28b-643ccc36e8a0.mp4
@Huink7 if you do not have a react app in your workspace, then the nx preset will fallback to a default webpack config with minimal settings. (this is true of what plain cypress component testing does as well) you can optionally provide your own webpack config to apply any extra things youβd need to test.
i.e.
Now I personally wouldβt want to do this because writing webpack configs and keeping up with them is a pain.
So you can leverage the
nxComponentTestingPreset
for react. where this preset will use@nrwl/web:webpack
under the hood to make this config for you. but it needs a handful of options, so this is where it uses your another react app in the workspace, since itβll already have a βbuildβ configuration in place.To do this, just make a react app or create a @nrwl/web:webpack based target in the project youβre wanting, i.e. make an app and copy over the stuff.
nx g @nrwl/react:app ct
// or whatever you want to call it. doesnβt matter since itβs going to just be used for component testing.then tell the component testing target about it.
now the nx component testing preset will be able to create a more complete webpack config for component testing.