1

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      
}
Daniel
  • 4,792
  • 2
  • 7
  • 20
M Thompson
  • 25
  • 2
  • Have you tested just creating a container interactively at the prompt to see if `New-PesterContainer` is working correctly still or this is what you mean by it works fine outside a job? – Daniel Sep 17 '21 at 21:46
  • I can run the test with New-PesterContainter without any issues. The issue is trying to run this inside a job. It will run this way. $container = New-PesterContainer -Path $scriptPath Invoke-Pester -Container $container -Output Diagnostic -PassThru – M Thompson Sep 17 '21 at 22:07
  • 1
    Could be that you are passing relative file paths into `Start-Job` and the job is running from a different working directory then what you are expecting? I would try changing to absolute paths or making sure you change directory to the expected folder in your `$mainScript`, or providing `Start-Job` with the `-WorkingDirectory` parameter – Daniel Sep 17 '21 at 22:59
  • No its not the directory, it is always run from the same directory. It seems that $scriptPath stays null, -Arugmentlist $file is not adding the variable to scriptPath. I need to think about this some more. – M Thompson Sep 20 '21 at 14:56
  • Okay. Logic looks good to me and tests okay. In your sample code there is no reason that `$file` or `$scriptPath` should be null that I can see. – Daniel Sep 20 '21 at 15:19
  • Have you tried running it in Pester 5.3.0 version? – M Thompson Sep 23 '21 at 21:10

0 Answers0