# Docker images provided by https://github.com/cypress-io/cypress-docker-images
# this example mostly follows the GitLab example in
# https://github.com/cypress-io/cypress-example-kitchensink

# first, install Cypress, then run all tests (in parallel)
stages:
  - build
  - test

# to cache both npm modules and Cypress binary we use environment variables
# to point at the folders we can list as paths in "cache" job settings
variables:
  npm_config_cache: "$CI_PROJECT_DIR/.npm"
  CYPRESS_CACHE_FOLDER: "$CI_PROJECT_DIR/cache/Cypress"

# cache using branch name
# https://gitlab.com/help/ci/caching/index.md
cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .npm
    - cache/Cypress
    - node_modules

# this job installs NPM dependencies and Cypress
install:
  image: cypress/browsers:latest
  stage: build

  script:
    - npm ci
    # show where the Cypress test runner binaries are cached
    - $(npm bin)/cypress cache path
    # show all installed versions of Cypress binary
    - $(npm bin)/cypress cache list
    - $(npm bin)/cypress verify

# two jobs that run after "install" job finishes
# NPM dependencies and Cypress binary should be already installed

cypress-e2e-chrome:
  image: cypress/browsers:latest
  stage: test
  before_script:
    - npm install
    - ./start.sh
  script:
    - $(npm bin)/cypress run --browser chrome
  after_script:
    - pkill -9 node
  artifacts:
    expire_in: 1 week
    when: always
    paths:
    - cypress/screenshots
    - cypress/videos
    reports:
      junit:
        - results/TEST-*.xml
