question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reuse or cache serve target across Cypress e2e projects with same devServerTarget

See original GitHub issue

Description

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

  1. Caching the serve target (not sure if this is currently possible) so subsequent serve actions are much faster
  2. Running the serve target before running each affected e2e suite with the same devServerTarget targeting that same serve target (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

  1. the dependency between serve and e2e run is no longer explicit
  2. 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 using start-server-and-test)
  3. start-server-and-test doesn’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:open
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
barbados-clemenscommented, Feb 18, 2022

This is an interesting idea that seems pretty valid. I’ll have to think about this and see what is/isn’t possible.

1reaction
barbados-clemenscommented, Oct 27, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ng e2e - Angular
Builds and serves an Angular application, then runs end-to-end tests. ... project. The name of the project to build. Can be an application...
Read more >
@nrwl/cypress:cypress | Nx
Run Cypress for e2e, integration and component testing. ... If devServerTarget is provided, the url returned from started the dev server will be...
Read more >
Migrating from Protractor to Cypress
What you'll learn Benefits of using Cypress in Angular apps How Cypress can create reliable e2e tests for Angular apps How to migrate...
Read more >
Workspace Settings - E2E Testing Configuration
devServerTarget and Cypress baseUrl. We need to set the devServerTarget for the production config of the e2e task for the corresponding e2e project....
Read more >
Notes of Best Practices for writing Cypress tests - Rule of Tech
Cypress is a nice tool for end-to-end tests and it has good documentation ... Add data-* attributes to make it easier to target...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found