steps:
  - task: NodeTool@0
    displayName: "Use Node 16.x"
    inputs:
      versionSpec: 16.x

  - bash: npm install gulp react-devtools @vscode/vsce -g --force
    displayName: "npm install gulp react-devtools @vscode/vsce -g"

  - bash: npm ci
    displayName: "npm ci"

  - bash: npm run build
    displayName: "npm run build"

  - bash: |
      /usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
      echo ">>> Started xvfb"
    displayName: Start xvfb
    condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))

  - bash: "npm test --verbose"
    displayName: "Run host tests"
    env:
      DISPLAY: ":99.0"

  - bash: npm run test-localization --verbose
    displayName: "Run localization tests"
    env:
      DISPLAY: ":99.0"

  - task: PublishTestResults@2
    displayName: "Publish Extension Test Results"
    inputs:
      testResultsFiles: test/ExtensionTests.xml
      failTaskOnFailedTests: true
      testRunTitle: "[Extension Context] $(Agent.OS) React Native unit tests - Attempt №$(System.JobAttempt)"
    condition: always()

  - task: PublishTestResults@2
    displayName: "Publish Localization Test Results"
    inputs:
      testResultsFiles: test/LocalizationTests.xml
      failTaskOnFailedTests: true
      testRunTitle: "[Localization Context] $(Agent.OS) React Native unit tests - Attempt №$(System.JobAttempt)"
    condition: always()
