version: 2

defaults: &defaults
  working_directory: ~/project
  docker:
    - image: circleci/node:10.15.1

jobs:
  tests:
    <<: *defaults

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
            - v1-npmdeps-{{ checksum "package.json" }}
            # fallback to using the latest cache if no exact match is found
            - v1-npmdeps-

      # - run: nix-shell --run 'npm install'
      - run: npm install

      - save_cache:
          paths:
            - node_modules
          key: v1-npmdeps-{{ checksum "package.json" }}
      
      - persist_to_workspace:
          # Must be an absolute path, or relative path from working_directory. This is a directory on the container which is 
          # taken to be the root directory of the workspace.
          root: .
          # Must be relative path from root
          paths:
            - node_modules

      - run: npm test

workflows:
  version: 2
  
  ubuntu:
    jobs:
      - tests