feat: experimentalRunAllSpecs for component testing #32926
+302
−90
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Extends
experimentalRunAllSpecsto Component Testing and wires Vite/Webpack dev servers and the app to load/run all specs via__all.experimentalRunAllSpecsfor CT (no longer e2e-only) and enable UI “Run [n] specs” in CT (run-all-specs-store.ts).specPath=__alland import all specs fromwindow.__RUN_ALL_SPECS__(initCypressTests.js), with comprehensive tests.shouldLoadnow treats__allas load-all (loader.ts).RUN_ALL_SPECS_KEY, compile/update dev server with the full spec set (socket-base.ts).window.__RUN_ALL_SPECS__alongside__RUN_MODE_SPECS__in served HTML (HtmlDataSource.ts).options.ts,schema.graphql,errors.ts, visual error tests, launchpad config warnings cleanup).experimentalRunAllSpecsfor Component Testing.Written by Cursor Bugbot for commit 490dd67. This will update automatically on new commits. Configure here.