-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 component testing - multiple issues #11372
Comments
I tried it with vite - it has a minimum setup and includes everything the test need. import { defineConfig, searchForWorkspaceRoot } from 'vite'
import react from '@vitejs/plugin-react'
import tsconfigPaths from 'vite-tsconfig-paths'
import svgr from 'vite-plugin-svgr'
import { join } from 'path'
import { defaultConfig } from '@tools/webpack/svg'
export default defineConfig({
plugins: [
react(),
tsconfigPaths({
root: join(__dirname, '../../')
}),
svgr({
svgrOptions: defaultConfig
})
],
server: {
fs: {
allow: [searchForWorkspaceRoot(process.cwd())]
}
}
}) Cypress: import { defineConfig } from 'cypress'
export default defineConfig({
component: {
devServer: {
framework: 'react',
bundler: 'vite'
}
}
}) component-index.html <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Cypress</title>
</head>
<body>
<div data-cy-root></div>
<script type="module">
import RefreshRuntime from "/@react-refresh"
RefreshRuntime.injectIntoGlobalHook(window)
window.$RefreshReg$ = () => {}
window.$RefreshSig$ = () => (type) => type
window.__vite_plugin_react_preamble_installed__ = true
</script>
</body>
</html> |
does this only happen when all four packages are added? |
It also happens for each one independently. |
@danr-za working on a fix for this now. got a PoC working levering Button.cy.tsx.mp4yarn nx component-test ui
yarn run v1.22.15
$ /Users/caleb/Work/danr-za/cypress-ct-nx/node_modules/.bin/nx component-test ui
> nx run ui:component-test
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://127.0.0.1:8080/
<i> [webpack-dev-server] Content not from webpack is served from '/Users/caleb/Work/danr-za/cypress-ct-nx/libs/ui/public' directory
=============================================================================
(Run Starting)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 10.3.1 │
│ Browser: Electron 100 (headless) │
│ Node Version: v16.15.0 (/Users/caleb/.nvm/versions/node/v16.15.0/bin/node) │
│ Specs: 1 found (Button.cy.tsx) │
│ Searched: **/*.cy.{js,jsx,ts,tsx} │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Button.cy.tsx (1 of 1)
chunk (runtime: main) cypress_support_component_ts.js 1.67 KiB [rendered]
chunk (runtime: main) main.js (main) (id hint: vendors) 156 KiB (javascript) 7.62 KiB (runtime) [entry] [rendered] reused as split chunk (cache group: defaultVendors)
chunk (runtime: main) spec-0.js (spec-0) 12.7 KiB [rendered]
chunk (runtime: main) vendors-node_modules_core-js_modules_es_object_assign_js-node_modules_react_jsx-runtime_js-no-9ce0a5.js (id hint: vendors) 83.3 KiB [rendered] split chunk (cache group: defaultVendors)
chunk (runtime: main) vendors-node_modules_react_index_js.js (id hint: vendors) 85.7 KiB [rendered] split chunk (cache group: defaultVendors)
chunk (runtime: main) vendors-node_modules_testing-library_cypress_add-commands_js-node_modules_cypress_react_dist_-16a054.js (id hint: vendors) 1.35 MiB [rendered] split chunk (cache group: defaultVendors)
webpack compiled successfully (a176b76fae95a61f)
Type-checking in progress...
No errors found.
Button
✓ should render (555ms)
1 passing (581ms)
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: 0 seconds │
│ Spec Ran: Button.cy.tsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /Users/caleb/Work/danr-za/cypress-ct-nx/dist/cypress/libs/u (0 seconds)
i/videos/Button.cy.tsx.mp4
=============================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ Button.cy.tsx 577ms 1 1 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! 577ms 1 1 - - -
———————————————————————————————————————————————————————————————————————————
> NX Successfully ran target component-test for project ui (7s)
✨ Done in 7.07s. |
…ebpack config fixes: nrwl#11372
I think it might be also a good time for nx to start integrating vite in 😉 |
…ebpack config fixes: nrwl#11372
…ebpack config fixes: nrwl#11372
…ebpack config fixes: nrwl#11372
…ebpack config fixes: nrwl#11372
…ebpack config fixes: nrwl#11372
…ebpack config fixes: nrwl#11372
…ebpack config fixes: nrwl#11372
…ebpack config fixes: nrwl#11372
…ebpack config fixes: nrwl#11372
…ebpack config fixes: nrwl#11372
…ebpack config fixes: nrwl#11372
@barbados-clemens forgive my ignorance, but could you provide a code example of the solution that you tested? I am relatively green to nx and the migration to 14.6.2 did not work for me. I am struggling with the same thing as OP except I am working in a component package library where we are exporting pure react components with no react app. It's possible I am missing additional configuration, but right now its just running on
|
@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) i.e. export default defineConfig({
component: {
devServer: {
framework: 'react',
bundler: 'webpack',
webpackConfig: // your custom webpack config
}
}
}) 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 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.
then tell the component testing target about it. "component-test": {
"options": {
"cypressConfig": "packages/form/cypress.config.ts",
"testingType": "component",
"devServerTarget": "some-project:some-target-using-nrwl/web:webpack",
"skipServe": true // very important so you don't build the project
}
} now the nx component testing preset will be able to create a more complete webpack config for component testing. |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
The following currently seems to not be supported in the component testing configuration preset when running
nx g @nrwl/react:cypress-component-configuration
:@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
styles.css
file that imports tailwind stuff (base, components & utils)nx g @nrwl/react:cypress-component-configuration
with the relevant libimport @testing-library/cypress/add-commands
tocomponent.ts
import '../../src/styles.css
tocomponent.ts
nx component-test --watch
Result:
exports is not defined
Here's a repo with the reproduction - https://github.com/danr-za/cypress-ct-nx
Failure Logs
Environment
The text was updated successfully, but these errors were encountered: