-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpester.ps1
More file actions
85 lines (73 loc) · 2.58 KB
/
Copy pathpester.ps1
File metadata and controls
85 lines (73 loc) · 2.58 KB
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
param (
[ValidateSet('None', 'Default', 'Passed', 'Failed', 'Pending', 'Skipped', 'Inconclusive', 'Describe', 'Context', 'Summary', 'Header', 'Fails', 'All')]
[string]
$Show = "None",
[ValidateSet('Everything', 'Functions', 'General')]
[string]
$Run = "Everything",
[string]
$Filter = "*.Tests.ps1"
)
Write-Host "Starting Tests" -ForegroundColor Green
Write-Host "Importing Module" -ForegroundColor Cyan
Remove-Module PSModuleDevelopment -ErrorAction Ignore
Import-Module "$PSScriptRoot\..\PSModuleDevelopment.psd1"
Import-Module "$PSScriptRoot\..\PSModuleDevelopment.psm1" -Force
$totalFailed = 0
$totalRun = 0
$testresults = @()
if ($Run -match "Everything|General")
{
Write-PSFMessage -Level Important -Message "Modules imported, proceeding with general tests"
foreach ($file in (Get-ChildItem "$PSScriptRoot\general" -Filter $Filter))
{
Write-PSFMessage -Level Significant -Message " Executing <c='em'>$($file.Name)</c>"
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru
foreach ($result in $results)
{
$totalRun += $result.TotalCount
$totalFailed += $result.FailedCount
$result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
$name = $_.Name
$testresults += [pscustomobject]@{
Describe = $_.Describe
Context = $_.Context
Name = "It $name"
Result = $_.Result
Message = $_.FailureMessage
}
}
}
}
}
if ($Run -match "Everything|Functions")
{
Write-PSFMessage -Level Important -Message "Proceeding with individual tests"
foreach ($file in (Get-ChildItem "$PSScriptRoot\functions" -Recurse -File -Filter $Filter))
{
Write-PSFMessage -Level Significant -Message " Executing $($file.Name)"
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru
foreach ($result in $results)
{
$totalRun += $result.TotalCount
$totalFailed += $result.FailedCount
$result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
$name = $_.Name
$testresults += [pscustomobject]@{
Describe = $_.Describe
Context = $_.Context
Name = "It $name"
Result = $_.Result
Message = $_.FailureMessage
}
}
}
}
}
$testresults | Sort-Object Describe, Context, Name, Result, Message | Format-List
if ($totalFailed -eq 0) { Write-PSFMessage -Level Critical -Message "All <c='em'>$totalRun</c> tests executed without a single failure!" }
else { Write-PSFMessage -Level Critical -Message "<c='em'>$totalFailed tests</c> out of <c='sub'>$totalRun</c> tests failed!" }
if ($totalFailed -gt 0)
{
throw "$totalFailed / $totalRun tests failed!"
}