From 956186c654b3dff37a33f28da22c419a1e33dfe3 Mon Sep 17 00:00:00 2001 From: "Rodweil, Theodor" Date: Sun, 6 Aug 2023 23:00:48 +0200 Subject: [PATCH] fix: resolve test runner scoping issue see https://github.com/pester/Pester/issues/2386 --- PSConfluencePublisher/Connection.Tests.ps1 | 2 +- PSConfluencePublisher/Manifest.Tests.ps1 | 2 +- PSConfluencePublisher/Page.Tests.ps1 | 2 +- PSConfluencePublisher/PageMeta.Tests.ps1 | 2 +- .../PersonalAccessToken.Tests.ps1 | 4 ++-- PSConfluencePublisher/String.Tests.ps1 | 2 +- README.md | 15 +-------------- 7 files changed, 8 insertions(+), 21 deletions(-) diff --git a/PSConfluencePublisher/Connection.Tests.ps1 b/PSConfluencePublisher/Connection.Tests.ps1 index f3b2194..5a44249 100755 --- a/PSConfluencePublisher/Connection.Tests.ps1 +++ b/PSConfluencePublisher/Connection.Tests.ps1 @@ -2,7 +2,7 @@ $ErrorActionPreference = "Stop" BeforeAll { - Import-Module (Join-Path $PSScriptRoot 'PSConfluencePublisher.psd1') -Force + Import-Module (Join-Path $PSScriptRoot 'PSConfluencePublisher.psd1') } diff --git a/PSConfluencePublisher/Manifest.Tests.ps1 b/PSConfluencePublisher/Manifest.Tests.ps1 index 97dd66a..fc658f9 100755 --- a/PSConfluencePublisher/Manifest.Tests.ps1 +++ b/PSConfluencePublisher/Manifest.Tests.ps1 @@ -2,7 +2,7 @@ $ErrorActionPreference = "Stop" BeforeAll { - Import-Module (Join-Path $PSScriptRoot 'PSConfluencePublisher.psd1') -Force + Import-Module (Join-Path $PSScriptRoot 'PSConfluencePublisher.psd1') } diff --git a/PSConfluencePublisher/Page.Tests.ps1 b/PSConfluencePublisher/Page.Tests.ps1 index 1c83d2b..8720c04 100755 --- a/PSConfluencePublisher/Page.Tests.ps1 +++ b/PSConfluencePublisher/Page.Tests.ps1 @@ -3,7 +3,7 @@ $ErrorActionPreference = "Stop" BeforeAll { - Import-Module (Join-Path $PSScriptRoot 'PSConfluencePublisher.psd1') -Force + Import-Module (Join-Path $PSScriptRoot 'PSConfluencePublisher.psd1') } diff --git a/PSConfluencePublisher/PageMeta.Tests.ps1 b/PSConfluencePublisher/PageMeta.Tests.ps1 index 1202a16..1030979 100755 --- a/PSConfluencePublisher/PageMeta.Tests.ps1 +++ b/PSConfluencePublisher/PageMeta.Tests.ps1 @@ -2,7 +2,7 @@ $ErrorActionPreference = "Stop" BeforeAll { - Import-Module (Join-Path $PSScriptRoot 'PSConfluencePublisher.psd1') -Force + Import-Module (Join-Path $PSScriptRoot 'PSConfluencePublisher.psd1') } diff --git a/PSConfluencePublisher/PersonalAccessToken.Tests.ps1 b/PSConfluencePublisher/PersonalAccessToken.Tests.ps1 index ea62a03..7f4ab9b 100755 --- a/PSConfluencePublisher/PersonalAccessToken.Tests.ps1 +++ b/PSConfluencePublisher/PersonalAccessToken.Tests.ps1 @@ -2,7 +2,7 @@ $ErrorActionPreference = "Stop" BeforeAll { - Import-Module (Join-Path $PSScriptRoot 'PSConfluencePublisher.psd1') -Force + Import-Module (Join-Path $PSScriptRoot 'PSConfluencePublisher.psd1') $mockHost = 'confluence.contoso.com' @@ -62,4 +62,4 @@ Describe 'Get-PersonalAccessToken' ` Get-PersonalAccessToken $mockHost | Should -Be $mockPat } } -} \ No newline at end of file +} diff --git a/PSConfluencePublisher/String.Tests.ps1 b/PSConfluencePublisher/String.Tests.ps1 index de93dfa..9eaadfd 100755 --- a/PSConfluencePublisher/String.Tests.ps1 +++ b/PSConfluencePublisher/String.Tests.ps1 @@ -2,7 +2,7 @@ $ErrorActionPreference = "Stop" BeforeAll { - Import-Module (Join-Path $PSScriptRoot 'PSConfluencePublisher.psd1') -Force + Import-Module (Join-Path $PSScriptRoot 'PSConfluencePublisher.psd1') } Describe 'Get-StringHash' ` diff --git a/README.md b/README.md index 3416465..657a20e 100755 --- a/README.md +++ b/README.md @@ -104,20 +104,7 @@ You can execute the following from within a PowerShell session. ``PS> Invoke-Pester PSConfluencePublisher/*.Tests.ps1 -Show 'All'`` -However the test suite still requires optimization towards execution, as Pester -requires a certain setup for tests of nested modules to work. The `Force` switch -does not work as expected on the `Import-Module` cmdlet (within the `BeforeAll` -script blocks). Therefore it is advised to wrap the `Invoke-Pester` as follows -so that the global scope gets teared down after execution. +or the following, from within a POSIX shell and PowerShell Core being present: ``$ pwsh -c "Invoke-Pester PSConfluencePublisher/*.Tests.ps1 -Show 'All'"`` - -There currently is an issue with the invocation of the test suites (see -[Pester Issue #2386](https://github.com/pester/Pester/issues/2386)), where -some tests fail, if ran via the wildcard discovery. - -Execute the following from within a PowerShell session to temporarily circumvent -this problem: - -``$ pwsh -c 'Get-ChildItem PSConfluencePublisher/*.Tests.ps1 | ForEach {pwsh -c Invoke-Pester (Resolve-Path -Relative $_)}'``