Skip to content

Commit

Permalink
Update compatibility with Pester 5
Browse files Browse the repository at this point in the history
  • Loading branch information
vicperdana committed Aug 20, 2024
1 parent b119341 commit d3c814b
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions pipeline.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -190,36 +190,52 @@ task Dependencies NuGet, {
}

# Synopsis: Test the module
task TestModule Dependencies, {
Import-Module Pester -RequiredVersion 5.6.1 -Force;
task TestModuleDependencies {
Import-Module Pester -RequiredVersion 5.6.1 -Force

# Run Pester tests
$pesterParams = @{ Path = $PWD; OutputFile = 'reports/pester-unit.xml'; OutputFormat = 'NUnitXml'; PesterOption = @{ IncludeVSCodeMarker = $True }; PassThru = $True; };
$pesterParams = @{
Path = $PWD
Output = @{
Format = 'NUnitXml'
File = 'reports/pester-unit.xml'
}
Configuration = @{
Run = @{
PassThru = $True
IncludeVSCodeMarker = $True
}
}
}

if ($CodeCoverage) {
$pesterParams.Add('CodeCoverage', (Join-Path -Path $PWD -ChildPath 'out/modules/**/*.psm1'));
$pesterParams.Add('CodeCoverageOutputFile', (Join-Path -Path $PWD -ChildPath reports/pester-coverage.xml));
$pesterParams.Configuration.CodeCoverage = @{
OutputFormat = 'JaCoCo'
OutputPath = (Join-Path -Path $PWD -ChildPath 'reports/pester-coverage.xml')
Path = (Join-Path -Path $PWD -ChildPath 'out/modules/**/*.psm1')
}
}

if (!(Test-Path -Path reports)) {
$Null = New-Item -Path reports -ItemType Directory -Force;
$Null = New-Item -Path reports -ItemType Directory -Force
}

if ($Null -ne $TestGroup) {
$pesterParams['Tags'] = $TestGroup;
$pesterParams.Configuration.Run.Tags = $TestGroup
}

$results = Invoke-Pester @pesterParams;
$results = Invoke-Pester @pesterParams

# Throw an error if pester tests failed
# Throw an error if Pester tests failed
if ($Null -eq $results) {
throw 'Failed to get Pester test results.';
throw 'Failed to get Pester test results.'
}
elseif ($results.FailedCount -gt 0) {
throw "$($results.FailedCount) tests failed.";
elseif ($results.Result.FailedCount -gt 0) {
throw "$($results.Result.FailedCount) tests failed."
}
}


task Benchmark {
if ($Benchmark -or $BuildTask -eq 'Benchmark') {
dotnet run --project src/PSDocs.Benchmark -f net7.0 -c Release -- benchmark --output $PWD;
Expand Down

0 comments on commit d3c814b

Please sign in to comment.