diff --git a/build.psake.ps1 b/build.psake.ps1 index 1976670..defdc08 100644 --- a/build.psake.ps1 +++ b/build.psake.ps1 @@ -21,9 +21,19 @@ properties { $PSBPreference.Test.OutputFile = [IO.Path]::Combine($PSScriptRoot, 'out', 'testResults.xml') $PSBPreference.Test.OutputFormat = 'NUnitXml' $PSBPreference.Test.CodeCoverage.Enabled = $true + # Coverage must target the staged build output, not the source tree — tests + # Import-Module from Output//, so Pester only records hits + # against those paths. $Env:BHBuildOutput points at /BuildOutput at + # properties-evaluation time (PowerShellBuild rewrites it later inside its + # tasks), so we compute the staged path from the manifest version here. + if (-not $Env:BHPSModuleManifest -or -not $Env:BHProjectName) { + throw 'Coverage configuration requires BuildHelpers env vars. Run via ./build.ps1 or call Set-BuildEnvironment first.' + } + $moduleVersion = (Import-PowerShellDataFile -Path $Env:BHPSModuleManifest).ModuleVersion + $stagedOutput = [IO.Path]::Combine($PSScriptRoot, 'Output', $Env:BHProjectName, $moduleVersion) $PSBPreference.Test.CodeCoverage.Files = @( - "$PSScriptRoot/PlexAutomationToolkit/Public/*.ps1" - "$PSScriptRoot/PlexAutomationToolkit/Private/*.ps1" + "$stagedOutput/Public/*.ps1" + "$stagedOutput/Private/*.ps1" ) $PSBPreference.Test.CodeCoverage.Threshold = 0 # Threshold enforced by Codecov $PSBPreference.Test.CodeCoverage.OutputFile = [IO.Path]::Combine($PSScriptRoot, 'out', 'codeCoverage.xml') diff --git a/tests/Help.tests.ps1 b/tests/Help.tests.ps1 index 6e60762..cf7c16c 100644 --- a/tests/Help.tests.ps1 +++ b/tests/Help.tests.ps1 @@ -69,6 +69,11 @@ BeforeDiscovery { If the BHBuildOutput environment variable exists, it is running in a psake build, so do not build the module. #> if ($null -eq $Env:BHBuildOutput) { + # Populate BuildHelpers env vars so build.psake.ps1's properties block has + # the values it needs (BHPSModuleManifest, BHProjectName) — when running + # via ./build.ps1 this happens before psake; running tests in isolation + # bypasses that, so we do it here. + Set-BuildEnvironment -Path (Split-Path -Parent $PSScriptRoot) -Force $buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1' $invokePsakeParameters = @{ TaskList = 'Build' @@ -122,6 +127,11 @@ BeforeAll { If the BHBuildOutput environment variable exists, it is running in a psake build, so do not build the module. #> if ($null -eq $Env:BHBuildOutput) { + # Populate BuildHelpers env vars so build.psake.ps1's properties block has + # the values it needs (BHPSModuleManifest, BHProjectName) — when running + # via ./build.ps1 this happens before psake; running tests in isolation + # bypasses that, so we do it here. + Set-BuildEnvironment -Path (Split-Path -Parent $PSScriptRoot) -Force $buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1' $invokePsakeParameters = @{ TaskList = 'Build' diff --git a/tests/Manifest.tests.ps1 b/tests/Manifest.tests.ps1 index ed18010..10687fe 100644 --- a/tests/Manifest.tests.ps1 +++ b/tests/Manifest.tests.ps1 @@ -32,6 +32,11 @@ BeforeDiscovery { If the BHBuildOutput environment variable exists, it is running in a psake build, so do not build the module. #> if ($null -eq $Env:BHBuildOutput) { + # Populate BuildHelpers env vars so build.psake.ps1's properties block has + # the values it needs (BHPSModuleManifest, BHProjectName) — when running + # via ./build.ps1 this happens before psake; running tests in isolation + # bypasses that, so we do it here. + Set-BuildEnvironment -Path (Split-Path -Parent $PSScriptRoot) -Force $buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1' $invokePsakeParameters = @{ TaskList = 'Build' @@ -65,6 +70,11 @@ BeforeAll { If the BHBuildOutput environment variable exists, it is running in a psake build, so do not build the module. #> if ($null -eq $Env:BHBuildOutput) { + # Populate BuildHelpers env vars so build.psake.ps1's properties block has + # the values it needs (BHPSModuleManifest, BHProjectName) — when running + # via ./build.ps1 this happens before psake; running tests in isolation + # bypasses that, so we do it here. + Set-BuildEnvironment -Path (Split-Path -Parent $PSScriptRoot) -Force $buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1' $invokePsakeParameters = @{ TaskList = 'Build'