Skip to content

Commit eaf49f3

Browse files
committed
feat: Enhance test coverage for various modules by adding new test cases and improving existing ones
1 parent 12197e1 commit eaf49f3

11 files changed

Lines changed: 96 additions & 14 deletions

tests/private/build/BuildManifest.Tests.ps1

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,27 @@ Describe 'Build-Manifest' {
4242
$manifest.Description | Should -Be 'A module'
4343
}
4444

45-
It 'adds resources/ paths when CopyResourcesToModuleRoot is false' {
45+
It 'records resource manifest entries for CopyResourcesToModuleRoot=<CopyResourcesToModuleRoot>' -ForEach @(
46+
@{
47+
CopyResourcesToModuleRoot = $false
48+
ExpectedFormat = 'resources/MyFormat.Format.ps1xml'
49+
ExpectedType = 'resources/MyTypes.Types.ps1xml'
50+
}
51+
@{
52+
CopyResourcesToModuleRoot = $true
53+
ExpectedFormat = 'MyFormat.Format.ps1xml'
54+
ExpectedType = 'MyTypes.Types.ps1xml'
55+
}
56+
) {
57+
$script:ctx.CopyResourcesToModuleRoot = $CopyResourcesToModuleRoot
4658
Set-Content -Path (Join-Path $script:ctx.ResourcesDir 'MyFormat.Format.ps1xml') -Value '<x/>'
4759
Set-Content -Path (Join-Path $script:ctx.ResourcesDir 'MyTypes.Types.ps1xml') -Value '<x/>'
4860
Mock Get-NovaBuildProjectInfo { $script:ctx }
4961
Mock Assert-ManifestSchema {}
5062
Build-Manifest -ProjectInfo ([pscustomobject]@{})
5163
$manifest = Import-PowerShellDataFile -Path $script:ctx.ManifestFilePSD1
52-
($manifest.FormatsToProcess -join ',') | Should -Match 'resources'
53-
($manifest.TypesToProcess -join ',') | Should -Match 'resources'
54-
}
55-
56-
It 'adds bare filenames when CopyResourcesToModuleRoot is true' {
57-
$script:ctx.CopyResourcesToModuleRoot = $true
58-
Set-Content -Path (Join-Path $script:ctx.ResourcesDir 'MyFormat.Format.ps1xml') -Value '<x/>'
59-
Mock Get-NovaBuildProjectInfo { $script:ctx }
60-
Mock Assert-ManifestSchema {}
61-
Build-Manifest -ProjectInfo ([pscustomobject]@{})
62-
$manifest = Import-PowerShellDataFile -Path $script:ctx.ManifestFilePSD1
63-
$manifest.FormatsToProcess | Should -Be 'MyFormat.Format.ps1xml'
64+
$manifest.FormatsToProcess | Should -Be $ExpectedFormat
65+
$manifest.TypesToProcess | Should -Be $ExpectedType
6466
}
6567

6668
It 'sets Prerelease when version has a prerelease label' {

tests/private/cli/FormatNovaCliCommandResult.Tests.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ Describe 'Format-NovaCliCommandResult' {
5454
Format-NovaCliCommandResult -Command 'build' -Result 'raw' | Should -Be 'raw'
5555
}
5656

57+
It 'formats version update results for the bump command' {
58+
$result = [pscustomobject]@{Applied=$true;PreviousVersion='1.0.0';NewVersion='1.1.0';Label='minor';CommitCount=4}
59+
Format-NovaCliCommandResult -Command 'bump' -Result $result | Should -Be (Format-NovaCliVersionUpdateResult -Result $result)
60+
}
61+
5762
It 'passes through a structured result that does not match update or bump shapes' {
5863
$result = [pscustomobject]@{Custom = 'value'}
5964
Format-NovaCliCommandResult -Command 'package' -Result $result | Should -Be $result

tests/private/cli/ReadAwesomeStandardPrompt.Tests.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,23 @@ Describe 'Read-AwesomeStandardPrompt' {
1111
$hostUi | Add-Member -MemberType ScriptMethod -Name Prompt -Value {param($caption, $message, $fields) return [pscustomobject]@{Values = 'x'}}
1212
Read-AwesomeStandardPrompt -Ask @{} -HostUi $hostUi | Should -Be 'final'
1313
}
14+
15+
It 'writes the retry message before prompting again when validation fails once' {
16+
$script:promptCallCount = 0
17+
$hostUi = [pscustomobject]@{}
18+
$hostUi | Add-Member -MemberType ScriptMethod -Name Prompt -Value {
19+
param($caption, $message, $fields)
20+
$script:promptCallCount += 1
21+
return [pscustomobject]@{Attempt = $script:promptCallCount}
22+
}
23+
24+
Mock Test-AwesomePromptRequiresRetry {
25+
return $Response.Attempt -eq 1
26+
}
27+
Mock Write-AwesomePromptRetryMessage {}
28+
29+
Read-AwesomeStandardPrompt -Ask @{} -HostUi $hostUi | Should -Be 'final'
30+
$script:promptCallCount | Should -Be 2
31+
Should -Invoke Write-AwesomePromptRetryMessage -Times 1
32+
}
1433
}

tests/private/release/InitiateGitRepo.Tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ Describe 'New-InitiateGitRepo' {
3535
Mock Invoke-NovaGitCommand {throw 'kaboom'}
3636
{New-InitiateGitRepo -DirectoryPath $script:dir} | Should -Throw '*kaboom*'
3737
}
38+
39+
It 'writes a success verbose message when git init succeeds' {
40+
Mock Invoke-NovaGitCommand {return [pscustomobject]@{ExitCode=0; Output=@()}}
41+
$verbose = New-InitiateGitRepo -DirectoryPath $script:dir -Confirm:$false -Verbose 4>&1
42+
@($verbose | Where-Object Message -EQ 'Git repository initialized successfully').Count | Should -Be 1
43+
}
3844
}
3945

4046
Describe 'Get-NovaGitInitializationFailureMessage' {

tests/private/release/InvokeNovaVersionUpdateWorkflow.Tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ Describe 'Get-NovaVersionUpdateAdvisoryMessage' {
3434
}
3535
}
3636

37+
Describe 'Get-NovaVersionUpdateProjectFile' {
38+
It 'returns null when the workflow context has no ProjectInfo' {
39+
Get-NovaVersionUpdateProjectFile -WorkflowContext ([pscustomobject]@{Other = 1}) | Should -BeNullOrEmpty
40+
}
41+
}
42+
3743
Describe 'Get-NovaVersionUpdateResult' {
3844
It 'assembles a structured result' {
3945
$ctx = [pscustomobject]@{

tests/private/release/PublishNovaBuiltModule.Tests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,13 @@ Describe 'Publish-NovaBuiltModule' {
3838
Publish-NovaBuiltModule -ProjectInfo $script:project
3939
Should -Invoke Publish-NovaBuiltModuleToDirectory -Times 1 -ParameterFilter {$ModuleDirectoryPath -eq '/local/resolved'}
4040
}
41+
42+
It 'uses Get-NovaProjectInfo when ProjectInfo is not supplied' {
43+
Mock Get-NovaProjectInfo { return $script:project }
44+
Mock Publish-NovaBuiltModuleToDirectory {}
45+
Mock Resolve-NovaLocalPublishPath {return '/local/resolved'}
46+
Publish-NovaBuiltModule
47+
Should -Invoke Get-NovaProjectInfo -Times 1
48+
Should -Invoke Publish-NovaBuiltModuleToDirectory -Times 1 -ParameterFilter {$ProjectInfo -eq $script:project}
49+
}
4150
}

tests/private/shared/GetResourceFilePath.Tests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@ Describe 'Get-ResourceFilePath' {
3030

3131
{Get-ResourceFilePath -FileName 'Missing.json'} | Should -Throw
3232
}
33+
34+
It 'writes a verbose fallback message when project resource discovery throws' {
35+
Mock Get-NovaProjectInfo { throw 'no project context' }
36+
Mock Test-Path { return $true }
37+
38+
$output = Get-ResourceFilePath -FileName 'Schema.json' -Verbose 4>&1
39+
($output | Out-String) | Should -Match 'Project resource discovery unavailable'
40+
($output | Out-String) | Should -Match 'Schema.json'
41+
}
3342
}

tests/private/shared/ImportNovaBuiltModuleForCi.Tests.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,20 @@ Describe 'Import-NovaBuiltModuleForCi' {
3636

3737
{Import-NovaBuiltModuleForCi -ProjectRoot '/p'} | Should -Throw
3838
}
39+
40+
It 'refreshes the imported module when the built manifest exists' {
41+
$projectInfo = [pscustomobject]@{ProjectName = 'Demo'; OutputModuleDir = '/dist/Demo'}
42+
Mock Get-NovaBuiltModuleManifestPathForCi { return '/dist/Demo/Demo.psd1' }
43+
Mock Test-Path { return $true }
44+
Mock Get-Module { return @([pscustomobject]@{Name = 'Demo'}) }
45+
Mock Remove-Module {}
46+
Mock Import-Module { return 'imported-module' }
47+
48+
$result = Import-NovaBuiltModuleForCi -ProjectInfo $projectInfo
49+
50+
$result | Should -Be 'imported-module'
51+
Should -Invoke Get-Module -Times 1 -ParameterFilter { $Name -eq 'Demo' -and $All }
52+
Should -Invoke Remove-Module -Times 1
53+
Should -Invoke Import-Module -Times 1 -ParameterFilter { $Name -eq '/dist/Demo/Demo.psd1' -and $Force -and $Global -and $PassThru }
54+
}
3955
}

tests/public/InitializeNovaModule.Tests.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ Describe 'Initialize-NovaModule' {
2323
Initialize-NovaModule -Path '/tmp/x' -WhatIf
2424
$script:workflowCalled | Should -BeFalse
2525
}
26+
27+
It 'defaults Path from the current location when Path is omitted' {
28+
Initialize-NovaModule
29+
$script:ctxArgs.Path | Should -Be (Get-Location).Path
30+
}
2631
}

tests/public/UpdateNovaModuleVersion.TestSupport.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function Invoke-NovaVersionUpdateCiActivation {param($ProjectRoot, $Parameters,
22
return $script:ciActivation
33
}
44
function Get-NovaVersionUpdateWorkflowContext {param($ProjectRoot, [switch]$PreviewRelease, [switch]$ContinuousIntegrationRequested, [switch]$OverrideWarningRequested)
5-
$script:ctxArgs = @{Preview=[bool]$PreviewRelease; CI=[bool]$ContinuousIntegrationRequested; Override=[bool]$OverrideWarningRequested}
5+
$script:ctxArgs = @{ProjectRoot=$ProjectRoot; Preview=[bool]$PreviewRelease; CI=[bool]$ContinuousIntegrationRequested; Override=[bool]$OverrideWarningRequested}
66
return [pscustomobject]@{Target=$ProjectRoot; Action='Bump'}
77
}
88
function Invoke-NovaVersionUpdateWorkflow {param($WorkflowContext, [switch]$ShouldRun, [switch]$WhatIfEnabled)

0 commit comments

Comments
 (0)