Skip to content

Commit

Permalink
Updated pester test to support pester v5 (#74)
Browse files Browse the repository at this point in the history
Co-authored-by: Gael <[email protected]>
  • Loading branch information
NicolasBn and gaelcolas authored Feb 7, 2023
1 parent b280512 commit e74846a
Show file tree
Hide file tree
Showing 7 changed files with 533 additions and 473 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
of pipeline artifact
- Updated build.ps1 script and build.yaml.
- Changed default timeout in Wait-Win32ProcessStart function for cab installation.
- Updated pester test to support pester v5
- Updated ReadMe.md to removed `RunRuleNow` parameter.

### Added
Expand Down
2 changes: 1 addition & 1 deletion RequiredModules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'powershell-yaml' = 'latest'
InvokeBuild = 'latest'
PSScriptAnalyzer = 'latest'
Pester = '4.10.1'
Pester = '5.3.3'
Plaster = 'latest'
ModuleBuilder = '1.0.0'
ChangelogManagement = 'latest'
Expand Down
272 changes: 144 additions & 128 deletions Tests/Unit/MSFT_UpdateServicesApprovalRule.tests.ps1

Large diffs are not rendered by default.

363 changes: 193 additions & 170 deletions Tests/Unit/MSFT_UpdateServicesCleanup.tests.ps1

Large diffs are not rendered by default.

295 changes: 145 additions & 150 deletions Tests/Unit/MSFT_UpdateServicesServer.tests.ps1

Large diffs are not rendered by default.

66 changes: 44 additions & 22 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ BuildWorkflow:
- package_module_nupkg

hqrmtest:
- DscResource_Tests_Stop_On_Fail
- Invoke_HQRM_Tests_Stop_On_Fail

test:
- Pester_Tests_Stop_On_Fail
- Convert_Pester_Coverage
- Pester_if_Code_Coverage_Under_Threshold

publish:
Expand All @@ -51,35 +52,54 @@ BuildWorkflow:


Pester: #Passthru, OutputFile, CodeCoverageOutputFile not supported
OutputFormat: NUnitXML
Configuration:
Run:
Path:
- tests/Unit
- tests/QA
Output:
Verbosity: Detailed
StackTraceVerbosity: Full
CIFormat: Auto
CodeCoverage:
CoveragePercentTarget: 50
OutputPath: JaCoCo_coverage.xml
OutputEncoding: ascii
# There is a bug in Pester when running unit tests for classes when 'UseBreakpoints' is turned off.
# See error in gist: https://gist.github.com/johlju/c16dfd9587c7e066e8825fc54b33a703
UseBreakpoints: true
TestResult:
OutputFormat: NUnitXML
OutputEncoding: ascii
ExcludeFromCodeCoverage:
- Modules/DscResource.Common
Script:
# - tests/Unit/MSFT_UpdateServicesCleanup.tests.ps1
# - tests/Unit/MSFT_UpdateServicesServer.tests.ps1
# - tests/Unit/MSFT_UpdateServicesApprovalRule.tests.ps1
- tests/Unit
- tests/QA
# - tests/Integration
ExcludeTag:
- helpQuality
- FunctionalQuality
- TestQuality
Tag:
CodeCoverageThreshold: 50 # Set to 0 to bypass
# CodeCoverageOutputFile: JaCoCo_$OsShortName.xml
# CodeCoverageOutputFileEncoding: ascii
# CodeCoverageMergedOutputFile: JaCoCo_Merged.xml

####################################################
# Pester Configuration (DscResource.Test) #
####################################################
DscTest:
ExcludeTag:
- "Common Tests - New Error-Level Script Analyzer Rules"
Tag:
ExcludeSourceFile:
- output
ExcludeModuleFile:
- Modules/DscResource.Common

Pester:
Configuration:
Filter:
ExcludeTag:
- "Common Tests - New Error-Level Script Analyzer Rules"
Output:
Verbosity: Detailed
CIFormat: Auto
TestResult:
OutputFormat: NUnitXML
OutputEncoding: ascii
OutputPath: ./output/testResults/NUnitXml_HQRM_Tests.xml
Script:
ExcludeSourceFile:
- output
ExcludeModuleFile:
- Modules/DscResource.Common
MainGitBranch: main

ModuleBuildTasks:
Sampler:
Expand All @@ -88,6 +108,8 @@ ModuleBuildTasks:
- '*.ib.tasks'
DscResource.DocGenerator:
- 'Task.*'
DscResource.Test:
- 'Task.*'


# Invoke-Build Header to be used to 'decorate' the terminal output of the tasks.
Expand Down
7 changes: 5 additions & 2 deletions source/Modules/PDT/PDT.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' -FileName 'P

# New-InvalidArgumentError
# New-InvalidArgumentException -ArgumentName 'Action' -Message $errorMessage

<#
.SYNOPSIS
Resolves a path and verifies it exists.
.PARAMETER Path
Path to resolve
Path to resolve and return to caller.
#>
function Invoke-ResolvePath
{
[CmdletBinding()]
[OutputType([string])]
param
(
[Parameter(Mandatory = $true)]
Expand Down Expand Up @@ -152,6 +154,7 @@ function Test-RootedPath
function Get-Arguments
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory = $true)]
Expand All @@ -166,7 +169,7 @@ function Get-Arguments
$NewArgumentNames
)

$returnValue = @{ }
$returnValue = @{}

for ($i = 0; $i -lt $ArgumentNames.Count; $i++)
{
Expand Down

0 comments on commit e74846a

Please sign in to comment.