Skip to content

Commit 1fce0e0

Browse files
Merge pull request #46 from Clebam/development
Update pester.ps1
2 parents c548608 + a9555f7 commit 1fce0e0

File tree

4 files changed

+66
-66
lines changed

4 files changed

+66
-66
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ PSModuleDevelopment/PSModuleDevelopment.psproj.bak
2222
PSModuleDevelopment/PSModuleDevelopment.psprojs
2323
PSModuleDevelopment/PSModuleDevelopment.psproj
2424
sh.exe.stackdump
25+
26+
# ignore the TestResults
27+
TestResults/*

PSModuleDevelopment/PSModuleDevelopment.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ function Import-PSMDFile
2929
$Path
3030
)
3131

32-
if ($script:doDotSource) { . $Path }
33-
else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($Path))), $null, $null) }
32+
if ($script:doDotSource) { . (Resolve-Path $Path) }
33+
else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($(Resolve-Path $Path)))), $null, $null) }
3434
}
3535
#endregion Helper function
3636

@@ -53,4 +53,4 @@ foreach ($function in (Get-ChildItem "$PSModuleRoot\functions" -Recurse -File -F
5353
#endregion Load functions
5454

5555
# Perform Actions after loading the module contents
56-
. Import-PSMDFile -Path "$PSModuleRoot\internal\scripts\postload.ps1"
56+
. Import-PSMDFile -Path "$PSModuleRoot\internal\scripts\postload.ps1"

PSModuleDevelopment/tests/pester.ps1

Lines changed: 59 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,82 @@
11
param (
2-
[ValidateSet('None', 'Default', 'Passed', 'Failed', 'Pending', 'Skipped', 'Inconclusive', 'Describe', 'Context', 'Summary', 'Header', 'Fails', 'All')]
3-
[string]
4-
$Show = "None",
5-
6-
[ValidateSet('Everything', 'Functions', 'General')]
7-
[string]
8-
$Run = "Everything",
9-
10-
[string]
11-
$Filter = "*.Tests.ps1"
2+
[ValidateSet('None', 'Default', 'Passed', 'Failed', 'Pending', 'Skipped', 'Inconclusive', 'Describe', 'Context', 'Summary', 'Header', 'Fails', 'All')]
3+
[string]
4+
$Show = "None",
5+
6+
[ValidateSet('Everything', 'Functions', 'General')]
7+
[string]
8+
$Run = "Everything",
9+
10+
[string]
11+
$Filter = "*.Tests.ps1"
1212
)
1313

14-
Write-Host "Starting Tests" -ForegroundColor Green
14+
Write-PSFMessage -Level Host -Message "Starting Tests"
1515

16-
Write-Host "Importing Module" -ForegroundColor Cyan
16+
Write-PSFMessage -Level Host -Message "Importing Module"
1717

1818
Remove-Module PSModuleDevelopment -ErrorAction Ignore
1919
Import-Module "$PSScriptRoot\..\PSModuleDevelopment.psd1"
2020
Import-Module "$PSScriptRoot\..\PSModuleDevelopment.psm1" -Force
2121

22+
Write-PSFMessage -Level Host -Message "Creating test result folder"
23+
$null = New-Item -Path "$PSScriptRoot\..\.." -Name TestResults -ItemType Directory -Force
24+
2225
$totalFailed = 0
2326
$totalRun = 0
2427

2528
$testresults = @()
2629

27-
if ($Run -match "Everything|General")
28-
{
29-
Write-PSFMessage -Level Important -Message "Modules imported, proceeding with general tests"
30-
foreach ($file in (Get-ChildItem "$PSScriptRoot\general" -Filter $Filter))
31-
{
32-
Write-PSFMessage -Level Significant -Message " Executing <c='em'>$($file.Name)</c>"
33-
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru
34-
foreach ($result in $results)
35-
{
36-
$totalRun += $result.TotalCount
37-
$totalFailed += $result.FailedCount
38-
$result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
39-
$name = $_.Name
40-
$testresults += [pscustomobject]@{
41-
Describe = $_.Describe
42-
Context = $_.Context
43-
Name = "It $name"
44-
Result = $_.Result
45-
Message = $_.FailureMessage
46-
}
47-
}
48-
}
49-
}
30+
if ($Run -match "Everything|General") {
31+
Write-PSFMessage -Level Important -Message "Modules imported, proceeding with general tests"
32+
foreach ($file in (Get-ChildItem "$PSScriptRoot\general" -Filter $Filter)) {
33+
Write-PSFMessage -Level Significant -Message " Executing <c='em'>$($file.Name)</c>"
34+
$TestOuputFile = Join-Path "$PSScriptRoot\..\..\TestResults" "TEST-$($file.BaseName).xml"
35+
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru -OutputFile $TestOuputFile -OutputFormat NUnitXml
36+
foreach ($result in $results) {
37+
$totalRun += $result.TotalCount
38+
$totalFailed += $result.FailedCount
39+
$result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
40+
$name = $_.Name
41+
$testresults += [pscustomobject]@{
42+
Describe = $_.Describe
43+
Context = $_.Context
44+
Name = "It $name"
45+
Result = $_.Result
46+
Message = $_.FailureMessage
47+
}
48+
}
49+
}
50+
}
5051
}
5152

52-
if ($Run -match "Everything|Functions")
53-
{
54-
Write-PSFMessage -Level Important -Message "Proceeding with individual tests"
55-
foreach ($file in (Get-ChildItem "$PSScriptRoot\functions" -Recurse -File -Filter $Filter))
56-
{
57-
Write-PSFMessage -Level Significant -Message " Executing $($file.Name)"
58-
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru
59-
foreach ($result in $results)
60-
{
61-
$totalRun += $result.TotalCount
62-
$totalFailed += $result.FailedCount
63-
$result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
64-
$name = $_.Name
65-
$testresults += [pscustomobject]@{
66-
Describe = $_.Describe
67-
Context = $_.Context
68-
Name = "It $name"
69-
Result = $_.Result
70-
Message = $_.FailureMessage
71-
}
72-
}
73-
}
74-
}
53+
if ($Run -match "Everything|Functions") {
54+
Write-PSFMessage -Level Important -Message "Proceeding with individual tests"
55+
foreach ($file in (Get-ChildItem "$PSScriptRoot\functions" -Recurse -File -Filter $Filter)) {
56+
Write-PSFMessage -Level Significant -Message " Executing $($file.Name)"
57+
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru
58+
foreach ($result in $results) {
59+
$totalRun += $result.TotalCount
60+
$totalFailed += $result.FailedCount
61+
$result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
62+
$name = $_.Name
63+
$testresults += [pscustomobject]@{
64+
Describe = $_.Describe
65+
Context = $_.Context
66+
Name = "It $name"
67+
Result = $_.Result
68+
Message = $_.FailureMessage
69+
}
70+
}
71+
}
72+
}
7573
}
7674

7775
$testresults | Sort-Object Describe, Context, Name, Result, Message | Format-List
7876

7977
if ($totalFailed -eq 0) { Write-PSFMessage -Level Critical -Message "All <c='em'>$totalRun</c> tests executed without a single failure!" }
8078
else { Write-PSFMessage -Level Critical -Message "<c='em'>$totalFailed tests</c> out of <c='sub'>$totalRun</c> tests failed!" }
8179

82-
if ($totalFailed -gt 0)
83-
{
84-
throw "$totalFailed / $totalRun tests failed!"
85-
}
80+
if ($totalFailed -gt 0) {
81+
throw "$totalFailed / $totalRun tests failed!"
82+
}

PSModuleDevelopment/xml/PSModuleDevelopment.Types.ps1xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Types>
33
<!-- PSModuleDevelopment.Template.ParameterScript -->
44
<Type>

0 commit comments

Comments
 (0)