-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.ps1
65 lines (53 loc) · 2.08 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# requires -Module PowerShellGet, @{ ModuleName = "Pester"; ModuleVersion = "5.5.0"; MaximumVersion = "5.0" }
using namespace Microsoft.PackageManagement.Provider.Utility
using namespace System.Management.Automation
param(
[switch]$SkipScriptAnalyzer,
[switch]$CodeCoverage,
[switch]$HideSuccess,
[switch]$IncludeVSCodeMarker
)
Push-Location $PSScriptRoot
$ModuleName = "F7History"
# Disable default parameters during testing, just in case
$PSDefaultParameterValues += @{}
$PSDefaultParameterValues["Disabled"] = $true
# Find a built module in the Output dir
$FoundModule = Get-ChildItem .\Output\"$($ModuleName)\$($ModuleName).psd1"
Write-Host "Testing $FoundModule..."
if (!$FoundModule) {
throw "Can't find $($ModuleName).psd1 in output dir. Did you build the module?"
}
$Show = if ($HideSuccess) {
"Fails"
} else {
"All"
}
Remove-Module $ModuleName -ErrorAction Ignore -Force
$ModuleUnderTest = Import-Module $FoundModule.FullName -PassThru -Force -DisableNameChecking -Verbose:$false
Write-Host "Invoke-Pester for Module $($ModuleUnderTest) version $($ModuleUnderTest.Version)"
$MyOptions = @{
Run = @{ # Run configuration.
PassThru = $true # Return result object after finishing the test run.
}
}
$config = New-PesterConfiguration -Hashtable $MyOptions
$config.Output.Verbosity = "Detailed"
if ($CodeCoverage) {
$config.CodeCoverage.Enabled = $true
$config.CodeCoverage.OutputPath = "./coverage.xml"
# Get code coverage for the psm1 file to a coverage.xml that we can mess with later
#Invoke-Pester -Confi
# IncludeVSCodeMarker = $IncludeVSCodeMarker
# } -CodeCoverage $ModuleUnderTest.Path -CodeCoverageOutputFile ./coverage.xml -PassThru | Convert-CodeCoverage -SourceRoot ./Source
}
Invoke-Pester -Configuration $config
Write-Host
if (-not $SkipScriptAnalyzer) {
$path = Split-Path $ModuleUnderTest.Path -Parent
Write-Host "Invoke-ScriptAnalyzer for $path"
Invoke-ScriptAnalyzer $path -Recurse -Settings PSGallery
}
Pop-Location
# Re-enable default parameters after testing
$PSDefaultParameterValues["Disabled"] = $false