# see https://circleci.com/docs/2.0/language-javascript/

version: 2
jobs:
  build:
    docker:
      - image: circleci/node:8-browsers

    working_directory: ~/md-to-pdf

    steps:
      - checkout

      - restore_cache:
          keys:
            - dependency-cache-{{ checksum "package.json" }}
            - dependency-cache- # fall back to latest

      - run: npm install

      - save_cache:
          paths:
            - node_modules
          key: dependency-cache-{{ checksum "package.json" }}

      - run:
          name: make test-results dirs
          command: mkdir -p ~/test-results/xo ~/test-results/ava

      - run:
          name: lint
          command: npx xo --reporter junit > ~/test-results/xo/results.xml

      - run:
          name: test lib
          command: npx nyc --reporter=lcov ava test/lib.spec.js --tap | npx tap-xunit > ~/test-results/ava/results.xml

      - run:
          name: test api
          command: npx ava test/api.spec.js

      - run:
          name: test cli
          command: npx ava test/cli.spec.js

      - store_test_results:
          path: ~/test-results

      - store_artifacts:
          path: coverage/lcov-report
          destination: nyc-report
