forked from PoshCode/ModuleBuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ps1
48 lines (41 loc) · 1.74 KB
/
test.ps1
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
#requires -Module ModuleBuilder, PowerShellGet, @{ ModuleName = "Pester"; ModuleVersion = "4.10.1"; MaximumVersion = "4.999" }
using namespace Microsoft.PackageManagement.Provider.Utility
using namespace System.Management.Automation
param(
[switch]$SkipScriptAnalyzer,
[switch]$SkipCodeCoverage,
[switch]$HideSuccess,
[switch]$IncludeVSCodeMarker
)
Push-Location $PSScriptRoot
$ModuleName = "ModuleBuilder"
# Disable default parameters during testing, just in case
$PSDefaultParameterValues += @{}
$PSDefaultParameterValues["Disabled"] = $true
$Show = if ($HideSuccess) {
"Fails"
} else {
"All"
}
Remove-Module $ModuleName -ErrorAction Ignore -Force
$FoundModule = Get-ChildItem [0-9]*, Modules/ModuleBuilder/[0-9]* -Directory | Sort-Object { $_.Name -as [SemanticVersion[]] } |
Select-Object -Last 1 -Ov Version |
Get-ChildItem -Filter "$($ModuleName).psd1"
$ModuleUnderTest = Import-Module $FoundModule.FullName -PassThru -Force -DisableNameChecking -Verbose:$false
Write-Host "Invoke-Pester for Module $($ModuleUnderTest) version $($ModuleUnderTest.Version)"
if (-not $SkipCodeCoverage) {
# Get code coverage for the psm1 file to a coverage.xml that we can mess with later
Invoke-Pester ./Tests -Show $Show -PesterOption @{
IncludeVSCodeMarker = $IncludeVSCodeMarker
} -CodeCoverage $ModuleUnderTest.Path -CodeCoverageOutputFile ./coverage.xml -PassThru |
Convert-CodeCoverage -SourceRoot ./Source
} else {
Invoke-Pester ./Tests -Show $Show -PesterOption @{ IncludeVSCodeMarker = $IncludeVSCodeMarker }
}
Write-Host
if (-not $SkipScriptAnalyzer) {
Invoke-ScriptAnalyzer $ModuleUnderTest.Path
}
Pop-Location
# Re-enable default parameters after testing
$PSDefaultParameterValues["Disabled"] = $false