-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathBuild-PSBuildUpdatableHelp.tests.ps1
More file actions
87 lines (71 loc) · 3.3 KB
/
Build-PSBuildUpdatableHelp.tests.ps1
File metadata and controls
87 lines (71 loc) · 3.3 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
Describe 'Build-PSBuildUpdatableHelp' {
BeforeAll {
. "$PSScriptRoot/../PowerShellBuild/Public/Build-PSBuildUpdatableHelp.ps1"
}
BeforeEach {
$script:LocalizedData = @{
MakeCabNotAvailable = 'MakeCab not available on this platform.'
DirectoryAlreadyExists = 'Directory {0} already exists.'
}
$script:ModuleName = 'PSBuildModule'
$script:moduleOutDir = '/tmp/module-out'
$script:newCabCalls = @()
}
It 'warns and exits early when running on non-Windows hosts' {
Mock Write-Warning {}
Mock Get-ChildItem { throw 'should not be called' }
Mock New-Item {}
Mock New-ExternalHelpCab {}
$script:IsWindows = $false
Build-PSBuildUpdatableHelp -DocsPath '/tmp/docs' -OutputPath '/tmp/out'
Should -Invoke Write-Warning -Times 1 -ParameterFilter { $Message -eq 'MakeCab not available on this platform.' }
Should -Invoke Get-ChildItem -Times 0
Should -Invoke New-ExternalHelpCab -Times 0
}
It 'creates output folder and generates one cab per locale on Windows' {
Mock Test-Path { $false }
Mock New-Item {}
Mock Get-ChildItem {
@(
[pscustomobject]@{ Name = 'en-US' },
[pscustomobject]@{ Name = 'fr-FR' }
)
} -ParameterFilter { $Path -eq '/tmp/docs' -and $Directory }
Mock New-ExternalHelpCab {
$script:newCabCalls += $PSBoundParameters
}
$script:IsWindows = $true
Build-PSBuildUpdatableHelp -DocsPath '/tmp/docs' -OutputPath '/tmp/out' -Module 'MyModule'
Should -Invoke New-Item -Times 1 -ParameterFilter { $Path -eq '/tmp/out' -and $ItemType -eq 'Directory' }
$script:newCabCalls.Count | Should -Be 2
$script:newCabCalls[0].CabFilesFolder | Should -Be ([IO.Path]::Combine('/tmp/module-out', 'en-US'))
$script:newCabCalls[0].LandingPagePath | Should -Be ([IO.Path]::Combine('/tmp/docs', 'en-US', 'MyModule.md'))
$script:newCabCalls[0].OutputFolder | Should -Be '/tmp/out'
$script:newCabCalls[1].CabFilesFolder | Should -Be ([IO.Path]::Combine('/tmp/module-out', 'fr-FR'))
$script:newCabCalls[1].LandingPagePath | Should -Be ([IO.Path]::Combine('/tmp/docs', 'fr-FR', 'MyModule.md'))
$script:newCabCalls[1].OutputFolder | Should -Be '/tmp/out'
}
It 'cleans existing output folder before generating cabs on Windows' {
Mock Test-Path { $true }
Mock Get-ChildItem {
@(
[pscustomobject]@{ Name = 'en-US' }
)
} -ParameterFilter { $Path -eq '/tmp/docs' -and $Directory }
Mock Get-ChildItem {
@(
[pscustomobject]@{ FullName = '/tmp/out/existing.cab' }
)
} -ParameterFilter { $Path -eq '/tmp/out' }
Mock Remove-Item {}
Mock New-ExternalHelpCab {
$script:newCabCalls += $PSBoundParameters
}
Mock Write-Verbose {}
$script:IsWindows = $true
Build-PSBuildUpdatableHelp -DocsPath '/tmp/docs' -OutputPath '/tmp/out' -Module 'MyModule'
Should -Invoke Write-Verbose -Times 1
Should -Invoke Remove-Item -Times 1 -ParameterFilter { $Recurse -and $Force }
Should -Invoke New-ExternalHelpCab -Times 1
}
}