首页 > 解决方案 > How can I run Fullstack E2E Tests in CI (Gitlab)

问题描述

I have a webapp consisting of - A frontend repository (Angular 8) - A backend repository (Node.js/NestJS 6)

I use Gitlab as SCM provider, docker registry and CI/CD tool. Installing, linting, testing (unit) and building already works with CI.

Now I want to introduce E2E tests which I added within the frontend repository using Cypress.

For the tests to work, I need to - run the backend (using docker-compose) including a S3 mock and the DB (mongo) - insert demo data to the backend (got a script for that) - run the frontend pointing to the backend API - run the cypress tests

The question that I have is: How can I run the dockerized backend including dependencies within the CI stage so that I have a backend instance to run the e2e tests aginst?

I already tried running the backend via docker-compose within the stage. This lead to the containers getting started but they were not accessible from within the gitlab-runner container.

This is a stage within the frontend repo .gitlab-ci.yml:

e2e:
  image: docker:stable
  stage: e2e
  script:
    - apk add --no-cache py-pip python-dev libffi-dev openssl-dev gcc libc-dev make nodejs npm git curl
    - pip install docker-compose
    - npm install -g wait-on spa-http-server forever
    - docker-compose up -d
    - wait-on http://localhost:4000/api/ && curl -X POST http://localhost:4000/global/createDemoData
    - npm run build
    - forever start -c http-server dist/XXX/ -p 4200 --push-state
    - wait-on http://localhost:4200 && npm run e2e-ci
    - forever stopall
    - docker-compose down

标签: continuous-integrationgitlab-cie2e-testinggitlab-ci-runner

解决方案


推荐阅读