version: 2
jobs:
  build:
    docker:
      - image: circleci/node:14.18.2

    working_directory: ~/repo

    steps:
      - checkout

      - restore_cache:
          keys:
            - yarn-node-modules-v1-{{ checksum "yarn.lock" }}

      - run:
          name: Install npm packages
          command: yarn install --frozen-lockfile --cache-folder ~/.cache/yarn

      - save_cache:
          name: Save Yarn Package Cache
          key: yarn-node-modules-v1-{{ checksum "yarn.lock" }}
          paths:
            - ~/.cache/yarn

      # run tests!
      - run:
          name: Run tests
          command: yarn test:ci

      - run:
          name: Upload code coverage report
          command: ./node_modules/.bin/codecov
