version: 2
jobs:
  build:
    working_directory: ~/Streampunk/beamcoder
    parallelism: 1
    shell: /bin/bash --login
    environment:
      CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
      CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
      UV_THREADPOOL_SIZE: 16
    docker:
    - image: streampunkmedia/testbeam:16-5.0
    steps:
    - checkout
    - run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
    - restore_cache:
        keys:
        # This branch if available
        - v2-dep-{{ .Branch }}-
        # Default branch if not
        - v2-dep-master-
        # Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly
        - v2-dep-
    - run: npm install tap-xunit
    - run: npm install --unsafe-perm
    - save_cache:
        key: v2-dep-{{ .Branch }}-{{ epoch }}
        paths:
        - ./node_modules
    - run: echo 'export PATH="~/Streampunk/beamcoder/node_modules/.bin:$PATH"' >> $BASH_ENV
    - run: mkdir -p $CIRCLE_TEST_REPORTS/eslint
    - run: mkdir -p $CIRCLE_TEST_REPORTS/xunit
    - run: eslint '**/*.js' -f junit -o /tmp/circleci-test-results/eslint/eslint.xml
    - run: set -eo pipefail && npm test | tap-xunit > /tmp/circleci-test-results/xunit/results.xml
      
    - store_test_results:
        path: /tmp/circleci-test-results
    - store_artifacts:
        path: /tmp/circleci-artifacts
    - store_artifacts:
        path: /tmp/circleci-test-results
