1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
parameters:
- name: TargetDirectory
type: string
- name: CustomTestSteps
type: object
default: []
- name: EnvVars
type: object
default: {}
- name: TargetTags
type: string
default: ''
steps:
- pwsh: |
Install-Module -Name Pester -Force
displayName: Install Pester
# default test steps
- ${{ if eq(length(parameters.CustomTestSteps), 0) }}:
- pwsh: |
$tags = "${{ parameters.TargetTags }}" -Split "," | ForEach-Object { return $_.Trim() }
$config = New-PesterConfiguration
$config.CodeCoverage.Enabled = $true
$config.TestResult.Enabled = $true
$config.Run.PassThru = $true
if ($tags) {
$config.Filter.Tag = $tags
}
Write-Host "Calling 'Invoke-Pester' in workingDirectory '$(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}'. Pester tags filter: '$tags'"
# https://pester.dev/docs/commands/Invoke-Pester
Invoke-Pester -Configuration $config
displayName: Run Pester Tests
env: ${{ parameters.EnvVars }}
workingDirectory: $(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}
- ${{ if not(eq(length(parameters.CustomTestSteps), 0)) }}:
- ${{ parameters.CustomTestSteps }}
- task: PublishTestResults@2
displayName: Publish Test Results
condition: succeededOrFailed()
inputs:
testResultsFormat: NUnit
testResultsFiles: $(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}/testResults.xml
testRunTitle: $(System.StageName)_$(Agent.JobName)_Tests
- task: PublishCodeCoverageResults@2
displayName: Publish Code Coverage to Azure DevOps
condition: succeededOrFailed()
inputs:
summaryFileLocation: $(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}/coverage.xml
pathToSources: $(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}
|