|
1 | 1 | # Requires -Module Pester |
2 | 2 | Describe "New-DocumentationScripts" { |
3 | 3 |
|
4 | | - It "Creates documentation scripts" { |
5 | | - $temp = Join-Path $env:TEMP ([guid]::NewGuid().ToString()) "TestModule" |
6 | | - New-Item -ItemType Directory -Path $temp | Out-Null |
| 4 | + BeforeAll { |
| 5 | + # Import the module under test |
| 6 | + $moduleRoot = Join-Path $PSScriptRoot '..' | Resolve-Path |
| 7 | + $manifest = Join-Path $moduleRoot 'NewModuleTemplate.psd1' |
| 8 | + Import-Module $manifest -Force |
| 9 | + } |
| 10 | + |
| 11 | + BeforeEach { |
| 12 | + # Fresh temp directory for each test |
| 13 | + $guid = [guid]::NewGuid().ToString() |
| 14 | + $root = Join-Path $env:TEMP $guid |
| 15 | + |
| 16 | + New-Item -ItemType Directory -Path $root | Out-Null |
| 17 | + |
| 18 | + Set-Variable -Name TempRoot -Value $root -Scope Local |
| 19 | + } |
| 20 | + |
| 21 | + It "Creates the Scripts directory and documentation update script" { |
| 22 | + $result = New-DocumentationScripts -ModulePath $TempRoot -Name "TestModule" |
| 23 | + |
| 24 | + $scriptsDir = Join-Path $TempRoot "Scripts" |
| 25 | + $expectedPath = Join-Path $scriptsDir "Update-ModuleDocumentation.ps1" |
| 26 | + |
| 27 | + # Directory exists |
| 28 | + Test-Path $scriptsDir | Should -Be $true |
| 29 | + |
| 30 | + # Script exists |
| 31 | + Test-Path $expectedPath | Should -Be $true |
| 32 | + |
| 33 | + # Function returns correct path |
| 34 | + $result | Should -Be $expectedPath |
| 35 | + } |
| 36 | + |
| 37 | + It "Replaces __MODULE_NAME__ correctly inside the script" { |
| 38 | + $path = New-DocumentationScripts -ModulePath $TempRoot -Name "TestModule" |
| 39 | + $lines = Get-Content $path |
| 40 | + |
| 41 | + # Script should import PlatyPS |
| 42 | + $lines | Should -Contain "Import-Module PlatyPS -ErrorAction Stop" |
| 43 | + |
| 44 | + # Script should import the module manifest using the correct name |
| 45 | + $lines | Should -Contain 'Import-Module "$PSScriptRoot\..\TestModule.psd1" -Force' |
| 46 | + |
| 47 | + # Script should call New-MarkdownHelp with the correct module name |
| 48 | + $lines | Should -Contain 'New-MarkdownHelp -Module TestModule -OutputFolder "$PSScriptRoot\..\Docs\" -WithModulePage -Force' |
| 49 | + } |
| 50 | + |
| 51 | + It "Is idempotent and overwrites the script cleanly" { |
| 52 | + # First write |
| 53 | + New-DocumentationScripts -ModulePath $TempRoot -Name "TestModule" |
7 | 54 |
|
8 | | - New-DocumentationScripts -Name "TestModule" -ModulePath $temp |
| 55 | + # Second write should not throw |
| 56 | + { |
| 57 | + New-DocumentationScripts -ModulePath $TempRoot -Name "TestModule" |
| 58 | + } | Should -Not -Throw |
9 | 59 |
|
10 | | - Test-Path "$temp\Scripts\Update-ModuleDocumentation.ps1" | Should Be $true |
| 60 | + # Script still contains correct module name |
| 61 | + $lines = Get-Content (Join-Path $TempRoot "Scripts\Update-ModuleDocumentation.ps1") |
| 62 | + $lines | Should -Contain 'New-MarkdownHelp -Module TestModule -OutputFolder "$PSScriptRoot\..\Docs\" -WithModulePage -Force' |
11 | 63 | } |
12 | 64 | } |
0 commit comments