diff --git a/powershell/tests/functions/Invoke-MtPackGitHubRequest.Tests.ps1 b/powershell/tests/functions/Invoke-MtPackGitHubRequest.Tests.ps1 index edba6469da..fc0f702b60 100644 --- a/powershell/tests/functions/Invoke-MtPackGitHubRequest.Tests.ps1 +++ b/powershell/tests/functions/Invoke-MtPackGitHubRequest.Tests.ps1 @@ -1,4 +1,4 @@ -BeforeAll { +BeforeAll { Import-Module "$PSScriptRoot/../../Maester.psd1" -Force $script:savedGhToken = $env:GH_TOKEN diff --git a/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 b/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 index dbd4ccc6fb..4d8197c5e6 100644 --- a/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 @@ -214,7 +214,7 @@ Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policy } Mock -ModuleName Maester Get-MtSetting { return $null } - InModuleScope Maester -Parameters @{ C = $config } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue + InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue } It 'Should pass when a group is excluded from all policies (auto-detected)' { @@ -223,7 +223,7 @@ Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policy } Mock -ModuleName Maester Get-MtSetting { return $null } - InModuleScope Maester -Parameters @{ C = $config } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue + InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue } } @@ -469,7 +469,7 @@ # Returns $false because Agent Identity policies don't apply to users and are filtered out # When all policies are filtered out, there are no policies to check, so no emergency access is detected - InModuleScope Maester -Parameters @{ C = $config } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeFalse + InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeFalse } It 'Should return false (no emergency access detected) when only a Service Principal policy exists (which should be ignored)' { @@ -480,7 +480,7 @@ # Returns $false because Service Principal policies don't apply to users and are filtered out # When all policies are filtered out, there are no policies to check, so no emergency access is detected - InModuleScope Maester -Parameters @{ C = $config } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeFalse + InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeFalse } It 'Should only check user-targeted policies when both Agent Identity and user policies exist' { @@ -493,7 +493,7 @@ Mock -ModuleName Maester Get-MtSetting { return $null } # Should pass because the Agent Identity policy is ignored and the user policy has exclusions - InModuleScope Maester -Parameters @{ C = $config } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue + InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue } } } diff --git a/powershell/tests/pester.ps1 b/powershell/tests/pester.ps1 index 0b9bce98f2..3edcf6450f 100644 --- a/powershell/tests/pester.ps1 +++ b/powershell/tests/pester.ps1 @@ -140,34 +140,34 @@ if ($testFiles.Count -eq 0) { #region Combined single-run mode (required for coherent coverage data) # When coverage is enabled, all test files are passed to a single Invoke-Pester call so Pester can # produce one consolidated JaCoCo report. - $config = New-PesterConfiguration - $config.TestResult.Enabled = $true + $pesterConfig = New-PesterConfiguration + $pesterConfig.TestResult.Enabled = $true $coverageOutputPath = Join-Path $resultRoot "CodeCoverage.xml" - $config.CodeCoverage.Enabled = $true - $config.CodeCoverage.OutputFormat = 'JaCoCo' - $config.CodeCoverage.OutputPath = $coverageOutputPath + $pesterConfig.CodeCoverage.Enabled = $true + $pesterConfig.CodeCoverage.OutputFormat = 'JaCoCo' + $pesterConfig.CodeCoverage.OutputPath = $coverageOutputPath # Scope coverage to module source directories only (exclude tests/). - $config.CodeCoverage.Path = @( + $pesterConfig.CodeCoverage.Path = @( (Resolve-Path "$PSScriptRoot\..\public").Path, (Resolve-Path "$PSScriptRoot\..\internal").Path ) - $config.CodeCoverage.RecursePaths = $true + $pesterConfig.CodeCoverage.RecursePaths = $true # Profiler-based coverage. With breakpoints on every line of the module the coverage run took ten # times as long as the other runs, as the tests run the engine end to end many times. - $config.CodeCoverage.UseBreakpoints = $false + $pesterConfig.CodeCoverage.UseBreakpoints = $false Write-PSFMessage -Level Important -Message "Code coverage enabled. Output: $coverageOutputPath" Write-PSFMessage -Level Important -Message "Running $($testFiles.Count) test files in combined coverage run" - $config.TestResult.OutputPath = Join-Path $resultRoot "TEST-Coverage.xml" - $config.TestResult.OutputFormat = "JUnitXml" - $config.Run.Path = [string[]]$testFiles.FullName - $config.Run.PassThru = $true - $config.Output.Verbosity = $Output - $result = Invoke-Pester -Configuration $config - - $totalRun += $result.TotalCount - $totalFailed += $result.FailedCount + $result.FailedContainersCount - foreach ($test in $result.Tests) { + $pesterConfig.TestResult.OutputPath = Join-Path $resultRoot "TEST-Coverage.xml" + $pesterConfig.TestResult.OutputFormat = "JUnitXml" + $pesterConfig.Run.Path = [string[]]$testFiles.FullName + $pesterConfig.Run.PassThru = $true + $pesterConfig.Output.Verbosity = $Output + $pesterRun = Invoke-Pester -Configuration $pesterConfig + + $totalRun += $pesterRun.TotalCount + $totalFailed += $pesterRun.FailedCount + $pesterRun.FailedContainersCount + foreach ($test in $pesterRun.Tests) { if ($test.Result -notin 'Passed', 'Skipped') { $null = $testresults.Add([pscustomobject]@{ Block = $test.Block.ExpandedName