version: 2.1

defaults: &defaults
  working_directory: ~/project/vue
  docker:
    - image: circleci/node:lts-browsers

aliases:
  - &restore-yarn-cache
    key: v2-vue-cli-{{ checksum "yarn.lock" }}

  - &save-yarn-cache
    key: v2-vue-cli-{{ checksum "yarn.lock" }}
    paths:
      - node_modules/
      - ~/.cache

workflow_filters: &filters
  filters:
    branches:
      ignore:
      - docs

jobs:
  install:
    <<: *defaults
    steps:
      - checkout
      - restore_cache: *restore-yarn-cache
      - run: yarn --network-timeout 600000
      - save_cache: *save-yarn-cache
      - persist_to_workspace:
          root: ~/
          paths:
            - project/vue
            - .cache/Cypress

  e2e:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/
      - run: ./scripts/e2e-test/run-e2e-test.sh

  core:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/
      - run: yarn test -p cli,cli-service,cli-shared-utils

  typescript:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/
      - run: yarn test 'ts(?:\w(?!E2e))+\.spec\.js$'

  plugins:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/
      - run: yarn lint-without-fix
      - run: yarn check-links
      - run: yarn test -p eslint,pwa,babel,babel-preset-app,vuex,router

  tests:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/
      - run: yarn test -p unit-mocha,unit-jest,e2e-cypress
      # e2e-nightwatch was left out due to some unknown issues with selenium and the CI image
      - run: yarn test tsPluginE2e

  cli-ui:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/
      - run: cd packages/@vue/cli-ui && yarn test
      - store_artifacts:
          path: packages/@vue/cli-ui/tests/e2e/videos
      - store_artifacts:
          path: packages/@vue/cli-ui/tests/e2e/screenshots
      - store_artifacts:
          path: /home/circleci/.npm/_logs

workflows:
  version: 2
  test:
    jobs:
      - install:
          <<: *filters
      - core:
          <<: *filters
          requires:
            - install
      - typescript:
          <<: *filters
          requires:
            - install
      - plugins:
          <<: *filters
          requires:
            - install
      - tests:
          <<: *filters
          requires:
            - install
      - cli-ui:
          <<: *filters
          requires:
            - install
      - e2e:
          <<: *filters
          requires:
            - install
