-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathBuild-Module.Tests.ps1
More file actions
88 lines (73 loc) · 3.53 KB
/
Build-Module.Tests.ps1
File metadata and controls
88 lines (73 loc) · 3.53 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
78
79
80
81
82
83
84
85
86
87
88
Describe 'Build-Module' {
BeforeAll {
# Import the module to make sure all functions are available
$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
# Set up temp directory
if ($IsWindows) {
$TempDir = $env:TEMP
} else {
$TempDir = '/tmp'
}
}
It 'Create New Module' {
$ModuleName = 'NewTestModule123456'
$Path = [io.path]::Combine($TempDir, 'Junk')
# lets remove junk first if it exists
$FullModulePath = [io.path]::Combine($Path, $ModuleName)
if (Test-Path -Path $FullModulePath) {
Remove-Item -Path $FullModulePath -Recurse -Force
}
$Exists = Test-Path -Path $FullModulePath
$Exists | Should -BeFalse
$Exists = Test-Path -Path $FullModulePath
$Exists | Should -BeFalse
# Handle module paths for different operating systems
if ($IsWindows) {
$DirectoryModulesCore = [io.path]::Combine([Environment]::GetFolderPath([Environment+SpecialFolder]::MyDocuments), 'PowerShell', 'Modules')
$DirectoryModules = [io.path]::Combine([Environment]::GetFolderPath([Environment+SpecialFolder]::MyDocuments), 'WindowsPowerShell', 'Modules')
} else {
$DirectoryModulesCore = [io.path]::Combine($env:HOME, '.local', 'share', 'powershell', 'Modules')
$DirectoryModules = $DirectoryModulesCore # On non-Windows, use the same path
}
$Desktop = [io.path]::Combine($DirectoryModules, $ModuleName)
$Core = [io.path]::Combine($DirectoryModulesCore, $ModuleName)
if (Test-Path -Path $Desktop) {
Remove-Item -Path $Desktop -Recurse -Force
}
if (Test-Path -Path $Core) {
Remove-Item -Path $Core -Recurse -Force
}
$Exists = Test-Path -Path $Desktop
$Exists | Should -BeFalse
$Exists = Test-Path -Path $Core
$Exists | Should -BeFalse
# lets create the path to folder as we create it deep in temp
New-Item -Path $Path -ItemType Directory -Force | Out-Null
# Lets build module
Build-Module -Path $Path -ModuleName $ModuleName
# lets see if module is created
$Exists = Test-Path -Path $FullModulePath
$Exists | Should -BeTrue
Get-ChildItem -Path $FullModulePath -Force | Format-Table -AutoSize | Out-String | Write-Host
# lets find if all files are copied
$FilesRelative = "$ModuleName.psd1", "$ModuleName.psm1", "CHANGELOG.MD", ".gitignore", "LICENSE", "README.MD"
foreach ($File in $FilesRelative) {
$FilePath = [io.path]::Combine($FullModulePath, $File)
$Exists = Test-Path -Path $FilePath
$Exists | Should -BeTrue
$Item = Get-Item -Path $FilePath -Force
$Item.Length | Should -BeGreaterThan 0
}
$FilesFullPath = [io.path]::Combine($FullModulePath, "Build", "Build-Module.ps1")
foreach ($File in $FilesFullPath) {
$Exists = Test-Path -Path $File
$Exists | Should -BeTrue
}
$Directories = "Build", "Examples", "Ignore", "Private", 'Public'
foreach ($Directory in $Directories) {
$Exists = Test-Path -Path ([io.path]::Combine($FullModulePath, $Directory)) -PathType Container
$Exists | Should -BeTrue
}
}
}