---
version: '3'

tasks:
  all:
    cmds:
      - task: :npm:build:all
      - task: :npm:test:unit
      - task: report

  check:
    deps:
      - :install:modules:local
      - :install:npm:nyc
    log:
      error: Errors encountered while running `nyc report` and `nyc check-coverage`
      start: Running `nyc report` and `nyc check-coverage`
      success: Finished running `nyc`
    cmds:
      - '{{.NPX_HANDLE}}nyc report'
      - '{{.NPX_HANDLE}}nyc check-coverage --lines 100 --functions 100 --branches 100'

  html:
    deps:
      - :install:modules:local
      - :install:npm:nyc
    log:
      error: Error while generating HTML report with `nyc`
      start: Reporting with `nyc` in HTML format
      success: Report generated by `nyc` in HTML format
    cmds:
      - '{{.NPX_HANDLE}}nyc report --reporter=html'

  lcov:
    deps:
      - :install:modules:local
      - :install:npm:nyc
    log:
      error: Encountered error generating `lcov` report with `nyc`
      start: Reporting with `nyc` in `lcov` format
      success: Finished `lcov` report with `nyc`
    cmds:
      - '{{.NPX_HANDLE}}nyc report --reporter=lcov'

  open:
    deps:
      - html
      - :npm:install:open-cli
    desc: View the code coverage report in the browser
    hide: '{{ne .REPOSITORY_TYPE "npm"}}'
    log:
      start: Opening `coverage/index.html` with the default browser
    cmds:
      - '{{.NPX_HANDLE}}open-cli coverage/index.html'

  report:
    deps:
      - html
      - lcov

  upload:
    deps:
      - lcov
      - :install:npm:codecov
    desc: Upload code coverage report to `codecov.io`
    hide: '{{ne .REPOSITORY_TYPE "npm"}}'
    log:
      error: Error while running `codecov`
      start: Running `codecov`
      success: Successfully ran `codecov`
    cmds:
      - '{{.NPX_HANDLE}}codecov'
