version: 2
jobs:
  test:
    docker:
      - image: circleci/node:14.15.0

    working_directory: ~/repo

    steps:
      - checkout

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

      - run: yarn

      - save_cache:
          paths:
            - node_modules
          key: v2-dependencies-{{ checksum "package.json" }}

      - run: yarn run lint
      - run: yarn test -w 1 --coverage
      - run: bash <(curl -s https://codecov.io/bash)

  build:
    docker:
      - image: circleci/node:14.15.0

    working_directory: ~/repo

    steps:
      - checkout

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

      - run: yarn

      - save_cache:
          paths:
            - node_modules
          key: v2-dependencies-{{ checksum "package.json" }}

      - run: yarn run build
workflows:
  version: 2
  build_and_test:
    jobs:
      - test
      - build
