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..bcab158 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,16 @@ 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. + +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/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/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/_.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 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' { 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