Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pester v5 #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions CI/Invoke-Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,30 @@ param(
)
$srcPath=Resolve-Path -Path "$PSScriptRoot\..\Src"
$outputFile=[System.IO.Path]::GetTempFileName()+".xml"
$splat=@{
Script=$srcPath
PassThru=$true
OutputFormat="NUnitXml"
OutputFile=$outputFile
ExcludeTag=$ExcludeTag
Tag=$Tag
}

# https://pester-docs.netlify.app/docs/commands/New-PesterConfiguration
$pesterConfiguration=New-PesterConfiguration
$pesterConfiguration.Run.Path=$srcPath
$pesterConfiguration.Run.PassThru=$true
$pesterConfiguration.Run.Path=$srcPath
$pesterConfiguration.Filter.Tag=$Tag
$pesterConfiguration.Filter.ExcludeTag=$ExcludeTag

$pesterConfiguration.TestResult.Enabled=$true
$pesterConfiguration.TestResult.OutputFormat="NUnitXml"
$pesterConfiguration.TestResult.OutputPath=$outputFile

$pesterConfiguration.Output.Verbosity="Detailed"
#$pesterConfiguration.Output.Verbosity="Diagnostic"

if($CodeCoverage)
{
$codeCoveragePath=$outputFile.Replace(".xml",".codecoverage.xml")
$splat+=@{
CodeCoverage=Get-ChildItem -Path $srcPath -Exclude @("*.Tests.ps1","*.NotReady.ps1","Src\Tests\**") -Filter "*.ps1" -Recurse|Select-Object -ExpandProperty FullName
CodeCoverageOutputFile=$codeCoveragePath
}
$pesterConfiguration.CodeCoverage.Enabled=$true
# $pesterConfiguration.CodeCoverage.OutputFormat="JaCoCo"
$pesterConfiguration.CodeCoverage.OutputPath=$outputFile.Replace(".xml",".codecoverage.xml")
}

$pesterResult=Invoke-Pester @splat
$pesterResult=Invoke-Pester -Configuration $pesterConfiguration
if($CodeCoverage)
{
$pesterResult|Select-Object @{
Expand All @@ -51,11 +57,11 @@ if($CodeCoverage)
switch($PSCmdlet.ParameterSetName) {
'AppVeyor' {
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", $outputFile)
if ($pesterResult.FailedCount -gt 0) {
throw "$($pesterResult.FailedCount) tests failed."
}
}
'Console' {

}
}
if ($pesterResult.FailedCount -gt 0) {
throw "$($pesterResult.FailedCount) tests failed."
}
14 changes: 9 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
version: 1.0.{build}
image: Ubuntu1804
init:
- pwsh: Get-ChildItem ENV:\
- pwsh: >-
$PSVersionTable

Get-ChildItem ENV:\
install:
- pwsh: >-
$modules=@(
Expand All @@ -13,8 +16,9 @@ install:

Get-Module -Name $modules -ListAvailable|Format-Table Name,Version,Path
build: off
test_script:
- pwsh: '& .\CI\Invoke-Test.ps1 -AppVeyor'
# There are no tests and Pester v5 throws error
# test_script:
# - pwsh: '& .\CI\Invoke-Test.ps1 -AppVeyor'
for:

-
Expand All @@ -24,11 +28,11 @@ for:

environment:
NuGetAPIKey:
secure: aU9vw9DIzXNRjmiS8ZtYvFZij4RUvdpeqoR1XaaemfKUjdc3y2Qw+qzCNSHsLXxY
secure: dQfAg96Oa5m/lEerqsiYFi87FsxKxtVWG4ejbQBLDyxxymuNuf2xvh8Lkf5dTqBc
deploy_script:
- pwsh: >-
& .\CI\Publish-Module.ps1 -NuGetAPIKey $env:NuGetAPIKey

notifications:
- provider: GitHubPullRequest
template: "{{#passed}}:white_check_mark:{{/passed}}{{#failed}}:x:{{/failed}} [Build {{&projectName}} {{buildVersion}} {{status}}]({{buildUrl}}) (commit {{commitUrl}} by @{{&commitAuthorUsername}})"
template: "{{#passed}}:white_check_mark:{{/passed}}{{#failed}}:x:{{/failed}} [Build {{&projectName}} {{buildVersion}} {{status}}]({{buildUrl}}) (commit {{commitUrl}} by @{{&commitAuthorUsername}})"