version: 2.1

commands:
  test-nodejs:
    steps:
      - run:
          name: Versions
          command: npm version
      - checkout
      - restore_cache:
          keys:
            - v{{ .Environment.CIRCLE_CACHE_VERSION }}-{{ arch }}-npm-cache-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}
            - v{{ .Environment.CIRCLE_CACHE_VERSION }}-{{ arch }}-npm-cache-master-{{ .Environment.CIRCLE_JOB }}
      - run:
          name: Install dependencies
          command: npm i
      - run:
          name: Test
          command: npm test
      - coverage
      - save-npm-cache
  save-npm-cache:
    steps:
      - save_cache:
          key: v{{ .Environment.CIRCLE_CACHE_VERSION }}-{{ arch }}-npm-cache-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package-lock.json" }}
          paths:
            - ~/.npm/_cacache
  coverage:
    steps:
      - run:
          command: npm run cover
      - run:
          command: npm run coveralls
jobs:
  node-v14:
    docker:
      - image: node:14
    steps:
      - test-nodejs
  node-v16:
    docker:
      - image: node:16
    steps:
      - test-nodejs
  node-v17:
    docker:
      - image: node:17
    steps:
      - test-nodejs

workflows:
  version: 2
  node-multi-build:
    jobs:
      - node-v14
      - node-v16
      - node-v17
