version: 2.1

jobs:
  test:
    working_directory: ~/repo
    docker:
      - image: circleci/node:10.13.0
    steps:
      - checkout
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-
      - run:
          name: Create NPMRC
          command: echo $NPMRC > ~/repo/.npmrc
      - run:
          name: update npm
          command: sudo npm i npm@6.8.0 -g
      - run:
          name: NPM Install
          command: npm install
      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}
      - run:
          name: NPM Test
          command: npm test
workflows:
   version: 2.1
   test:
     jobs:
       - test:
           context: NPM