-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhonoxsPSHelpers.tests.ps1
130 lines (125 loc) · 5.23 KB
/
PhonoxsPSHelpers.tests.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#Requires -Module @{ ModuleName = 'Pester'; ModuleVersion = '4.9.0' }
$ScriptPath = $PSScriptRoot
$ModuleName = ( Split-Path $PSCommandPath -Leaf ) -replace '\.tests\.ps1$'
$File = "$ModuleName.psd1"
$FilePath = Convert-Path (Join-Path $ScriptPath $File)
if ( !(test-path $FilePath ) ) { Write-Error "Failed to find file" }
$TestFolderPath = Join-Path $ScriptPath "Tests"
Describe "Importing module" -Tags "Module" {
Context "It should be no errors importing" {
It "Importing should not result with any issues" {
if ( !(Get-Module $modulename) ) {
{ Import-Module $ScriptPath -Force -ea stop -DisableNameChecking 4>$null 3>$null } | Should -Not -Throw
#$imported = $true
}
else {
#$imported = $false
Remove-Module $modulename -Force
{ Import-Module $ScriptPath -Force -ea stop -DisableNameChecking 4>$null 3>$null } | Should -Not -Throw
}
}
It "No errors should occour" {
$Error.Clear()
if ( !(Get-Module $modulename) ) {
Import-Module $ScriptPath -Force -DisableNameChecking 4>$null 3>$null
}
else {
Remove-Module $modulename -Force
Import-Module $ScriptPath -Force -ea stop -DisableNameChecking 4>$null 3>$null
}
prompt *>$null
Start-Sleep -m 50
Write-Warning "$($Error.Count)"
$Error.Count | Should -Be 0
}
}
# import required
$allCommands = Get-Command -module $modulename -CommandType Function
Context 'All functions have help' {
foreach ( $path in $allCommands ) {
It "SYNOPSIS should exist for $path" {
[bool](get-command $path -ShowCommandInfo | Where-Object Definition -match 'SYNOPSIS') | should -be "True"
}
}
}
Context 'All functions should have a test file each' {
$AllFiles = Get-ChildItem -File ( Join-Path $ScriptPath "Functions" ) | Select-Object -expand Name | ForEach-Object { $_ -replace '\.ps1', '.tests.ps1' }
foreach ( $path in $AllFiles ) {
$testFile = Join-Path $TestFolderPath $Path
$testFileExists = Test-Path $testFile
if ($testFileExists) {
It "Testfile exists for: $path" {
$testFileExists | Should -BeTrue
}
It "All tests should have Describe: $path" {
$testFile |should -FileContentMatch "Describe"
}
It "All tests should have tags: $path" {
$testFile |should -FileContentMatch "-Tags"
}
}else {
It "Testfile exists for: $path" {
Set-ItResult -Skipped -Because "they haven't been created yet"
}
}
}
}
Context 'Functions...' {
It "should exist atleast 18 functions" {
($allCommands.count) | should -BeGreaterOrEqual 18
}
}
}
Import-LocalizedData -BaseDirectory $ScriptPath -FileName "$modulename.psd1" -BindingVariable data
describe "Testing module manifest $ModuleName" {
Context "ModuleManifest" {
It "Should have a correct formated manifest" {
#$Manifest = (Test-ModuleManifest $FilePath)
#write-host -ForegroundColor Magenta $FilePath
#write-host -ForegroundColor Magenta $ModuleName
(Test-ModuleManifest $FilePath).Name | should -Be $ModuleName
}
It "Manifest should exist" {
$FilePath | Should -Exist
}
# WIP
It "Should have atleast 10 exported functions" {
Set-ItResult -Skipped -Because "feature has not been created"
$Manifest.ExportedFunctions.count | Should -BeGreaterThan 10
}
}
Context 'All NestedModules exists' {
# WIP To get performance
It "should include a NestedModules" {
Set-ItResult -Skipped -Because "feature has not been created"
#$countedFiles = (gci $PSScriptRoot -file -Recurse |? {$_.name -notmatch "$modulename"} ).count
#$data.NestedModules.count | Should -BeGreaterThan $countedFiles
}
foreach ( $path in $data.NestedModules ) {
It "Exists: $path" {
(Join-Path $PSScriptRoot $_) | should -Exist
}
}
}
Context 'All FileList exists'{
# WIP To get performance
It "should include a FileList" {
Set-ItResult -Skipped -Because "feature has not been created"
#$countedFiles = (Get-ChildItem $PSScriptRoot -file -Recurse |Where-Object {$_.name -notmatch "$modulename"} ).count
#$data.FileList.count | Should -BeGreaterThan $countedFiles
}
foreach ( $path in $data.FileList){
It "File should exist: $path" {
Set-ItResult -Skipped -Because "feature has not been created"
#(Join-Path $PSScriptRoot $_) | should -Exist
}
}
}
Context 'All ModuleListexists' {
foreach ( $path in $data.ModuleListexists ) {
It "$path should exist" {
(Join-Path $PSScriptRoot $_) | should -Exist
}
}
}
}