Skip to content

Commit 35bc522

Browse files
authored
Merge pull request #2 from deadlydog/RunBuildTestsOnWindowsPowerShellToo
feat: Run build tests on Windows PowerShell as well
2 parents 7253e68 + 2a58d88 commit 35bc522

File tree

6 files changed

+57
-8
lines changed

6 files changed

+57
-8
lines changed

.github/workflows/build-and-test-powershell-module.yml

+21-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ env:
4747

4848
jobs:
4949
build-and-test:
50-
runs-on: windows-latest # Use Windows agent to ensure dotnet.exe is available to build C# assemblies, if required.
50+
runs-on: windows-latest # Use Windows agent so we can run Pester tests on Windows PowerShell 5.1 as well.
5151
outputs:
5252
powerShellModuleName: ${{ env.powerShellModuleName }}
5353
stableVersionNumber: ${{ steps.version-number.outputs.majorMinorPatch }}
@@ -107,6 +107,25 @@ jobs:
107107
shell: pwsh
108108
run: Invoke-ScriptAnalyzer -Path . -Recurse -EnableExit
109109

110+
- name: Run Pester tests on Windows PowerShell to ensure backward compatibility
111+
shell: powershell
112+
run: |
113+
Write-Output "Pester version being used:"
114+
Import-Module -Name Pester
115+
Get-Module -Name Pester
116+
117+
Write-Output "Running all Pester tests in the repo:"
118+
$pesterConfig = New-PesterConfiguration @{
119+
Output = @{ Verbosity = 'Detailed' }
120+
Run = @{ Throw = $true }
121+
TestResult = @{
122+
Enabled = $true
123+
OutputPath = 'test-results-windows-powershell-nunit.xml'
124+
}
125+
CodeCoverage = @{ Enabled = $false }
126+
}
127+
Invoke-Pester -Configuration $pesterConfig
128+
110129
- name: Run Pester tests and generate code coverage report
111130
shell: pwsh
112131
run: |
@@ -120,7 +139,7 @@ jobs:
120139
Run = @{ Throw = $true }
121140
TestResult = @{
122141
Enabled = $true
123-
OutputPath = 'test-results-nunit.xml'
142+
OutputPath = 'test-results-pwsh-nunit.xml'
124143
}
125144
CodeCoverage = @{
126145
Enabled = $true

Changelog.md

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
This page is a list of _notable_ changes made in each version.
44

5+
## v1.1.0 - April 20, 2024
6+
7+
Features:
8+
9+
- Run Pester tests during the build on Windows PowerShell too, to catch backward-incompatible changes earlier.
10+
11+
Fixes:
12+
13+
- Use backslash instead of forward-slash to import module in Pester tests for Windows PowerShell backward compatibility.
14+
515
## v1.0.0 - April 13, 2024
616

717
Features:

ReadMe.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ Use this repo template or module for your new git repository to get the followin
3131
- Can also manually trigger deployments of feature branches.
3232
- Version the module.
3333
- Run PSScriptAnalyzer to ensure best practices are followed.
34-
- Run build tests, and smoke tests on multiple platforms (Windows, Linux, MacOS).
35-
- Publish the module to the PowerShell Gallery or a custom feed.
34+
- Run build tests with Pwsh and PowerShell to ensure backward compatibility.
35+
- Run smoke tests on multiple platforms (Windows, Linux, MacOS) to ensure the module works as expected after being installed on all platforms.
36+
- Publish the module to the PowerShell Gallery (custom feed support coming soon).
3637
- Spell check all files in the repository.
3738
- Display test code coverage results on PRs.
3839
- Visual Studio Code tasks to easily run Pester tests and PSScriptAnalyzer locally.

src/ScriptModuleRepositoryTemplate/ScriptModuleRepositoryTemplate.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using module './ScriptModuleRepositoryTemplate.psm1'
1+
using module '.\ScriptModuleRepositoryTemplate.psm1'
22

33
Describe 'New-PowerShellScriptModuleRepository' {
44
BeforeEach {

src/ScriptModuleRepositoryTemplate/TemplateRepoFiles/_.github/workflows/build-and-test-powershell-module.yml

+21-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ env:
4747

4848
jobs:
4949
build-and-test:
50-
runs-on: windows-latest # Use Windows agent to ensure dotnet.exe is available to build C# assemblies, if required.
50+
runs-on: windows-latest # Use Windows agent so we can run Pester tests on Windows PowerShell 5.1 as well.
5151
outputs:
5252
powerShellModuleName: ${{ env.powerShellModuleName }}
5353
stableVersionNumber: ${{ steps.version-number.outputs.majorMinorPatch }}
@@ -108,6 +108,25 @@ jobs:
108108
shell: pwsh
109109
run: Invoke-ScriptAnalyzer -Path . -Recurse -EnableExit
110110

111+
- name: Run Pester tests on Windows PowerShell to ensure backward compatibility
112+
shell: powershell
113+
run: |
114+
Write-Output "Pester version being used:"
115+
Import-Module -Name Pester
116+
Get-Module -Name Pester
117+
118+
Write-Output "Running all Pester tests in the repo:"
119+
$pesterConfig = New-PesterConfiguration @{
120+
Output = @{ Verbosity = 'Detailed' }
121+
Run = @{ Throw = $true }
122+
TestResult = @{
123+
Enabled = $true
124+
OutputPath = 'test-results-windows-powershell-nunit.xml'
125+
}
126+
CodeCoverage = @{ Enabled = $false }
127+
}
128+
Invoke-Pester -Configuration $pesterConfig
129+
111130
- name: Run Pester tests and generate code coverage report
112131
shell: pwsh
113132
run: |
@@ -121,7 +140,7 @@ jobs:
121140
Run = @{ Throw = $true }
122141
TestResult = @{
123142
Enabled = $true
124-
OutputPath = 'test-results-nunit.xml'
143+
OutputPath = 'test-results-pwsh-nunit.xml'
125144
}
126145
CodeCoverage = @{
127146
Enabled = $true

src/ScriptModuleRepositoryTemplate/TemplateRepoFiles/src/__NewModuleName__/__NewModuleName__.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using module './__NewModuleName__.psm1'
1+
using module '.\__NewModuleName__.psm1'
22

33
# UPDATE ME: This is just example code. Replace the code below with your module's tests.
44
Describe 'Get-HelloWorld' {

0 commit comments

Comments
 (0)