-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat: experimentalRunAllSpecs for component testing #32926
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
base: develop
Are you sure you want to change the base?
feat: experimentalRunAllSpecs for component testing #32926
Conversation
|
|
@scottohara I'll enable the tests to run, so keep an eye out on the results if anything needs updating. I'm not quite remembering the blocker for this originally and whether all those blockers are addressed here. It does seem like there should be more test coverage here somehow, but I'll see if someone from our team has ideas on that. |
| if (spec.relative === RUN_ALL_SPECS_KEY) { | ||
| const specsToCompile = ctx.project.runAllSpecs.map((relPath) => { | ||
| return ctx.project.specs.find((s) => s.relative === relPath) | ||
| }).filter(Boolean) as Cypress.Spec[] |
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.
Bug: Robustly Handle Undefined Data Collections
Calling .map() on ctx.project.runAllSpecs without checking if it's defined will throw a TypeError if runAllSpecs is undefined. The code should use (ctx.project.runAllSpecs || []) to safely handle the undefined case, similar to how it's handled in HtmlDataSource.ts line 123.
Additional details
This change extends the existing
experimentalRunAllSpecsconfig option to support component testing as well as e2e testing, allowing a full suite of component tests to be executed in the Cypress UI with a single click.By reusing most of the existing
experimentalRunAllSpecsmachinery, many of files touched by this PR are simply just to relax the previous restriction on it being for e2e testing only.With this PR,
experimentalRunAllSpecscan now be configured at either root level to enable it for both testing types:...or individually for each testing type:
Description of files changed
packages/app/src/store/run-all-specs-store.ts- removed checks on the testing type, allowing both e2e and componentpackages/config/src/options.ts- removes the option from thebreakingRootOptionsandtestingTypeBreakingOptionsarrays, allowing configuration at any levelpackages/data-context/schemas/schema.graphql- removed the now redundantEXPERIMENTAL_RUN_ALL_SPECS_E2E_ONLYenumpackages/errors/src/errors.ts- removed the now redundantEXPERIMENTAL_RUN_ALL_SPECS_E2E_ONLYerrorpackages/errors/test/visualSnapshotErrors.spec.ts- removes the now redundantEXPERIMENTAL_RUN_ALL_SPECS_E2E_ONLYerrorpackages/launchpad/cypress/e2e/config-warning.cy.ts- removed warnings relating to where the option config is allowedWith the above changes, the "Run [n] specs" buttons should now appear in the UI for component testing when the option is configured.
The next set of changes handle how the set of all specs is provided to either
webpack-dev-serverorvite-dev-server(depending on the bundler used).Starting with webpack:
packages/server/lib/socket-base.ts- was taught to handle theRUN_ALL_SPECS_KEY("__all"), and pass a set of specs to the CT dev server instead of a single specnpm/webpack-dev-server/src/loader.ts- was also taught to handle?specPath=__all, allowing all specs to be loadedVite was a bit tricker, and to be honest I'm not entirely happy with the implementation, so I would appreciate any feedback on a more robust and less hacky way to do this. For now:
packages/data-context/src/sources/HtmlDataSource.ts- sets a newwindow.__RUN_ALL_SPECS__property with the list of all specs to runnpm/vite-dev-server/client/initCypressTests.js- reads the above list of specs and adds each to the list of imports to load into the dev serverI'm not a regular Cypress contributor, so please do let me know if I have missed anything, if there are any additional tests needed for the above changes, or any improvements can be suggested.
Steps to test
cypress.config.(js|ts)withexperimentalRunAllSpecs: trueat either the root level or thecomponentlevelHow has the user experience changed?
PR Tasks
cypress-documentation?type definitions?Note
Enables
experimentalRunAllSpecsfor component testing, wiring Vite/Webpack and the runner to load/compile all specs and removing the prior e2e-only restriction and related errors.experimentalRunAllSpecsfor component (and e2e); permit config at root or per testing type. Updaterun-all-specsstore to not gate on testing type.client/initCypressTests.jsimports all specs whenspecPath="__all"usingwindow.__RUN_ALL_SPECS__; comprehensive tests added innpm/vite-dev-server/test/....src/loader.tsshouldLoad()recognizes?specPath=__all.socket-base.tscompiles multiple specs when receivingRUN_ALL_SPECS_KEY.window.__RUN_ALL_SPECS__inHtmlDataSource.experimentalRunAllSpecsinpackages/config/src/options.ts.EXPERIMENTAL_RUN_ALL_SPECS_E2E_ONLYenum and error; remove related tests and launchpad warnings.cli/CHANGELOG.mdto announce CT support forexperimentalRunAllSpecs.Written by Cursor Bugbot for commit 458f3cf. This will update automatically on new commits. Configure here.