Run cypress tests in github actions, running up front-end and back-end http servers.

Hi, i would like to run cypress tests on my Vue project linked to cypress dashboard in Github actions, triggered on push or pull events.
To test my application, wich is written on NodeJS at the backend and Vue in the frontend, i have to run both https server in the github workflow. 
I am using cypress-io/github-action and it worked fine without running the backend server. This was my configuration:

name: End-to-end tests
on: [push]
jobs:
  cypress-run:
    runs-on: windows-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v1

      - name: Cypress run
        uses: cypress-io/github-action@v1
        with:
          record: true
          start: npm run serve --prefix frontend/app
          wait-on: http://localhost:8080
        env:
          CYPRESS_RECORD_KEY: <key>

Now the goal is to have also a running server using:

npm run start # --> node index.js

 So that i can get backend api listening on localhost:8000 (and vue in dev mode is refering to).

But i can not get that to work. I have tried various configuration like this: 

name: End-to-end tests
on: [push]
jobs:
  cypress-run:
    runs-on: windows-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v1

      - name: Run backend
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
          run: npm run start

      - name: Cypress run
        uses: cypress-io/github-action@v1
        with:
          record: true
          start: npm run serve --prefix frontend/nix-app
          wait-on: http://localhost:8080
        env:
          # pass the Dashboard record key as an environment variable
          CYPRESS_RECORD_KEY: <key>

The backend server runs correctly on port 8000, but then the workflow is stuck there! It doesn’t continue on Cypress run because, i guess, it’s waiting the end of the process.
How can i force to go at the next step after the first server is set up?

Another solution that i have tried is to use two different jobs in parallel, but also this is not working because the two servers will not stop running. Then what if cypress tests run before the two servers are up?

Can you suggest something else? Thank you!

Hi @alessandroamedei , 

To run a node.js app as a background service, you can start the Node JS server with nohup command as below.

nobup node index.js

 Have you tried this method? 

If this could not work, It would be great if you could share a sample project here for me to investigate further. 

1 Like

Hi @yanjingzhu , thank you for the answer.

Now i have this:

name: End-to-end tests
on: [push]
jobs:
  cypress-run:
    runs-on: windows-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v1

      - name: Set up node
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: Run backend nohup
        run: nohup node backend/index.js

      - name: Cypress run
        uses: cypress-io/github-action@v1
        with:
          record: true
          start: npm run serve --prefix frontend/nix-app
          wait-on: http://localhost:8080
        env:
          # pass the Dashboard record key as an environment variable
          CYPRESS_RECORD_KEY: <key>

I am using two steps, i am doing :

nohup node backend/index.js

But it is not working:

It is still stuck.

The & symbol at the end of a command in bash will run the command in the background. 

I tested it in powershell core on windows-latest runner, it could also work.

Please try to add & at the end of the command which you want to run in backgroud . 

Did you run the background process successfully? Did you meet the this situation. At the last step, a job named Complete Job will clean up the orphan process. And this step will clean up the backgroup process unfortunately. I don’t know how do deal with this.