# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
  build:
    docker:
      - image: circleci/node:8.16-browsers
    
    environment:
      NODE_ENV: production
      JEST_JUNIT_OUTPUT_NAME: results.xml
    working_directory: ~/repo

    steps:
      - checkout

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

      - run: sudo npm install -g greenkeeper-lockfile
      - run: npm --production=false install
      - run: greenkeeper-lockfile-update

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package-lock.json" }}

      - run:
          name: Lint
          command: npm run test:lint -- --quiet --output-file test-results/eslint/results.xml --format junit
      
      - run:
          name: Unit
          environment:
              JEST_JUNIT_OUTPUT_DIR: test-results/unit
          command: npm run test:unit -- --reporters="default" --reporters="jest-junit" --coverage --coverageReporters=text --coverageReporters=lcov
      - store_artifacts:
          path: coverage
      
      - run:
          name: Build
          command: npm run build
      - store_artifacts:
          path: build
      
      - run:
          name: Integration
          environment:
              JEST_JUNIT_OUTPUT_DIR: test-results/integration
          command: npm run test:integration -- --reporters="default" --reporters="jest-junit"
      - store_test_results:
          path: test-results

      - run: greenkeeper-lockfile-upload
