-
Notifications
You must be signed in to change notification settings - Fork 5
/
Pester-step.yml
83 lines (72 loc) · 3.28 KB
/
Pester-step.yml
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# We need a pester step because the pester task won't let me specify `pwsh`
parameters:
testsDirectory: '$(Build.SourcesDirectory)/Tests'
includeTag: []
excludeTag: []
additionalModulePaths: []
codeCoverageDirectory: ''
testRunTitle: 'Pester'
show: 'All'
steps:
- powershell: |
Import-Module Pester -Passthru
$Options = @{
Path = Convert-Path "${{ parameters.testsDirectory }}"
OutputFormat = "NUnitXml"
OutputFile = Join-Path '$(Common.TestResultsDirectory)' 'Test-$(Build.SourceVersion).xml'
Show = "${{ parameters.show }}"
}
if ($CodeCoverage = "${{ parameters.codeCoverageDirectory }}") {
$Options.CodeCoverage = Get-ChildItem $CodeCoverage -Recurse -Include *.psm1, *.ps1 | Convert-Path
$Options.CodeCoverageOutputFile = '$(Common.TestResultsDirectory)/Coverage-$(Build.SourceVersion).xml'
}
if ($IncludeTag = @("${{ join('", "', parameters.includeTag) }}")) {
Write-Verbose "IncludeTag $($IncludeTag -join ', ')" -Verbose
$Options.Tag = $IncludeTag
}
if ($ExcludeTag = @("${{ join('", "', parameters.excludeTag) }}")) {
Write-Verbose "ExcludeTag $($ExcludeTag -join ', ')" -Verbose
$Options.ExcludeTag = $ExcludeTag
}
if ($AdditionalModulePaths = @("${{ join('", "', parameters.additionalModulePaths) }}")) {
$Env:PSModulePath = @(
@($AdditionalModulePaths -split [IO.Path]::PathSeparator | % TrimEnd(':;')) +
@($Env:PSModulePath -split [IO.Path]::PathSeparator | % TrimEnd(':;'))
) -join [IO.Path]::PathSeparator
Write-Verbose "Current PSModulePath $Env:PSModulePath" -Verbose
}
Write-Host $($Options | Out-String)
if (!$PSVersionTable.OS) {
$PSVersionTable.OS = [System.Environment]::OSVersion
}
Write-Host "##vso[task.setvariable variable=PSPlatform]PowerShell $($PSVersionTable['PSVersion', 'OS'] -join ' on ')"
Invoke-Pester @Options
displayName: Invoke-Pester
- powershell: |
#normalize source dir for code coverage
$sourceDirs = (@(Get-ChildItem ${{ parameters.codeCoverageDirectory }} -Directory -Recurse | Convert-Path) + "${{ parameters.codeCoverageDirectory }}") -join ";"
Write-Host "INFO [task.setvariable variable=CodeCoverageRecurseDirectories]$sourceDirs"
Write-Host "##vso[task.setvariable variable=CodeCoverageRecurseDirectories]$sourceDirs"
#}
displayName: Normalize Source Directory for Code Coverage Report
- task: PublishCodeCoverageResults@1
displayName: Publish Code Coverage
inputs:
summaryFileLocation: '$(Common.TestResultsDirectory)/Coverage-$(Build.SourceVersion).xml'
pathToSources: $(CodeCoverageRecurseDirectories)
failIfCoverageEmpty: true
condition: |
and(
succeededOrFailed(),
ne('', '${{ parameters.codeCoverageDirectory }}')
)
- task: PublishTestResults@2
displayName: Publish Test Results
inputs:
testResultsFormat: NUnit
testResultsFiles: '$(Common.TestResultsDirectory)/Test-$(Build.SourceVersion).xml'
buildPlatform: $(PSPlatform)
buildConfiguration: ${{ parameters.configurationName }}
failTaskOnFailedTests: true
testRunTitle: "${{ parameters.testRunTitle }} on $(PSPlatform)"
condition: succeededOrFailed()