version: 2

references:
  test-steps: &test-steps
    - checkout
    - restore_cache:
        keys:
          - v2-dependencies-{{ .Environment.CIRCLE_JOB }}-{{ arch }}-{{ checksum "package.json" }}
    - run: npm install
    - run: npm run build
    - run: npm run ${BUILDTARGET}
    - run: npm run ${TESTTARGET}
    - save_cache:
        key: v2-dependencies-{{ .Environment.CIRCLE_JOB }}-{{ arch }}-{{ checksum "package.json" }}
        paths:
          - node_modules

jobs:
  unittest-node8:
    docker:
      - image: circleci/node:8-browsers
    steps: *test-steps
    environment:
      BUILDTARGET: build:unittests
      TESTTARGET: test:unit
  unittest-node10:
    docker:
      - image: circleci/node:10-browsers
    steps: *test-steps
    environment:
      BUILDTARGET: build:unittests
      TESTTARGET: test:unit
  uitest-firefox:
    docker:
      - image: circleci/node:10-browsers
    steps: *test-steps
    environment:
      BUILDTARGET: build:uitests
      TESTTARGET: test:ui firefox
  uitest-chrome:
    docker:
      - image: circleci/node:10-browsers
    steps: *test-steps
    environment:
      BUILDTARGET: build:uitests
      TESTTARGET: test:ui chrome
  lint:
    docker:
      - image: circleci/node:8-browsers
    steps:
      - checkout
      - restore_cache:
          keys:
            - v2-dependencies-test-node8-{{ arch }}-{{ checksum "package.json" }}
      - run: npm install
      - run: npm run lint

workflows:
  version: 2
  build:
    jobs:
      - unittest-node8
      - unittest-node10
      - uitest-firefox
      - uitest-chrome
      - lint
