Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Sep 1, 2024
1 parent e0e8676 commit 63b0028
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions source/Public/Invoke-PesterJob.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ function Invoke-PesterJob
}
}

# TODO: Move the scriptblock to a private function so it can be unit tested
Start-Job -ScriptBlock {
[CmdletBinding()]
param
Expand Down
42 changes: 40 additions & 2 deletions tests/Unit/Public/Invoke-PesterJob.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Describe 'Invoke-PesterJob' {
}

Mock -CommandName Write-Information
Mock -CommandName Get-Module
Mock -CommandName Start-Job -MockWith { return $mockJob }
Mock -CommandName Receive-Job
Mock -CommandName Get-Location -MockWith { return @{ Path = Join-Path -Path $TestDrive -ChildPath 'MockPath' } }
Expand All @@ -72,6 +71,10 @@ Describe 'Invoke-PesterJob' {
}

Context 'When passing invalid parameter values' {
BeforeAll {
Mock -CommandName Get-Module
}

It 'Should throw error if BuildScriptPath does not exist' {
Mock -CommandName Test-Path -MockWith { return $false }

Expand Down Expand Up @@ -120,6 +123,7 @@ Describe 'Invoke-PesterJob' {

Context 'When using Pester v4' {
BeforeAll {
Mock -CommandName Get-Module -MockWith { return @{ Version = [version] '4.10.1' } }
Mock -CommandName Get-ModuleVersion -MockWith { return '4.10.1' }
Mock -CommandName Import-Module -MockWith { return @{ Version = [version]'4.10.1' } }
}
Expand All @@ -132,6 +136,28 @@ Describe 'Invoke-PesterJob' {
}
}

Context 'When passing RootPath parameter' {
It 'Should use passed RootPath' {
$params = @{
Path = Join-Path -Path $TestDrive -ChildPath 'MockPath/tests'
RootPath = $TestDrive
}

Invoke-PesterJob @params
}
}

Context 'When passing Tag parameter' {
It 'Should use passed RootPath' {
$params = @{
Path = Join-Path -Path $TestDrive -ChildPath 'MockPath/tests'
Tag = 'Unit'
}

Invoke-PesterJob @params
}
}

Context 'When changing output verbosity levels' {
It 'Should set Output verbosity to Detailed by default' {
$params = @{
Expand Down Expand Up @@ -228,6 +254,7 @@ Describe 'Invoke-PesterJob' {

Context 'When using Pester v5' {
BeforeAll {
Mock -CommandName Get-Module -MockWith { return @{ Version = [version] '5.4.0' } }
Mock -CommandName Get-ModuleVersion -MockWith { return '5.4.0' }
Mock -CommandName Import-Module -MockWith { return @{ Version = [version] '5.4.0' } }
}
Expand All @@ -243,14 +270,25 @@ Describe 'Invoke-PesterJob' {
Context 'When passing RootPath parameter' {
It 'Should use passed RootPath' {
$params = @{
Path = Join-Path -Path $TestDrive -ChildPath 'MockPath/tests'
Path = Join-Path -Path $TestDrive -ChildPath 'MockPath/tests'
RootPath = $TestDrive
}

Invoke-PesterJob @params
}
}

Context 'When passing Tag parameter' {
It 'Should use passed RootPath' {
$params = @{
Path = Join-Path -Path $TestDrive -ChildPath 'MockPath/tests'
Tag = 'Unit'
}

Invoke-PesterJob @params
}
}

Context 'When changing output verbosity levels' {
It 'Should set Output verbosity to Detailed by default' {
$params = @{
Expand Down

0 comments on commit 63b0028

Please sign in to comment.