From f578dec52048f38c8bfaec2a3508d4287601d48f Mon Sep 17 00:00:00 2001 From: deadlydog Date: Sat, 20 Apr 2024 10:02:07 -0600 Subject: [PATCH 1/4] feat: Run build tests on Windows PowerShell as well --- .../build-and-test-powershell-module.yml | 23 +++++++++++++++++-- Changelog.md | 6 +++++ ReadMe.md | 5 ++-- .../build-and-test-powershell-module.yml | 23 +++++++++++++++++-- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-and-test-powershell-module.yml b/.github/workflows/build-and-test-powershell-module.yml index 6856a03..b744914 100644 --- a/.github/workflows/build-and-test-powershell-module.yml +++ b/.github/workflows/build-and-test-powershell-module.yml @@ -47,7 +47,7 @@ env: jobs: build-and-test: - runs-on: windows-latest # Use Windows agent to ensure dotnet.exe is available to build C# assemblies, if required. + runs-on: windows-latest # Use Windows agent so we can run Pester tests on Windows PowerShell 5.1 as well. outputs: powerShellModuleName: ${{ env.powerShellModuleName }} stableVersionNumber: ${{ steps.version-number.outputs.majorMinorPatch }} @@ -107,6 +107,25 @@ jobs: shell: pwsh run: Invoke-ScriptAnalyzer -Path . -Recurse -EnableExit + - name: Run Pester tests on Windows PowerShell to ensure backward compatibility + shell: powershell + run: | + Write-Output "Pester version being used:" + Import-Module -Name Pester + Get-Module -Name Pester + + Write-Output "Running all Pester tests in the repo:" + $pesterConfig = New-PesterConfiguration @{ + Output = @{ Verbosity = 'Detailed' } + Run = @{ Throw = $true } + TestResult = @{ + Enabled = $true + OutputPath = 'test-results-windows-powershell-nunit.xml' + } + CodeCoverage = @{ Enabled = $false } + } + Invoke-Pester -Configuration $pesterConfig + - name: Run Pester tests and generate code coverage report shell: pwsh run: | @@ -120,7 +139,7 @@ jobs: Run = @{ Throw = $true } TestResult = @{ Enabled = $true - OutputPath = 'test-results-nunit.xml' + OutputPath = 'test-results-pwsh-nunit.xml' } CodeCoverage = @{ Enabled = $true diff --git a/Changelog.md b/Changelog.md index bd13a95..7c6c332 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,12 @@ This page is a list of _notable_ changes made in each version. +## v1.1.0 - April 20, 2024 + +Features: + +- Run Pester tests during the build on Windows PowerShell too, to catch backward-incompatible changes earlier. + ## v1.0.0 - April 13, 2024 Features: diff --git a/ReadMe.md b/ReadMe.md index 9eebb1f..611de87 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -31,8 +31,9 @@ Use this repo template or module for your new git repository to get the followin - Can also manually trigger deployments of feature branches. - Version the module. - Run PSScriptAnalyzer to ensure best practices are followed. - - Run build tests, and smoke tests on multiple platforms (Windows, Linux, MacOS). - - Publish the module to the PowerShell Gallery or a custom feed. + - Run build tests with Pwsh and PowerShell to ensure backward compatibility. + - Run smoke tests on multiple platforms (Windows, Linux, MacOS) to ensure the module works as expected after being installed on all platforms. + - Publish the module to the PowerShell Gallery (custom feed support coming soon). - Spell check all files in the repository. - Display test code coverage results on PRs. - Visual Studio Code tasks to easily run Pester tests and PSScriptAnalyzer locally. diff --git a/src/ScriptModuleRepositoryTemplate/TemplateRepoFiles/_.github/workflows/build-and-test-powershell-module.yml b/src/ScriptModuleRepositoryTemplate/TemplateRepoFiles/_.github/workflows/build-and-test-powershell-module.yml index 35e0d20..5107c39 100644 --- a/src/ScriptModuleRepositoryTemplate/TemplateRepoFiles/_.github/workflows/build-and-test-powershell-module.yml +++ b/src/ScriptModuleRepositoryTemplate/TemplateRepoFiles/_.github/workflows/build-and-test-powershell-module.yml @@ -47,7 +47,7 @@ env: jobs: build-and-test: - runs-on: windows-latest # Use Windows agent to ensure dotnet.exe is available to build C# assemblies, if required. + runs-on: windows-latest # Use Windows agent so we can run Pester tests on Windows PowerShell 5.1 as well. outputs: powerShellModuleName: ${{ env.powerShellModuleName }} stableVersionNumber: ${{ steps.version-number.outputs.majorMinorPatch }} @@ -108,6 +108,25 @@ jobs: shell: pwsh run: Invoke-ScriptAnalyzer -Path . -Recurse -EnableExit + - name: Run Pester tests on Windows PowerShell to ensure backward compatibility + shell: powershell + run: | + Write-Output "Pester version being used:" + Import-Module -Name Pester + Get-Module -Name Pester + + Write-Output "Running all Pester tests in the repo:" + $pesterConfig = New-PesterConfiguration @{ + Output = @{ Verbosity = 'Detailed' } + Run = @{ Throw = $true } + TestResult = @{ + Enabled = $true + OutputPath = 'test-results-windows-powershell-nunit.xml' + } + CodeCoverage = @{ Enabled = $false } + } + Invoke-Pester -Configuration $pesterConfig + - name: Run Pester tests and generate code coverage report shell: pwsh run: | @@ -121,7 +140,7 @@ jobs: Run = @{ Throw = $true } TestResult = @{ Enabled = $true - OutputPath = 'test-results-nunit.xml' + OutputPath = 'test-results-pwsh-nunit.xml' } CodeCoverage = @{ Enabled = $true From 469afe789cef3cf9747d365d1ffc932acb7236b3 Mon Sep 17 00:00:00 2001 From: deadlydog Date: Sat, 20 Apr 2024 11:21:02 -0600 Subject: [PATCH 2/4] Run Windows PowerShell tests after Pwsh Pester tests for troubleshooting --- .../build-and-test-powershell-module.yml | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-and-test-powershell-module.yml b/.github/workflows/build-and-test-powershell-module.yml index b744914..d0e3ef4 100644 --- a/.github/workflows/build-and-test-powershell-module.yml +++ b/.github/workflows/build-and-test-powershell-module.yml @@ -107,8 +107,8 @@ jobs: shell: pwsh run: Invoke-ScriptAnalyzer -Path . -Recurse -EnableExit - - name: Run Pester tests on Windows PowerShell to ensure backward compatibility - shell: powershell + - name: Run Pester tests and generate code coverage report + shell: pwsh run: | Write-Output "Pester version being used:" Import-Module -Name Pester @@ -120,14 +120,18 @@ jobs: Run = @{ Throw = $true } TestResult = @{ Enabled = $true - OutputPath = 'test-results-windows-powershell-nunit.xml' + OutputPath = 'test-results-pwsh-nunit.xml' + } + CodeCoverage = @{ + Enabled = $true + OutputPath = 'code-coverage-jacoco.xml' + Path = 'src/' # Only include code coverage for the module's source code, not build or deployment scripts. } - CodeCoverage = @{ Enabled = $false } } Invoke-Pester -Configuration $pesterConfig - - name: Run Pester tests and generate code coverage report - shell: pwsh + - name: Run Pester tests on Windows PowerShell to ensure backward compatibility + shell: powershell run: | Write-Output "Pester version being used:" Import-Module -Name Pester @@ -139,13 +143,9 @@ jobs: Run = @{ Throw = $true } TestResult = @{ Enabled = $true - OutputPath = 'test-results-pwsh-nunit.xml' - } - CodeCoverage = @{ - Enabled = $true - OutputPath = 'code-coverage-jacoco.xml' - Path = 'src/' # Only include code coverage for the module's source code, not build or deployment scripts. + OutputPath = 'test-results-windows-powershell-nunit.xml' } + CodeCoverage = @{ Enabled = $false } } Invoke-Pester -Configuration $pesterConfig From 1761c89a8be308826bb41f34692dacafb09a63a8 Mon Sep 17 00:00:00 2001 From: deadlydog Date: Sat, 20 Apr 2024 12:21:57 -0600 Subject: [PATCH 3/4] fix: Use backslash instead of forward-slash for Windows PowerShell backward compatibility --- Changelog.md | 4 ++++ .../ScriptModuleRepositoryTemplate.Tests.ps1 | 2 +- .../src/__NewModuleName__/__NewModuleName__.Tests.ps1 | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 7c6c332..bcab158 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,10 @@ Features: - Run Pester tests during the build on Windows PowerShell too, to catch backward-incompatible changes earlier. +Fixes: + +- Use backslash instead of forward-slash to import module in Pester tests for Windows PowerShell backward compatibility. + ## v1.0.0 - April 13, 2024 Features: diff --git a/src/ScriptModuleRepositoryTemplate/ScriptModuleRepositoryTemplate.Tests.ps1 b/src/ScriptModuleRepositoryTemplate/ScriptModuleRepositoryTemplate.Tests.ps1 index 0407f9d..25a925a 100644 --- a/src/ScriptModuleRepositoryTemplate/ScriptModuleRepositoryTemplate.Tests.ps1 +++ b/src/ScriptModuleRepositoryTemplate/ScriptModuleRepositoryTemplate.Tests.ps1 @@ -1,4 +1,4 @@ -using module './ScriptModuleRepositoryTemplate.psm1' +using module '.\ScriptModuleRepositoryTemplate.psm1' Describe 'New-PowerShellScriptModuleRepository' { BeforeEach { diff --git a/src/ScriptModuleRepositoryTemplate/TemplateRepoFiles/src/__NewModuleName__/__NewModuleName__.Tests.ps1 b/src/ScriptModuleRepositoryTemplate/TemplateRepoFiles/src/__NewModuleName__/__NewModuleName__.Tests.ps1 index a033d94..3cbfdda 100644 --- a/src/ScriptModuleRepositoryTemplate/TemplateRepoFiles/src/__NewModuleName__/__NewModuleName__.Tests.ps1 +++ b/src/ScriptModuleRepositoryTemplate/TemplateRepoFiles/src/__NewModuleName__/__NewModuleName__.Tests.ps1 @@ -1,4 +1,4 @@ -using module './__NewModuleName__.psm1' +using module '.\__NewModuleName__.psm1' # UPDATE ME: This is just example code. Replace the code below with your module's tests. Describe 'Get-HelloWorld' { From 2a58d88c650c76bcb97670addbf87248ce672ea4 Mon Sep 17 00:00:00 2001 From: deadlydog Date: Sat, 20 Apr 2024 12:22:54 -0600 Subject: [PATCH 4/4] ci: Run Windows PowerShell tests first --- .../build-and-test-powershell-module.yml | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-and-test-powershell-module.yml b/.github/workflows/build-and-test-powershell-module.yml index d0e3ef4..b744914 100644 --- a/.github/workflows/build-and-test-powershell-module.yml +++ b/.github/workflows/build-and-test-powershell-module.yml @@ -107,8 +107,8 @@ jobs: shell: pwsh run: Invoke-ScriptAnalyzer -Path . -Recurse -EnableExit - - name: Run Pester tests and generate code coverage report - shell: pwsh + - name: Run Pester tests on Windows PowerShell to ensure backward compatibility + shell: powershell run: | Write-Output "Pester version being used:" Import-Module -Name Pester @@ -120,18 +120,14 @@ jobs: Run = @{ Throw = $true } TestResult = @{ Enabled = $true - OutputPath = 'test-results-pwsh-nunit.xml' - } - CodeCoverage = @{ - Enabled = $true - OutputPath = 'code-coverage-jacoco.xml' - Path = 'src/' # Only include code coverage for the module's source code, not build or deployment scripts. + OutputPath = 'test-results-windows-powershell-nunit.xml' } + CodeCoverage = @{ Enabled = $false } } Invoke-Pester -Configuration $pesterConfig - - name: Run Pester tests on Windows PowerShell to ensure backward compatibility - shell: powershell + - name: Run Pester tests and generate code coverage report + shell: pwsh run: | Write-Output "Pester version being used:" Import-Module -Name Pester @@ -143,9 +139,13 @@ jobs: Run = @{ Throw = $true } TestResult = @{ Enabled = $true - OutputPath = 'test-results-windows-powershell-nunit.xml' + OutputPath = 'test-results-pwsh-nunit.xml' + } + CodeCoverage = @{ + Enabled = $true + OutputPath = 'code-coverage-jacoco.xml' + Path = 'src/' # Only include code coverage for the module's source code, not build or deployment scripts. } - CodeCoverage = @{ Enabled = $false } } Invoke-Pester -Configuration $pesterConfig pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy