Skip to content

Commit f85f512

Browse files
tablackburnclaude
andcommitted
feat: make Help tests runnable standalone via Set-BuildEnvironment
tests/Help.tests.ps1 bootstraps the build via Invoke-psake when $Env:BHBuildOutput is unset, but build.psake.ps1's properties block needs BuildHelpers vars (BHProjectName, BHPSModuleManifest) that are only populated by ./build.ps1 before psake runs. Running the Help tests in isolation (e.g. Invoke-Pester tests/Help.tests.ps1 from an editor) bypasses that, leaving the vars empty and the standalone build broken. Call Set-BuildEnvironment inside the existing bootstrap guard in both BeforeDiscovery and BeforeAll so the vars are populated before psake is invoked. The guard only fires when BHBuildOutput is unset, so there is no effect when tests run via ./build.ps1 or in CI; Set-BuildEnvironment -Force is idempotent. Surfaced by a cross-repo audit against a consumer module (tablackburn/PlexAutomationToolkit) that already carried this fix locally. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 329ca92 commit f85f512

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ own `CHANGELOG.md` (generated from `CHANGELOG.template.md` during init).
1414

1515
- "Repository secrets" section in `README.md` documenting the GitHub Actions secrets the bundled workflows expect (`PSGALLERY_API_KEY`, `CODECOV_TOKEN`, `GITGUARDIAN_API_KEY`) — required vs. optional, source, and failure mode when missing.
1616
- `Initialize-Template.ps1` now mentions configuring GitHub repository secrets in its post-init "Next steps" output, between the build-test step and the first push.
17+
- `tests/Help.tests.ps1` now calls `Set-BuildEnvironment` inside its build-bootstrap guard (both `BeforeDiscovery` and `BeforeAll`) so the Help tests can run standalone — e.g. `Invoke-Pester tests/Help.tests.ps1` directly from an editor — without first running `./build.ps1`. The call is skipped entirely when tests run through the build pipeline (the guard only fires when `BHBuildOutput` is unset), and `Set-BuildEnvironment -Force` is idempotent, so there is no effect on CI or `./build.ps1` runs.
1718

1819
### Changed
1920

tests/Help.tests.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ BeforeDiscovery {
4848
# Check if the BHBuildOutput environment variable exists to determine if this test is running in a psake
4949
# build or not. If it does not exist, it is not running in a psake build, so build the module.
5050
if ($null -eq $Env:BHBuildOutput) {
51+
# Populate BuildHelpers env vars so build.psake.ps1's properties block has
52+
# the values it needs (BHPSModuleManifest, BHProjectName). When running via
53+
# ./build.ps1 this happens before psake; running tests in isolation bypasses
54+
# that, so we do it here. Set-BuildEnvironment is idempotent and -Force keeps
55+
# it from erroring if the vars are already set.
56+
Set-BuildEnvironment -Path (Split-Path -Path $PSScriptRoot -Parent) -Force
5157
$buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1'
5258
$invokePsakeParameters = @{
5359
TaskList = 'Build'
@@ -99,6 +105,12 @@ BeforeAll {
99105
# Check if the BHBuildOutput environment variable exists to determine if this test is running in a psake
100106
# build or not. If it does not exist, it is not running in a psake build, so build the module.
101107
if ($null -eq $Env:BHBuildOutput) {
108+
# Populate BuildHelpers env vars so build.psake.ps1's properties block has
109+
# the values it needs (BHPSModuleManifest, BHProjectName). When running via
110+
# ./build.ps1 this happens before psake; running tests in isolation bypasses
111+
# that, so we do it here. Set-BuildEnvironment is idempotent and -Force keeps
112+
# it from erroring if the vars are already set.
113+
Set-BuildEnvironment -Path (Split-Path -Path $PSScriptRoot -Parent) -Force
102114
$buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1'
103115
$invokePsakeParameters = @{
104116
TaskList = 'Build'

0 commit comments

Comments
 (0)