version: 2

jobs:
  ci:
    docker:
      - image: cimg/node:lts
    steps:
      - checkout

      - restore_cache:
          keys:
            - node-v1-{{ checksum "package-lock.json" }}

      - run:
          name: Install dependencies
          command: npm ci

      - save_cache:
          key: node-v1-{{ checksum "package-lock.json" }}
          paths:
            - ~/.npm

      - run:
          name: Run linter
          command: npm run lint

      - run:
          name: Run tests
          command: npm run test

workflows:
  version: 2
  ci:
    jobs:
      - ci:
          filters:
            branches:
              only:
                - main
                - master
