Private/New-TestFile.ps1

Function New-TestFile {
    <#
    .SYNOPSIS
    Creates a basic Test.ps1 file with initial Pester configuration.
 
    .DESCRIPTION
    This function creates a Test.ps1 file and includes a basic Pester configuration section.
    This configuration enables code coverage, sets a target coverage percentage, and specifies
    output options for Pester test results.
 
    .PARAMETER Path
    Required. Specifies the path where the Test.ps1 file should be created.
 
    .EXAMPLE
    New-TestFile -Path C:\MyProject\tests
    This creates a Test.ps1 file in the "C:\MyProject\tests" directory with the basic Pester configuration.
 
    .NOTES
    Author: owen.heaume
    Version: 1.0.0 - Initial release
    #>


    [CmdletBinding()]

    param (
        [Parameter(Mandatory)]
        [string]$Path
    )

    Begin {}

    Process {
        try {
            $TestPath = Join-Path -Path $Path -ChildPath "Test.ps1" -ea Stop
        } catch {
            throw "Error joining path: $_"
        }
        $TestContent = @"
Set-Location `$PSScriptRoot
 
`$config = New-PesterConfiguration
 
`$config.CodeCoverage.Enabled = `$true
`$config.CodeCoverage.CoveragePercentTarget = 90
`$config.Output.Verbosity = 'Detailed'
`$config.CodeCoverage.Path = "`$psscriptroot\src\Functions.ps1"
`$config.CodeCoverage.OutputPath = "`$psscriptroot\coverage.xml"
 
Invoke-Pester -Configuration `$config
"@


        try {
            Write-Host "Creating Test.ps1 file: $TestPath" -ForegroundColor DarkCyan
            if (Test-Path $TestPath) {
                Write-Host "Test.ps1 file already exists" -ForegroundColor DarkYellow
            } else {
                $TestContent | Out-File -FilePath $TestPath -ea Stop
                Write-Host "Test.ps1 file created successfully" -ForegroundColor DarkGreen
            }
        } catch {
            throw "Error writing Test.ps1 file: $_"
        }
    }

    End {}
}