defaults: &defaults
  working_directory: ~/repo
  environment: 
    - TERM: xterm
    - YARN_VERSION: 1.4.0
    - NODE_VERSION: 8.9.4

  docker:
    - image: circleci/node:8.9.4

version: 2

jobs:
  build: 
    <<: *defaults

    working_directory: ~/repo

    steps:
      - checkout
      - attach_workspace:
          at: ~/repo

      - run:
          name: Install node deps
          command: yarn install --network-concurrency 1

      - persist_to_workspace:
          root: .
          paths:
            - node_modules
            - src

  test: 
    <<: *defaults

    working_directory: ~/repo

    steps:
      - checkout
      - attach_workspace:
          at: ~/repo
      - run: yarn test

workflows:
  version: 2
  build_and_test_and_deploy:
    jobs:
      - build

      - test:
          requires:
            - build