-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathPSWriteOffice.Tests.ps1
More file actions
77 lines (71 loc) · 2.88 KB
/
PSWriteOffice.Tests.ps1
File metadata and controls
77 lines (71 loc) · 2.88 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
param(
[string] $ModulePath = $PSScriptRoot,
[string] $TestsPath = "$PSScriptRoot\Tests",
[switch] $SkipDependencyInstall
)
$ResolvedModulePath = (Resolve-Path -Path $ModulePath).Path
$PrimaryModule = Get-ChildItem -Path $ResolvedModulePath -Filter '*.psd1' -Recurse -ErrorAction SilentlyContinue -Depth 1
if (-not $PrimaryModule) {
throw "Path $ResolvedModulePath doesn't contain PSD1 files. Failing tests."
}
if ($PrimaryModule.Count -ne 1) {
throw 'More than one PSD1 files detected. Failing tests.'
}
$ModuleName = $PrimaryModule.BaseName
$PSDInformation = Import-PowerShellDataFile -Path $PrimaryModule.FullName
$RequiredModules = @(
'Pester'
'PSWriteColor'
if ($PSDInformation.RequiredModules) {
$PSDInformation.RequiredModules
}
)
if (-not $SkipDependencyInstall) {
foreach ($Module in $RequiredModules) {
if ($Module -eq 'PSWriteOffice') {
continue
}
if ($Module -is [System.Collections.IDictionary]) {
$Exists = Get-Module -ListAvailable -Name $Module.ModuleName
if (-not $Exists) {
Write-Warning "$ModuleName - Downloading $($Module.ModuleName) from PSGallery"
Install-Module -Name $Module.ModuleName -Force -SkipPublisherCheck
}
} else {
$Exists = Get-Module -ListAvailable $Module -ErrorAction SilentlyContinue
if (-not $Exists) {
Install-Module -Name $Module -Force -SkipPublisherCheck
}
}
}
}
Write-Color 'ModuleName: ', $ModuleName, ' Version: ', $PSDInformation.ModuleVersion -Color Yellow, Green, Yellow, Green -LinesBefore 2
Write-Color 'PowerShell Version: ', $PSVersionTable.PSVersion -Color Yellow, Green
Write-Color 'PowerShell Edition: ', $PSVersionTable.PSEdition -Color Yellow, Green
Write-Color 'Required modules: ' -Color Yellow
foreach ($Module in $PSDInformation.RequiredModules) {
if ($Module -is [System.Collections.IDictionary]) {
Write-Color ' [>] ', $Module.ModuleName, ' Version: ', $Module.ModuleVersion -Color Yellow, Green, Yellow, Green
} else {
Write-Color ' [>] ', $Module -Color Yellow, Green
}
}
Write-Color
try {
Import-Module $PrimaryModule.FullName -Force -Global -ErrorAction Stop
Import-Module Pester -Force -ErrorAction Stop
} catch {
throw "Failed to import module $ModuleName"
}
$env:PSWRITEOFFICE_MODULE_MANIFEST = $PrimaryModule.FullName
$Configuration = [PesterConfiguration]::Default
$Configuration.Run.Path = $TestsPath
$Configuration.Run.Exit = $true
$Configuration.Should.ErrorAction = 'Continue'
$Configuration.CodeCoverage.Enabled = $false
$Configuration.Output.Verbosity = 'Detailed'
$Result = Invoke-Pester -Configuration $Configuration
#$result = Invoke-Pester -Script $PSScriptRoot\Tests -Verbose -Output Detailed #-EnableExit
if ($Result.FailedCount -gt 0) {
throw "$($Result.FailedCount) tests failed."
}