Question
I'm writing a small ticket system (for myself) using Powershell as CLI.
One option I'm finally about is to run it via -Serve using Pode providing
the list of tickets as json (http://localhost:8080/api/tickets).
That does work fine. However the Pester tests are configured
to check code coverage and my code coverage decreases since the
server is running in another process (see code block)
Could you please give help on this how to manage that correctly
that code coverage will work?
(I tried start-job and start-threadjob but that seems not to be an option)
Kind Regards,
Thomas
BeforeEach {
# provide test path
$tempPath = [System.IO.Path]::GetTempPath()
$tempFolder = (New-Guid).ToString("N")
$testPath = Join-Path $tempPath $tempFolder
New-Item -ItemType Directory -Path $testPath
$processInfo = @{
FilePath = 'pwsh'
ArgumentList = @(
"-File", "./Invoke-Ticket.ps1",
"-Serve",
"-Path", "`"$testPath`""
)
NoNewWindow = $true
PassThru = $true
}
$serverProcess = Start-Process @processInfo
}
AfterEach {
if (-not $serverProcess.HasExited) {
$serverProcess.Kill()
$serverProcess.WaitForExit()
}
# cleanup of test path
Remove-Item -Path $testPath -Recurse -Force
}
Question
I'm writing a small ticket system (for myself) using Powershell as CLI.
One option I'm finally about is to run it via
-Serveusing Pode providingthe list of tickets as json (http://localhost:8080/api/tickets).
That does work fine. However the Pester tests are configured
to check code coverage and my code coverage decreases since the
server is running in another process (see code block)
Could you please give help on this how to manage that correctly
that code coverage will work?
(I tried start-job and start-threadjob but that seems not to be an option)
Kind Regards,
Thomas
BeforeEach { # provide test path $tempPath = [System.IO.Path]::GetTempPath() $tempFolder = (New-Guid).ToString("N") $testPath = Join-Path $tempPath $tempFolder New-Item -ItemType Directory -Path $testPath $processInfo = @{ FilePath = 'pwsh' ArgumentList = @( "-File", "./Invoke-Ticket.ps1", "-Serve", "-Path", "`"$testPath`"" ) NoNewWindow = $true PassThru = $true } $serverProcess = Start-Process @processInfo } AfterEach { if (-not $serverProcess.HasExited) { $serverProcess.Kill() $serverProcess.WaitForExit() } # cleanup of test path Remove-Item -Path $testPath -Recurse -Force }