-
Notifications
You must be signed in to change notification settings - Fork 187
/
run-unitTests.yaml
87 lines (78 loc) · 3.43 KB
/
run-unitTests.yaml
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
84
85
86
87
#
# This template contains the necessary jobs to run Pester on the repo and
# publish the test and code coverage results.
#
#--------------------------------------------------------------------------------------------------
# This template is dependent on the following pipeline variables being configured within the pipeline.
#
# 1. GitHubAccessToken - The access token with sufficient permissions to modify the accounts
# specified by GitHubOwnerName and GitHubOrganizatioName.
# It should be configured as a "secret".
# 2. GitHubOwnerName - The default "owner" that will be used for tests.
# 3. GitHubOrganizationName - The default "organization" that will be used for tests.
#--------------------------------------------------------------------------------------------------
parameters:
- name: 'gitHubAccessToken'
type: string
- name: 'gitHubOwnerName'
type: string
- name: 'gitHubOrganizationName'
type: string
- name: 'platformName'
default: 'Windows'
type: string
- name: 'usePowerShellCore'
default: false
type: boolean
steps:
- task: PowerShell@2
displayName: 'Install Pester'
inputs:
pwsh: eq('${{ parameters.usePowerShellCore }}', true)
errorActionPreference: 'stop'
workingDirectory: '$(System.DefaultWorkingDirectory)'
targetType: 'inline'
script: |
Install-Module -Name Pester -Repository PSGallery -Scope CurrentUser -AllowClobber -SkipPublisherCheck -MinimumVersion 5.3.3 -Force -Verbose
- task: PowerShell@2
displayName: 'Run Unit Tests via Pester'
inputs:
pwsh: eq('${{ parameters.usePowerShellCore }}', true)
errorActionPreference: 'stop'
workingDirectory: '$(System.DefaultWorkingDirectory)'
targetType: 'inline'
script: |
# Import the module, otherwise GitHubCore.tests.ps1 has problems since it's testing things in module scope.
Import-Module -Global ./PowerShellForGitHub.psd1
$null = New-Item -Path ../ -Name Pester -ItemType Directory -Force
$pesterConfig = New-PesterConfiguration
$pesterConfig.CodeCoverage.Enabled = $true
$pesterConfig.CodeCoverage.Path = @('.\*.ps*1')
$pesterConfig.CodeCoverage.OutputPath = '../Pester/coverage.xml'
$pesterConfig.CodeCoverage.OutputFormat = 'JaCoCo'
$pesterConfig.Run.Exit = $true
$pesterConfig.TestResult.Enabled = $true
$pesterConfig.TestResult.OutputPath = '../Pester/test-results.xml'
$pesterConfig.TestResult.OutputFormat = 'NUnitXml'
$pesterConfig.Output.CIFormat = 'AzureDevops'
Invoke-Pester -Configuration $pesterConfig
env:
ciAccessToken: ${{ parameters.gitHubAccessToken }}
ciOwnerName: ${{ parameters.gitHubOwnerName }}
ciOrganizationName: ${{ parameters.gitHubOrganizationName }}
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testRunTitle: '${{ parameters.platformName }} Test Results for Pester'
buildPlatform: 'Windows'
testRunner: NUnit
testResultsFiles: '../Pester/test-results.xml'
failTaskOnFailedTests: true # required to fail build when tests fail
condition: succeededOrFailed()
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: 'JaCoCo'
summaryFileLocation: '../Pester/coverage.xml'
failIfCoverageEmpty: true
condition: succeededOrFailed()