-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathModuleTestingFunctions.Tests.ps1
More file actions
68 lines (57 loc) · 2.74 KB
/
ModuleTestingFunctions.Tests.ps1
File metadata and controls
68 lines (57 loc) · 2.74 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
Describe "Module Testing Functions" {
BeforeAll {
# Clean up any existing module instances first
Get-Module PSPublishModule | Remove-Module -Force -ErrorAction SilentlyContinue
# Import the module fresh
$moduleManifest = if ($env:PSPUBLISHMODULE_TEST_MANIFEST_PATH) { $env:PSPUBLISHMODULE_TEST_MANIFEST_PATH } else { Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath '..') -ChildPath 'PSPublishModule.psd1' }
Import-Module $moduleManifest -Force
}
AfterAll {
# Clean up after tests
Get-Module PSPublishModule | Remove-Module -Force -ErrorAction SilentlyContinue
}
Context "Get-ModuleInformation" {
It "Should retrieve module information correctly" {
$result = Get-ModuleInformation -Path (Join-Path -Path $PSScriptRoot -ChildPath '..')
$result | Should -Not -BeNullOrEmpty
$result.ModuleName | Should -Be 'PSPublishModule'
$result.ModuleVersion | Should -Not -BeNullOrEmpty
$result.ManifestPath | Should -Match '\.psd1$'
$result.RequiredModules | Should -Not -BeNullOrEmpty
}
It "Should throw error for invalid path" {
$invalidPath = Join-Path -Path $TestDrive -ChildPath 'NonExistentPath'
{ Get-ModuleInformation -Path $invalidPath } | Should -Throw
}
}
Context "Invoke-ModuleTestSuite" {
BeforeAll {
$script:moduleTestSuiteResult = $null
$script:moduleTestSuiteException = $null
$invokeParams = @{
ProjectPath = (Join-Path -Path $PSScriptRoot -ChildPath '..')
SkipDependencies = $true
SkipImport = $true
OutputFormat = 'Minimal'
PassThru = $true
TimeoutSeconds = 600
TestPath = [IO.Path]::Combine($PSScriptRoot, '..', 'Tests', 'Build-Module.Tests.ps1')
}
try {
$script:moduleTestSuiteResult = Invoke-ModuleTestSuite @invokeParams
} catch {
$script:moduleTestSuiteException = $_
}
}
It "Should execute complete test suite successfully" {
$script:moduleTestSuiteException | Should -BeNullOrEmpty
}
It "Should handle invalid project path gracefully" {
$invalidProjectPath = Join-Path -Path $TestDrive -ChildPath 'NonExistentProjectPath'
{ Invoke-ModuleTestSuite -ProjectPath $invalidProjectPath -SkipDependencies -SkipImport -OutputFormat Minimal } | Should -Throw
}
It "Should return test results when PassThru is specified" {
$script:moduleTestSuiteResult | Should -Not -BeNullOrEmpty
}
}
}