# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: ci push

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
          cache: npm
      - run: npm ci
      - run: npm test
      - uses: dorny/test-reporter@v1
        with:
          reporter: 'jest-junit'
          name: 'Jest tests results'
          path: 'jest-report/jest-junit.xml'
      - uses: actions/upload-artifact@v3
        with:
          name: jest-report
          path: jest-report
          if-no-files-found: ignore
      - uses: codecov/codecov-action@v3
  cypress-interceptor:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
          cache: npm
      - run: npm ci
      - name: Cypress interceptor run
        uses: cypress-io/github-action@v5
        with:
          start: npm run start:complete-interceptor-example
          wait-on: 'http://localhost:4200'
          wait-on-timeout: 180
          install: false
      - uses: actions/upload-artifact@v3
        if: failure()
        with:
          name: cypress-screenshots
          path: cypress/screenshots
          if-no-files-found: warn
  cypress-instrumentation:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
          cache: npm
      - run: npm ci
      - name: Cypress instrumentation run
        uses: cypress-io/github-action@v5
        with:
          start: npm run start:complete-instrumentation-example
          wait-on: 'http://localhost:4200'
          wait-on-timeout: 180
          install: false
      - uses: actions/upload-artifact@v3
        if: failure()
        with:
          name: cypress-screenshots
          path: cypress/screenshots
          if-no-files-found: warn
