Skip to content

Powershell Pester and Pode #1559

@Nachtfeuer

Description

@Nachtfeuer

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
    }

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions