version: 2

jobs:
  build:
    docker:
      - image: cypress/browsers:chrome67
        environment:
          TERM: xterm

    working_directory: ~/root

    steps:
      - checkout

      - restore_cache:
          keys:
            - v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }}
            - v1-dependencies-{{ .Branch }}
            - v1-dependencies

      - run:
          name: Checking node version
          command: |
            node --version
            npm --version

      - run:
          name: Installing dependencies
          command: npm ci

      - save_cache:
          key: v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }}
          paths:
            - ~/.npm
            - ~/.cache

      - run:
          name: Building the package
          command: npm run build

      - run:
          name: Running unit tests
          command: npm run test:unit

      - run:
          name: Running integration tests
          command: npm run test:e2e
