This was working before Pester 5.3.0 but now it seems broken and I do not know why it has stopped working. The idea of this tests is to check to see if counters have been removed, this is part of a larger installation and uninstallation. But the problem is the counter remain in the current powershell process. This needs to start a new PS so it will run the tests and return the results and then post them in the automation. I added the error that I am now receiving.
I tried to rename the tests to counters.Test.ps1 but that didn't seem work. So I am kind of at a loss at this point. Any help would be great, thanks in advance out there.
The actual test is really basic and runs just fine outside of a job.
Results:
Pester v5.3.0
System.Management.Automation.RuntimeException: No test files were found and no scriptblocks were provided. Please ensure that you provided at least one path to a *.Tests.ps1 file, or a directory that contains such file. Or that you provided a ScriptBlock test container.
at Invoke-Pester<End>, C:\Users\Administrator\Documents\PowerShell\Modules\Pester\5.3.0\Pester.psm1: line 5220
at <ScriptBlock>, <No file>: line 6
$TestFiles = @(
".\pestertests\test_new_counters.ps1",
".\pestertests\test_counters.test.ps1"
)
foreach ($file in $TestFiles[1]){
$newPSSession = {
function Get-Counters {
Start-Process pwsh
}
}
$mainScript = {
Param (
$scriptPath
)
$container = New-PesterContainer -Path $scriptPath
Invoke-Pester -Container $container -Output Diagnostic -PassThru
}
$job = Start-Job -Name UninstallCounterCheck -InitializationScript $newPSSession -ScriptBlock $mainScript -ArgumentList $file
$results = $job | Receive-Job -Wait -AutoRemoveJob
}