-
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
feat: Use JSX/TSX in generated spec filenames #25318
feat: Use JSX/TSX in generated spec filenames #25318
Conversation
Test summaryRun details
View run in Cypress Dashboard ➡️ Flakiness
This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
// If generating a component test then check whether there are JSX/TSX files present in the project. | ||
// If project uses JSX then user likely wants to use JSX for their tests as well. | ||
// JSX can be used (or not used) with a variety of frameworks depending on user preference/config, so | ||
// the only reliable way to determine is whether there are files with JSX extension present |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ultimately it would be nice to put the extension preference for generated tests in the component testing config or something so there is the ability to override this if needed 🤔. But I think this is a good rubric, especially for new people to get what they probably expect.
Testing more, but in a Vue project that use jsx for tests, I get a It's this project: https://github.com/marktnoonan/cy-validators-example/tree/what-component |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took me a few reads of everything to understand that the scope of this doesn't include "Create from Component" - so the Vue problems I reported are actually unrelated, I made a new issue here to track: #25346
// the only reliable way to determine is whether there are files with JSX extension present | ||
if (this.ctx.coreData.currentTestingType === 'component') { | ||
debug('Checking for jsx/tsx files to determine file extension for default spec filename') | ||
const projectJsxFiles = await this.ctx.file.getFilesByGlob(this.ctx.currentProject ?? '', '**/*.[jt]sx') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this check not be framework based? If it's react -> {fileExtensionToUse}x
else ${fileExtensionToUse}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to use JSX with React (albeit 99.9% of people do), and you can use JSX with non-React frameworks (like we do with our Vue tests). Doing a "is there already a JSX/TSX file present" seemed like the most reliable option, but I'll defer to the team
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to think through some edge-cases, like a user having some jsx
file for storybook but not wanting to have that pollute their generated Cypress tests if they don't plan on using jsx to write their CT tests. I think the proper solution is to have a more deterministic output like what framework they have and then, like @marktnoonan pointed out, having a user config override.
In the end this is just a suggestion for a filename and the user can change it if they want. I'm cool with this if this gets us closer, especially for react devs as that is our majority.
* develop: (45 commits) fix: re-enable CYPRESS_INTERNAL_VITE_DEV development (#25364) fix: add skip domain injection description (#25463) fix: revert CSP header and script-src addition (#25445) chore: Update v8 snapshot cache (#25401) feat: Do not strip CSP headers from HTTPResponse (#24760) fix: keep spaces in formatted output in test runner (#24687) fix: Restrict dependency versions to known supported ranges (#25380) chore: Update v8 snapshot cache (#25370) feat: experimental skip domain injection (#25307) chore: support vite v4 for component testing (#25365) feat: Use JSX/TSX in generated spec filenames (#25318) docs(angular): Properties that are spied upon have to be defined within `componentProperties` instead of on root level. (#25359) chore: remove lint-changed from scripts/docs (#25308) chore: bump to 12.3.0 [skip ci] (#25355) fix: make NODE_ENV "production" for prod builds of launchpad (#25320) fix: .contains() should only return one element at all times (#25250) feat: add currentRetry to Cypress API (#25297) chore: release @cypress/webpack-dev-server-v3.2.2 chore: release create-cypress-tests-v2.0.1 fix: change wording for spec creation (#25271) ...
User facing changelog
specPattern
has been configured to exclude files with those extensions.Additional details
Original writeup was specific to React which, while likely the largest use case for JSX, is not the only setup that can use JSX. It's also not necessary to use a JSX extension if using React (or other frameworks). For these reasons, I think the only reliable way to determine if we should use a JSX extension for the default spec filename is to check whether there are other existing files using that extension and it would not violate the project's configured specPattern to use it (so we don't generate "disappearing" spec files)
Steps to test
cy.js
(not JSX)cy.jsx
(CHANGED BEHAVIOR)typescript
dependency to the project and renamecypress.config.js
tocypress.config.ts
cy.tsx
(CHANGED BEHAVIOR)specPattern
to**/*.cy.js
cy.ts
(not TSX)How has the user experience changed?
PR Tasks
cypress-documentation
?type definitions
?