# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/node:12.0
      
      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/mongo:3.4.4

    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v4-dependencies-{{ checksum "package-lock.json" }}

      - run:
          name: "install puppeteer dependencies"
          command: |
            sudo apt-get update && \
            sudo apt-get install -yq libasound2 libatk1.0-0 libcairo2 libcups2 \
            libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
            libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
            libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \
            ca-certificates libnss3 lsb-release xdg-utils

      - run:
          name: "install node modules"
          command: |
            [[ -d node_modules ]] || npm ci

      - save_cache:
          paths:
            - node_modules
          key: v4-dependencies-{{ checksum "package-lock.json" }}
        
      # run tests!
      - run: npm test
