Private/New-PesterTestsFile.ps1

Function New-PesterTestsFile {
    <#
    .SYNOPSIS
    Creates a basic Pester test file with an initial 'Describe' block.
 
    .DESCRIPTION
    This function creates a Pester tests file (.tests.ps1) with a placeholder "Describe" block.
    Rename "<Your-FunctionName>" to your actual function name. This helps you quickly set up a base structure
    for your Pester tests.
 
    .PARAMETER Path
    Required. Specifies the path where the Pester test file will be created.
 
    .PARAMETER Name
    Required. The name of your function. This will be used within the generated "Describe" block.
 
    .EXAMPLE
    New-PesterTestsFile -Path C:\MyProject\tests -Name Get-Data
    Creates a test file named "Get-Data.tests.ps1" in the "C:\MyProject\tests" directory with a "Describe" block ready for your tests.
 
    .NOTES
    Author: owen.heaume
    Version: 1.0.0 - Initial release
    #>


    [CmdletBinding()]

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

        [Parameter(Mandatory)]
        [string]$Name
    )

    Begin {}

    Process {
        try {
            $TestPath = Join-Path -Path $Path -ChildPath "$name.tests.ps1" -ea Stop
        } catch {
            throw "Error joining path: $_"
        }
        $pesterContent = @"
BeforeAll {
    . "`$PSScriptRoot\Functions.ps1"
}
 
Describe "<Your-FunctionName>" {
 
}
"@


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

    End {}
}