diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ca8e39..7a7748d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ own `CHANGELOG.md` (generated from `CHANGELOG.template.md` during init). - "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. - `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. +- `tests/Help.tests.ps1` can now run standalone — e.g. `Invoke-Pester tests/Help.tests.ps1` directly from an editor (or an agent running a single test) — without first running `./build.ps1`. Its build-bootstrap guard (in both `BeforeDiscovery` and `BeforeAll`) now delegates to `build.ps1 -Task 'Build' -Bootstrap`, the canonical entry point, so dependency bootstrap, BuildHelpers environment setup, and module staging all happen through the real build path instead of a partial reimplementation. The guard only fires when `BHBuildOutput` is unset, so there is no effect on CI or `./build.ps1` runs. `build.ps1` is invoked with the call operator (`&`), not dot-sourced, so its terminating `exit` is contained to the script boundary and does not end the Pester run. ### Changed diff --git a/tests/Help.tests.ps1 b/tests/Help.tests.ps1 index f61606d..97f62a8 100644 --- a/tests/Help.tests.ps1 +++ b/tests/Help.tests.ps1 @@ -48,12 +48,15 @@ BeforeDiscovery { # Check if the BHBuildOutput environment variable exists to determine if this test is running in a psake # build or not. If it does not exist, it is not running in a psake build, so build the module. if ($null -eq $Env:BHBuildOutput) { - $buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1' - $invokePsakeParameters = @{ - TaskList = 'Build' - BuildFile = $buildFilePath - } - Invoke-psake @invokePsakeParameters + # Standalone run (e.g. Invoke-Pester on this file directly, or an agent + # running one test): the module isn't built and the BuildHelpers env vars + # aren't set. Defer to build.ps1 -- the canonical entry point -- to bootstrap + # dependencies, set the BuildHelpers environment, and stage the module. + # Invoke with & (not dot-sourcing): build.ps1 ends in an exit statement, and + # the call operator contains it to the script boundary instead of ending the + # whole Pester run. + $buildScript = Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'build.ps1' + & $buildScript -Task 'Build' -Bootstrap } # PowerShellBuild outputs to Output///, override BHBuildOutput @@ -99,12 +102,15 @@ BeforeAll { # Check if the BHBuildOutput environment variable exists to determine if this test is running in a psake # build or not. If it does not exist, it is not running in a psake build, so build the module. if ($null -eq $Env:BHBuildOutput) { - $buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1' - $invokePsakeParameters = @{ - TaskList = 'Build' - BuildFile = $buildFilePath - } - Invoke-psake @invokePsakeParameters + # Standalone run (e.g. Invoke-Pester on this file directly, or an agent + # running one test): the module isn't built and the BuildHelpers env vars + # aren't set. Defer to build.ps1 -- the canonical entry point -- to bootstrap + # dependencies, set the BuildHelpers environment, and stage the module. + # Invoke with & (not dot-sourcing): build.ps1 ends in an exit statement, and + # the call operator contains it to the script boundary instead of ending the + # whole Pester run. + $buildScript = Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'build.ps1' + & $buildScript -Task 'Build' -Bootstrap } }