Skip to content

Commit

Permalink
Merge pull request #2 from deadlydog/RunBuildTestsOnWindowsPowerShellToo
Browse files Browse the repository at this point in the history
feat: Run build tests on Windows PowerShell as well
  • Loading branch information
deadlydog authored Apr 20, 2024
2 parents 7253e68 + 2a58d88 commit 35bc522
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/build-and-test-powershell-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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: |
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using module './ScriptModuleRepositoryTemplate.psm1'
using module '.\ScriptModuleRepositoryTemplate.psm1'

Describe 'New-PowerShellScriptModuleRepository' {
BeforeEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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: |
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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' {
Expand Down

0 comments on commit 35bc522

Please sign in to comment.