jobs:
  - job: ${{ parameters.name }}
    pool:
      vmImage: ${{ parameters.vmImage }}
    strategy:
      matrix:
        node_10_x:
          node_version: 10.x
        node_12_x:
          node_version: 12.x
      maxParallel: 3
    steps:
      - task: NodeTool@0
        inputs:
          versionSpec: $(node_version)
        displayName: 'Install Node.js'

      # Install Rust
      - ${{ if ne(parameters.name, 'Windows') }}:
          - script: |
              curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly
              export PATH="$HOME/.cargo/bin:$PATH"
              echo "##vso[task.setvariable variable=PATH]$PATH"
              rustc -Vv
              cargo -V
            displayName: Install Rust
      - ${{ if eq(parameters.name, 'Windows') }}:
          - script: |
              curl -sSf -o rustup-init.exe https://win.rustup.rs
              rustup-init.exe -y --default-toolchain nightly
              set PATH=%PATH%;%USERPROFILE%\.cargo\bin
              echo "##vso[task.setvariable variable=PATH]%PATH%;%USERPROFILE%\.cargo\bin"
              rustc -Vv
              cargo -V
            displayName: Install Rust

      - ${{ if eq(parameters.name, 'Linux') }}:
          - script: |
              echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p;
            displayName: Bump max inotify watches

      # use `--frozen-lockfile` to fail immediately if the committed yarn.lock needs updates
      # https://yarnpkg.com/lang/en/docs/cli/install/#toc-yarn-install-frozen-lockfile
      - script: yarn --frozen-lockfile
        displayName: 'Install dependencies'
      - script: yarn test:unit
        displayName: 'Run unit tests'
      - script: yarn test:integration-ci
        displayName: 'Run integration tests'
      - script: yarn flow
        displayName: 'Type check with Flow'
      - script: yarn lint
        displayName: 'Lint'
      - task: PublishTestResults@2
        displayName: 'Publish Test Results'
        condition: succeededOrFailed()
        inputs:
          testResultsFiles: '**/junit-*.xml'
          testRunTitle: TestRun ${{ parameters.name }} $(node_version)
      - task: PublishCodeCoverageResults@1
        displayName: 'Publish code coverage results'
        condition: succeededOrFailed()
        inputs:
          codeCoverageTool: 'cobertura'
          summaryFileLocation: '**/coverage/cobertura-coverage.xml'
          reportDirectory: '**/parcel-bundler/coverage'
