Reuse or cache serve target across Cypress e2e projects with same devServerTarget
See original GitHub issueDescription
Say I have two Cypress e2e projects, myapp-feature-A-e2e and myapp-feature-B-e2e, which test two parts of a single app, myapp. myapp-feature-A-e2e and myapp-feature-B-e2e both have the same devServerTarget of myapp:serve:e2e. These projects are split for a performance improvement with affected, and we have implicit dependencies from myapp-feature-A-e2e to feature-A-lib and from myapp-feature-B-e2e to feature-B-lib.
When both myapp-feature-A-e2e and myapp-feature-B-e2e target the same devServerTarget, they both do a full run of myapp:serve:e2e, which adds a performance overhead (in our case it’s ~30 seconds). As the number of e2e prjects grows, so does the overhead for re-serving the myapp:serve:e2e.
It would be really helpful if e2e projects targeting the same devServerTarget could reuse that serve target without a full rebuild occurring.
Motivation
For improved local development experience (and for teams that can’t distribute e2e across multiple runners in CI), the performance improvements of reusing the same serve target would be a big boost to e2e testing speed, especially as the application grows.
Suggested Implementation
Implementation options might include
- Caching the
servetarget (not sure if this is currently possible) so subsequentserveactions are much faster - Running the
servetarget before running eachaffectede2e suite with the samedevServerTargettargeting that sameservetarget (would need to handle stopping the serve after all of these e2e projects are done)
Alternate Implementations
I’m not sure if incremental builds are a suitable solution here (slightly larger startup time for first e2e serve but much faster after that)
Somewhat related requests I’ve found before: https://github.com/nrwl/nx/issues/1604 https://github.com/nrwl/nx/issues/3748
Our current workaround is following this suggestion (https://github.com/nrwl/nx/issues/3748#issuecomment-791278929) and using start-server-and-test package to run the app before executing all e2e. The reasons this implementation is less than ideal are
- the dependency between serve and e2e run is no longer explicit
- more cumbersome handling e2e with different targets (before it’s as easy as a configuration with
"skipServe": true, now it’s a separate command for running e2e against a local target usingstart-server-and-test) start-server-and-testdoesn’t support chaining arguments to the test command (https://github.com/bahmutov/start-server-and-test/issues/267), so we’ve had to add custom scripts to allow chaining arguments and it’s hard to maintain
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)

Top Related StackOverflow Question
This is an interesting idea that seems pretty valid. I’ll have to think about this and see what is/isn’t possible.
so serve will never be able to be a cacheable target since it technically never ends. instead you should serve the build files like with @nrwl/web:file-server for static FE apps. then the build should be cacheable and make it quicker to startup/less resource intensive.