Tests/Run-PesterTests.ps1

$SplitPath =
    @{
        Parent =
            $true
    }

$ModuleRootPath = 
    $PSScriptRoot | 
        Split-Path @SplitPath
$Config = 
    New-PesterConfiguration

# Run
$Run = 
    @{ 
        Path = 
            "$ModuleRootPath\Tests"
        ExcludePath = 
            @(
                'Run-PesterTests.ps1'
            ) 
        PassThru = 
            $true 
    }

$CodeCoverage = 
    @{ 
        Enabled = 
            $true
        path = 
            @(
                "$ModuleRootPath\CM.Logger.psm1"
            ) 
        OutputPath = 
            "$ModuleRootPath\Tests\CodeCoverage.xml" 
    }

$TestResult = 
    @{ 
        Enabled = 
            $true 
        OutputPath =
            "$ModuleRootPath\Tests\TestResults.xml"
    }

$Output = 
    @{ 
        Verbosity = 
            'Detailed' 
    }

$Config.
    Run = 
        $Run
$Config.
    CodeCoverage = 
        $CodeCoverage
$Config.
    TestResult = 
        $TestResult
$Config.
    Output = 
        $Output

$InvokePester =
    @{
        Configuration =
            $Config
    }
$Results = 
    Invoke-Pester @InvokePester

if (
    $Results.
        CodeCoverage.
            CoveragePercent -eq 
                100 -and 
    $Results.
        Result -eq 
            'Passed'
) {
    $PublishModule =
        @{
            Name = 
                'CM.Logger'
            RequiredVersion =
                '4.0.1.2'
            NuGetApiKey =
                #'4dcd7207-0992-479b-a203-bcb1470c5b4a'
                'oy2ap7tsmap5fcsy7xbqzy7rzf7sjbgu7hgqgsifv6xlcq'
            Repository =
                #'LeidosPSGallery'
                'PSGallery'
            Force =
                $true
            Verbose =
                $true
        }
    Publish-Module @PublishModule
}

code "$ModuleRootPath\Tests\CodeCoverage.xml"
code "$ModuleRootPath\Tests\TestResults.xml"