|
| 1 | +# Requires -Module Pester |
| 2 | +Describe "New-ModuleTemplate" { |
| 3 | + |
| 4 | + BeforeEach { |
| 5 | + $root = Join-Path $env:TEMP ([guid]::NewGuid().ToString()) |
| 6 | + New-Item -ItemType Directory -Path $root | Out-Null |
| 7 | + Set-Variable -Name TempRoot -Value $root -Scope Local |
| 8 | + } |
| 9 | + |
| 10 | + It "Creates the core module scaffold" { |
| 11 | + $modulePath = Join-Path $TempRoot "TestModule" |
| 12 | + New-ModuleTemplate -Path $TempRoot -Name "TestModule" -NoGit |
| 13 | + |
| 14 | + Test-Path $modulePath | Should -Be $true |
| 15 | + Test-Path (Join-Path $modulePath "TestModule.psd1") | Should -Be $true |
| 16 | + Test-Path (Join-Path $modulePath "TestModule.psm1") | Should -Be $true |
| 17 | + Test-Path (Join-Path $modulePath "README.md") | Should -Be $true |
| 18 | + Test-Path (Join-Path $modulePath "CHANGELOG.md") | Should -Be $true |
| 19 | + Test-Path (Join-Path $modulePath "Public") | Should -Be $true |
| 20 | + Test-Path (Join-Path $modulePath "Private") | Should -Be $true |
| 21 | + } |
| 22 | + |
| 23 | + It "Throws when module exists and -Force is not used" { |
| 24 | + $modulePath = Join-Path $TempRoot "TestModule" |
| 25 | + New-Item -ItemType Directory -Path $modulePath | Out-Null |
| 26 | + |
| 27 | + { |
| 28 | + New-ModuleTemplate -Path $TempRoot -Name "TestModule" |
| 29 | + } | Should -Throw |
| 30 | + } |
| 31 | + |
| 32 | + It "Overwrites existing module when -Force is used" { |
| 33 | + $modulePath = Join-Path $TempRoot "TestModule" |
| 34 | + New-Item -ItemType Directory -Path $modulePath | Out-Null |
| 35 | + |
| 36 | + { |
| 37 | + New-ModuleTemplate -Path $TempRoot -Name "TestModule" -Force -NoGit |
| 38 | + } | Should -Not -Throw |
| 39 | + |
| 40 | + Test-Path (Join-Path $modulePath "TestModule.psd1") | Should -Be $true |
| 41 | + } |
| 42 | + |
| 43 | + It "Creates a minimal scaffold when -Minimal is used" { |
| 44 | + $modulePath = Join-Path $TempRoot "MiniModule" |
| 45 | + New-ModuleTemplate -Path $TempRoot -Name "MiniModule" -Minimal -NoGit |
| 46 | + |
| 47 | + # Core files exist |
| 48 | + Test-Path (Join-Path $modulePath "MiniModule.psd1") | Should -Be $true |
| 49 | + Test-Path (Join-Path $modulePath "MiniModule.psm1") | Should -Be $true |
| 50 | + Test-Path (Join-Path $modulePath "README.md") | Should -Be $true |
| 51 | + Test-Path (Join-Path $modulePath "CHANGELOG.md") | Should -Be $true |
| 52 | + |
| 53 | + # Optional components do NOT exist |
| 54 | + Test-Path (Join-Path $modulePath "Tests") | Should -Be $false |
| 55 | + Test-Path (Join-Path $modulePath "Analyzer") | Should -Be $false |
| 56 | + Test-Path (Join-Path $modulePath "Docs") | Should -Be $false |
| 57 | + Test-Path (Join-Path $modulePath "Scripts") | Should -Be $false |
| 58 | + } |
| 59 | + |
| 60 | + It "Respects NoTests, NoDocs, NoAnalyzer, and NoScripts switches" { |
| 61 | + $modulePath = Join-Path $TempRoot "SwitchModule" |
| 62 | + |
| 63 | + New-ModuleTemplate -Path $TempRoot -Name "SwitchModule" ` |
| 64 | + -NoTests -NoDocs -NoAnalyzer -NoScripts -NoGit |
| 65 | + |
| 66 | + Test-Path (Join-Path $modulePath "Tests") | Should -Be $false |
| 67 | + Test-Path (Join-Path $modulePath "Docs") | Should -Be $false |
| 68 | + Test-Path (Join-Path $modulePath "Analyzer") | Should -Be $false |
| 69 | + Test-Path (Join-Path $modulePath "Scripts") | Should -Be $false |
| 70 | + } |
| 71 | + |
| 72 | + It "Initializes Git when not disabled" { |
| 73 | + $modulePath = Join-Path $TempRoot "GitModule" |
| 74 | + |
| 75 | + New-ModuleTemplate -Path $TempRoot -Name "GitModule" |
| 76 | + |
| 77 | + Test-Path (Join-Path $modulePath ".git") | Should -Be $true |
| 78 | + Test-Path (Join-Path $modulePath ".gitignore") | Should -Be $true |
| 79 | + Test-Path (Join-Path $modulePath ".gitattributes") | Should -Be $true |
| 80 | + } |
| 81 | + |
| 82 | + It "Skips Git initialization when -NoGit is used" { |
| 83 | + $modulePath = Join-Path $TempRoot "NoGitModule" |
| 84 | + |
| 85 | + New-ModuleTemplate -Path $TempRoot -Name "NoGitModule" -NoGit |
| 86 | + |
| 87 | + Test-Path (Join-Path $modulePath ".git") | Should -Be $false |
| 88 | + } |
| 89 | +} |
0 commit comments