version: 2
jobs:
  build:
    working_directory: ~/tiny-donuts
    docker:
      - image: circleci/node:10
    steps:
      - checkout
      - restore_cache:
          key: dependency-cache-{{ checksum "package.json" }}
      - run:
          name: install-npm
          command: npm ci
      - save_cache:
          key: dependency-cache-{{ checksum "package.json" }}
          paths:
            - ./node_modules
      - run:
          name: ensure reports directory
          command: mkdir ./reports
      - run:
          name: test
          command: ./node_modules/.bin/mocha --reporter mocha-junit-reporter -r ts-node/register tests/*.spec.ts
          environment:
            MOCHA_FILE: ./reports/test-results.xml
            TS_NODE_COMPILER_OPTIONS: '{"module":"commonjs"}'
          when: always
      - run:
          name: lint
          command: ./node_modules/.bin/tslint -p tsconfig.json --format junit --out ./reports/tslint.xml
          when: always
      - store_artifacts:
          path: ./reports/test-results.xml
      - store_artifacts:
          path: ./reports/tslint.xml
      - store_test_results:
          path: ./reports/