How can I run Cypress tests from an external Gitlab repository?

I have two repositories each with their own pipleline:

  • Repo 1 - A ReactJS/Node project that runs a simple development server on localhost’s port 3000 and is started locally using npm start but I also have a Dockerfile for building this project to an image and my pipeline already builds & stores these images in my Gitlab Docker Registry.

  • Repo 2 - Some end-to-end Cypress tests intended to run against the React project in repo 1. The cypress tests expect to be able to find the React project running on localhost port 3000 for them to work.

My desired behaviour is that a push to the repo 1 (React) would trigger a job from repo 2 (Cypress) to run against the React server in repo 1.

What’s the best way to achieve this?

Presumably, I’d need corresponding stages defined in both pipelines and use multi-project downstream pipelines to define the triggers?

Is it possible to define a stage in repo 2 (Cypress) that can be “injected” into a stage in repo 1 (React) to effectively run against the server that I start up in repo 1?

Currently my Cypress stage in repo 2 is as follows:

cypress-test:
  image: cypress/browsers:latest
  stage: test
  script:
    # install dependencies
    - npm ci
    # start the server in the background
    - npm run start:ci & npx wait-on http://localhost:3000
    # run Cypress tests
    - npx cypress run
  artifacts:
    when: always
    paths:
      - cypress/videos/**/*.mp4
      - cypress/screenshots/**/*.png
    expire_in: 1 day

This previously worked when my Cypress tests sat in the same repository as my React code. However, this will now fail because I’m not sure how to start my React server if it’s sitting in an external repository.

My React stage in repo 2 simply needs to install the React dependencies and start the server on localhost:3000:

npm install 
npm start

I want to be able to install React’s dependencies and start the React server just before the run cypress tests line given two separate repositories/pipelines.