version: 2.1

workflows:
  build:
    jobs:
      - build

jobs:
  build:
    docker:
      - image: cimg/node:16.19.0   # Primary execution image
    steps:
      - checkout
      - run:
          name: Update npm
          command: 'sudo npm install -g npm@8.19.3'
      - restore_cache:
          key: dependency-cache-{{ checksum "package-lock.json" }}
      - run:
          name: Install npm
          command: npm install
      - save_cache:
          key: dependency-cache-{{ checksum "package-lock.json" }}
          paths:
            - ./node_modules
      - run:
          name: Unit test
          command: npm test
      - run:
          name: Code Coverage
          command: './node_modules/.bin/nyc report --reporter=text-lcov'
      - store_artifacts:
          path: coverage
          prefix: coverage