Skip to content

Commit a35799b

Browse files
author
Nathanael BOT
committed
test: add coverage for Build-PSBuildMarkdown
1 parent 5e25263 commit a35799b

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
Describe 'Build-PSBuildMarkdown' {
2+
BeforeAll {
3+
. "$PSScriptRoot/../PowerShellBuild/Public/Build-PSBuildMarkdown.ps1"
4+
}
5+
6+
BeforeEach {
7+
$script:LocalizedData = @{
8+
NoCommandsExported = 'No commands exported.'
9+
FailedToGenerateMarkdownHelp = 'Failed to generate markdown help: {0}'
10+
}
11+
12+
$script:newMarkdownParams = $null
13+
$script:updateMarkdownParams = @()
14+
}
15+
16+
It 'warns and exits when module exports no commands' {
17+
Mock Import-Module {
18+
[pscustomobject]@{ ExportedCommands = @() }
19+
}
20+
Mock Write-Warning {}
21+
Mock New-MarkdownHelp {}
22+
Mock Remove-Module {}
23+
24+
Build-PSBuildMarkdown \
25+
-ModulePath '/tmp/module' \
26+
-ModuleName 'MyModule' \
27+
-DocsPath '/tmp/docs' \
28+
-Locale 'en-US' \
29+
-Overwrite:$false \
30+
-AlphabeticParamsOrder:$true \
31+
-ExcludeDontShow:$false \
32+
-UseFullTypeName:$false
33+
34+
Should -Invoke Write-Warning -Times 1
35+
Should -Invoke New-MarkdownHelp -Times 0
36+
Should -Invoke Remove-Module -Times 1 -ParameterFilter { $Name -eq 'MyModule' }
37+
}
38+
39+
It 'generates markdown help without force when overwrite is false' {
40+
Mock Import-Module {
41+
[pscustomobject]@{ ExportedCommands = @{ Test = 'Test-Command' } }
42+
}
43+
Mock Test-Path { $false }
44+
Mock New-Item {}
45+
Mock Get-ChildItem { @() }
46+
Mock New-MarkdownHelp {
47+
$script:newMarkdownParams = $PSBoundParameters
48+
}
49+
Mock Remove-Module {}
50+
51+
Build-PSBuildMarkdown \
52+
-ModulePath '/tmp/module' \
53+
-ModuleName 'MyModule' \
54+
-DocsPath '/tmp/docs' \
55+
-Locale 'en-US' \
56+
-Overwrite:$false \
57+
-AlphabeticParamsOrder:$true \
58+
-ExcludeDontShow:$true \
59+
-UseFullTypeName:$false
60+
61+
Should -Invoke New-Item -Times 1 -ParameterFilter { $Path -eq '/tmp/docs' -and $ItemType -eq 'Directory' }
62+
$script:newMarkdownParams.Module | Should -Be 'MyModule'
63+
$script:newMarkdownParams.Locale | Should -Be 'en-US'
64+
$script:newMarkdownParams.OutputFolder | Should -Be ([IO.Path]::Combine('/tmp/docs', 'en-US'))
65+
$script:newMarkdownParams.ErrorAction | Should -Be 'SilentlyContinue'
66+
$script:newMarkdownParams.ContainsKey('Force') | Should -BeFalse
67+
}
68+
69+
It 'updates existing markdown and forces generation when overwrite is true' {
70+
Mock Import-Module {
71+
[pscustomobject]@{ ExportedCommands = @{ Test = 'Test-Command' } }
72+
}
73+
Mock Test-Path { $true }
74+
Mock Get-ChildItem {
75+
@('existing.md')
76+
} -ParameterFilter { $LiteralPath -eq '/tmp/docs' -and $Filter -eq '*.md' -and $Recurse }
77+
Mock Get-ChildItem {
78+
@([pscustomobject]@{ FullName = '/tmp/docs/en-US' })
79+
} -ParameterFilter { $LiteralPath -eq '/tmp/docs' -and $Directory }
80+
Mock Update-MarkdownHelp {
81+
$script:updateMarkdownParams += $PSBoundParameters
82+
}
83+
Mock New-MarkdownHelp {
84+
$script:newMarkdownParams = $PSBoundParameters
85+
}
86+
Mock Remove-Module {}
87+
88+
Build-PSBuildMarkdown \
89+
-ModulePath '/tmp/module' \
90+
-ModuleName 'MyModule' \
91+
-DocsPath '/tmp/docs' \
92+
-Locale 'en-US' \
93+
-Overwrite:$true \
94+
-AlphabeticParamsOrder:$false \
95+
-ExcludeDontShow:$false \
96+
-UseFullTypeName:$true
97+
98+
Should -Invoke Update-MarkdownHelp -Times 1 -ParameterFilter { $Path -eq '/tmp/docs/en-US' }
99+
$script:newMarkdownParams.ContainsKey('Force') | Should -BeTrue
100+
$script:newMarkdownParams.Force | Should -BeTrue
101+
$script:newMarkdownParams.ContainsKey('ErrorAction') | Should -BeFalse
102+
}
103+
}

0 commit comments

Comments
 (0)