parameters:
  name: ''
  vmImage: ''
  nodeVersion: ''
  preBuild: []
  testCommand: ''
  browser: ''

jobs:
- job: ${{ parameters.name }}
  pool:
    vmImage: ${{ parameters.vmImage }}
  dependsOn: CodeCheck
  steps:
  - task: NodeTool@0
    displayName: Install Node.js
    inputs:
      versionSpec: ${{ parameters.nodeVersion }}

  - ${{ parameters.preBuild }}

  - script: npm install
    displayName: Install dependencies
    workingDirectory: $(coreDirectory)

  - script: npm test -- --ci --runInBand --coverage --reporters="default" --reporters="jest-junit" --coverage-reporters="cobertura"
    displayName: Test
    workingDirectory: $(coreDirectory)
    env:
      BROWSER: ${{ parameters.browser }}
      BROWSERSTACK_USERNAME: $(browserstack.user)
      BROWSERSTACK_ACCESS_KEY: $(browserstack.key)

  - task: PublishTestResults@2
    displayName: Publish Jest Test Results
    condition: succeededOrFailed()
    inputs:
      testResultsFormat: 'JUnit'
      testResultsFiles: 'junit.xml'
      searchFolder: $(coreDirectory)
      mergeTestResults: true
      testRunTitle: 'Test Results (${{ parameters.browser }})'

  - task: PublishCodeCoverageResults@1
    displayName: Publish Jest Test Coverage
    inputs:
      codeCoverageTool: 'cobertura'
      summaryFileLocation: $(coreDirectory)/coverage/cobertura-coverage.xml
      reportDirectory: $(coreDirectory)/coverage
      failIfCoverageEmpty: true

parameters:
  name: ''
  vmImage: ''
  nodeVersion: ''
  preBuild: []
  testCommand: ''
  browser: ''

jobs:
- job: ${{ parameters.name }}
  pool:
    vmImage: ${{ parameters.vmImage }}
  dependsOn: CodeCheck
  steps:
  - task: NodeTool@0
    displayName: Install Node.js
    inputs:
      versionSpec: ${{ parameters.nodeVersion }}

  - ${{ parameters.preBuild }}

  - script: npm install
    displayName: Install dependencies
    workingDirectory: $(coreDirectory)

  - script: npm test -- --ci --runInBand --coverage --reporters=default --reporters=jest-junit --coverage-reporters=cobertura
    displayName: Test
    workingDirectory: $(coreDirectory)
    env:
      BROWSER: ${{ parameters.browser }}
      BROWSERSTACK_USERNAME: $(browserstack.user)
      BROWSERSTACK_ACCESS_KEY: $(browserstack.key)
      JEST_SUITE_NAME: ${{ parameters.browser }}
      JEST_JUNIT_INCLUDE_CONSOLE_OUTPUT: 'true'

  - task: PublishTestResults@2
    displayName: Publish Jest Test Results
    condition: succeededOrFailed()
    inputs:
      testResultsFormat: 'JUnit'
      testResultsFiles: 'junit.xml'
      searchFolder: $(coreDirectory)
      mergeTestResults: true
      testRunTitle: 'Test Results (${{ parameters.browser }})'

  - task: PublishCodeCoverageResults@1
    displayName: Publish Jest Test Coverage
    inputs:
      codeCoverageTool: 'cobertura'
      summaryFileLocation: $(coreDirectory)/coverage/cobertura-coverage.xml
      reportDirectory: $(coreDirectory)/coverage
      failIfCoverageEmpty: true

Include console output in junit report
Include console output in junit report
