---
version: 2
jobs:
  "node-6":
    docker:
      - image: circleci/node:6
    steps:
      - checkout
      - restore_cache:
          keys:
            - dependency-cache-{{ checksum "package.json" }}
            # fallback to the latest cache if no match is found
            - v1-dependencies-
      - run:
          name: install-npm
          command: npm install
      - save_cache:
          key: v1-dependencies-{{ checksum "package.json" }}
          paths:
            - node_modules
      - run:
          name: test
          command: npm test
  "node-8":
    docker:
      - image: circleci/node:8
    steps:
      - checkout
      - restore_cache:
          keys:
            - dependency-cache-{{ checksum "package.json" }}
            # fallback to the latest cache if no match is found
            - v1-dependencies-
      - run:
          name: install-npm
          command: npm install
      - save_cache:
          key: v1-dependencies-{{ checksum "package.json" }}
          paths:
            - node_modules
      - run:
          name: test
          command: npm test

workflows:
  version: 2
  build:
    jobs:
      - "node-6"
      - "node-8"

---
version: 2

buildSteps: &buildSteps
  - checkout
  - restore_cache:
      keys:
        - dependency-cache-{{ checksum "package.json" }}
        # fallback to the latest cache if no match is found
        - dependency-cache-
  - run:
      name: install-npm
      command: npm install
  - save_cache:
      key: dependency-cache-{{ checksum "package.json" }}
      paths:
        - node_modules
  - run:
      name: test
      command: npm test

jobs:
  "node-6":
    docker:
      - image: circleci/node:6
    steps: *buildSteps
  "node-8":
    docker:
      - image: circleci/node:8
    steps: *buildSteps

workflows:
  version: 2
  build:
    jobs:
      - "node-6"
      - "node-8"

Refactor out duplicated build steps
Refactor out duplicated build steps
