|
| 1 | +trigger: |
| 2 | + branches: |
| 3 | + include: |
| 4 | + - main |
| 5 | + - preview |
| 6 | + - release/* |
| 7 | + |
| 8 | +pr: |
| 9 | + branches: |
| 10 | + include: |
| 11 | + - main |
| 12 | + - preview |
| 13 | + - release/* |
| 14 | + |
| 15 | +pool: |
| 16 | + vmImage: ubuntu-latest |
| 17 | + |
| 18 | +stages: |
| 19 | +- stage: Build |
| 20 | + displayName: Build and offline tests |
| 21 | + jobs: |
| 22 | + - job: NodeTests |
| 23 | + displayName: Node.js tests |
| 24 | + strategy: |
| 25 | + matrix: |
| 26 | + Node20: |
| 27 | + nodeVersion: 20.x |
| 28 | + Node22: |
| 29 | + nodeVersion: 22.x |
| 30 | + Node24: |
| 31 | + nodeVersion: 24.x |
| 32 | + steps: |
| 33 | + - checkout: self |
| 34 | + - task: UseNode@1 |
| 35 | + displayName: Use Node.js $(nodeVersion) |
| 36 | + inputs: |
| 37 | + version: $(nodeVersion) |
| 38 | + - script: npm ci |
| 39 | + displayName: Install dependencies |
| 40 | + - script: npm run lint |
| 41 | + displayName: Lint |
| 42 | + - script: npm run build |
| 43 | + displayName: Build |
| 44 | + - script: npm test -- --reporter xunit --reporter-option "output=$(Agent.TempDirectory)/test-results/unit-tests.xml" |
| 45 | + displayName: Run Node.js unit tests |
| 46 | + - script: npm run test-browser -- --reporter=default --reporter=junit --outputFile="$(Agent.TempDirectory)/test-results/browser-tests.xml" |
| 47 | + displayName: Run browser tests |
| 48 | + - task: PublishTestResults@2 |
| 49 | + displayName: Publish unit and browser test results |
| 50 | + condition: succeededOrFailed() |
| 51 | + inputs: |
| 52 | + testResultsFormat: JUnit |
| 53 | + testResultsFiles: | |
| 54 | + unit-tests.xml |
| 55 | + browser-tests.xml |
| 56 | + searchFolder: $(Agent.TempDirectory)/test-results |
| 57 | + mergeTestResults: true |
| 58 | + failTaskOnFailedTests: true |
| 59 | + failTaskOnFailureToPublishResults: true |
| 60 | + failTaskOnMissingResultsFile: true |
| 61 | + testRunTitle: Node.js $(nodeVersion) unit and browser tests |
| 62 | + |
| 63 | +- stage: Integration |
| 64 | + displayName: Live integration tests |
| 65 | + dependsOn: Build |
| 66 | + condition: | |
| 67 | + and( |
| 68 | + succeeded(), |
| 69 | + or( |
| 70 | + and( |
| 71 | + eq(variables['Build.Reason'], 'Manual'), |
| 72 | + startsWith(variables['Build.SourceBranch'], 'refs/heads/') |
| 73 | + ), |
| 74 | + and( |
| 75 | + in(variables['Build.SourceBranch'], 'refs/heads/main', 'refs/heads/preview'), |
| 76 | + in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI') |
| 77 | + ) |
| 78 | + ) |
| 79 | + ) |
| 80 | + jobs: |
| 81 | + - job: LiveTests |
| 82 | + displayName: Node.js live integration tests |
| 83 | + timeoutInMinutes: '15' |
| 84 | + steps: |
| 85 | + - checkout: self |
| 86 | + - task: UseNode@1 |
| 87 | + displayName: Use Node.js 24 |
| 88 | + inputs: |
| 89 | + version: 24.x |
| 90 | + - script: npm ci |
| 91 | + displayName: Install dependencies |
| 92 | + - task: AzureCLI@2 |
| 93 | + displayName: Run integration tests with the service principal |
| 94 | + inputs: |
| 95 | + azureSubscription: 'JS Provider GitHub PR Integration Test' |
| 96 | + addSpnToEnvironment: true |
| 97 | + visibleAzLogin: false |
| 98 | + scriptType: pscore |
| 99 | + scriptLocation: inlineScript |
| 100 | + workingDirectory: $(Build.SourcesDirectory) |
| 101 | + inlineScript: | |
| 102 | + foreach ($name in @("servicePrincipalId", "tenantId", "idToken")) { |
| 103 | + if ([string]::IsNullOrWhiteSpace([Environment]::GetEnvironmentVariable($name))) { |
| 104 | + throw "Missing $name. Configure the service connection with workload identity federation." |
| 105 | + } |
| 106 | + } |
| 107 | + if ($env:AZURE_CLIENT_SECRET -or $env:AZURE_CLIENT_CERTIFICATE_PATH) { |
| 108 | + throw "Do not configure client secrets or certificates for this federated test job." |
| 109 | + } |
| 110 | +
|
| 111 | + $env:AZURE_CLIENT_ID = $env:servicePrincipalId |
| 112 | + $env:AZURE_TENANT_ID = $env:tenantId |
| 113 | + $tokenPath = Join-Path $env:AGENT_TEMPDIRECTORY "appconfig-federated-$([Guid]::NewGuid().ToString('N')).txt" |
| 114 | +
|
| 115 | + try { |
| 116 | + Set-Content -LiteralPath $tokenPath -Value $env:idToken -NoNewline -Encoding utf8 |
| 117 | + $env:AZURE_FEDERATED_TOKEN_FILE = $tokenPath |
| 118 | + $env:AZURE_SUBSCRIPTION_ID = az account show --query id --output tsv --only-show-errors |
| 119 | + if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($env:AZURE_SUBSCRIPTION_ID)) { |
| 120 | + throw "Could not read the subscription selected by the service connection." |
| 121 | + } |
| 122 | +
|
| 123 | + $resultsPath = Join-Path $env:AGENT_TEMPDIRECTORY "test-results/integration-tests.xml" |
| 124 | + npm run test:integration -- --reporter xunit --reporter-option "output=$resultsPath" |
| 125 | + if ($LASTEXITCODE -ne 0) { |
| 126 | + throw "Integration tests failed with exit code $LASTEXITCODE." |
| 127 | + } |
| 128 | + } finally { |
| 129 | + $env:AZURE_FEDERATED_TOKEN_FILE = $null |
| 130 | + if (Test-Path -LiteralPath $tokenPath) { |
| 131 | + Remove-Item -LiteralPath $tokenPath -Force |
| 132 | + } |
| 133 | + } |
| 134 | + - task: PublishTestResults@2 |
| 135 | + displayName: Publish integration test results |
| 136 | + condition: succeededOrFailed() |
| 137 | + inputs: |
| 138 | + testResultsFormat: JUnit |
| 139 | + testResultsFiles: integration-tests.xml |
| 140 | + searchFolder: $(Agent.TempDirectory)/test-results |
| 141 | + failTaskOnFailedTests: true |
| 142 | + failTaskOnFailureToPublishResults: true |
| 143 | + failTaskOnMissingResultsFile: true |
| 144 | + testRunTitle: Node.js 24 live integration tests |
0 commit comments