nx: E2E tests can't be ran in parallel

Expected Behavior

E2E tests can be ran in parallel.

Current Behavior

E2E tests can’t be ran in parallel. Different errors are thrown based on the test runner.

Cypress:

Screen Shot 2019-07-20 at 4 23 32 PM

Protractor:

Screen Shot 2019-07-20 at 4 28 24 PM

Steps to Reproduce

  1. Generate a Nx workspace
  2. Generate either two Cypress or two Protractor projects
  3. npm run affected:e2e -- --all --parallel

Context

  • version of Nx used 8.2.0

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 22 (4 by maintainers)

Most upvoted comments

Any news about this ?
I have the issue.

Without having looked at it, this may work though as it is right now. nx affected:e2e --parallel --maxParallel=2 -- --parallel where the second --parallel gets passed along to the individual cypress run for the affected application.

I can verify that this approach (adding -- --parallel) fixes our problems with the --parallel flag being eaten by nx, and not passed to cypress.

Have spent quite some time trying to get E2E tests running in parallel using Cypress Dashboard.

It works for single project target, splitting specs over multiple machines, but anything taking more projects such as affected:e2e fails either due to port in use, discrepancy in the capabilities (browser, version specs) sent to Cypress, group being closed or some issue with ngcc.

Wonder if the --parallel flag should be removed from the e2e target until it is ready - otherwise at least some improvement of the docs would be nice to be clear exactly when and how it can be used.

This is interesting because of the way the --parallel flag works.

It essentially creates new processes and lets them do their thing. It has no way of knowing the context of the process that should be spawned. In the case of Cypress (or anything else that could potentially spin up a server that listens on a port), all processes try to get access to the same port.

We could potentially make the cypress builder a bit smarter and check to see if the port is available before starting it. 🤔

We would like to run multiple Cypress instances simultaneously on our CI environment to test different applications in the Nx workspace in parallel. But as described above, it fails when launching multiple as the port is already in use:

PS C:\MyApp> npx nx e2e myapp-e2e --headless

> ng run myapp-e2e:e2e --headless
Port 4200 is already in use. Use '--port' to specify a different port.

It says to specify a different port, but I don’t get it to work:

PS C:\MyApp> npx nx e2e myapp-e2e --headless --port=0

> ng run myapp-e2e:e2e --headless --port=0 
Unknown option: '--port'

Is there any way to do this?

Just adding the piece of info that Cypress (with a paid plan) supports parallelization via the same --parallel flag, so a way to differentiate between the two may be necessary.
Without having looked at it, this may work though as it is right now. nx affected:e2e --parallel --maxParallel=2 -- --parallel where the second --parallel gets passed along to the individual cypress run for the affected application. Cypress docs

semi-related #8286

for now, cypress doesn’t know what ports are/aren’t available as @Cammisuli this might be something we can make the cypress executor look into. the safest way to prevent this is going to be running nx with --parallel=1 to prevent the processes from reaching for the same port. or to change the port in which the apps are served on in each project being used in cypress

as others have mentioned you can pass the -- --parallel flag to get that flag to cypress if needed. closing for now.

I also had issues with this. I was able to use “dash dash” to pass parallel as params. My full command to running parallelized tests in gitlab CI is below.

 nx e2e mhvillage-e2e --record --key "${CYPRESS_DASHBOARD_TEST_SUITE_KEY}"  --ci-build-id "e2e-${CI_PIPELINE_ID}" -- --parallel

In my situation…In order to get parallel tests to work, I also had to pass the --ci-build-id by hand. It seems that NX is not allowing cypress to determine this automatically as discussed here:

I would also like to run cypress e2e in parallel but adding following command

yarn affected:e2e --base=origin/master --head=HEAD --browser chrome --record --parallel --ci-build-id $BUILD_BUILDNUMBER --group "Azure CI"

The result is following:

Unknown option: '--ci-build-id'
Unknown option: '--ciBuildId'
Unknown option: '--group'
Unknown option: 'CI'
error Command failed with exit code 1.```

In AzureDevops