Skip to content

Commit

Permalink
fixes #88 - refactored pester 5 samples to follow pester 5 rules
Browse files Browse the repository at this point in the history
  • Loading branch information
techthoughts2 committed Aug 7, 2024
1 parent 89c62e6 commit 215e499
Show file tree
Hide file tree
Showing 19 changed files with 170 additions and 212 deletions.
6 changes: 5 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.13.0]
## [2.16.0]

- Catesta template module changes
- CI/CD Changes:
- Adjusted all action bootstrap for module installs to include a `SkipPublisherCheck` when installing Pester module on Windows builds. (https://github.com/pester/Pester/issues/2389)
- Pester bumped from `5.5.0` to `5.6.1`
- InvokeBuild bumped from `5.11.1` to `5.11.3`
- Sample pester tests for Pester v5 refactored to follow Pester 5 rules
- Refactored `ExportedFunctions.Tests.ps1` for better efficiency in loops
- Minor spelling correction in sample Pester tests
- `tasks.json`
- `Test` task is now explicitly set as default test task
Expand All @@ -21,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Pester bumped from `5.5.0` to `5.6.1`
- InvokeBuild bumped from `5.11.1` to `5.11.3`
- Adjusted action bootstrap for module installs to include a `SkipPublisherCheck` when installing Pester module on Windows builds. (https://github.com/pester/Pester/issues/2389)
- Refactored all unit and infra tests to adhere to Pester 5 rules
- Refactored `ExportedFunctions.Tests.ps1` for better efficiency in loops

## [2.12.0]

Expand Down
2 changes: 1 addition & 1 deletion docs/Catesta.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module Name: Catesta
Module Guid: 6796b193-9013-468a-b022-837749af2d06
Download Help Link: NA
Help Version: 2.13.0
Help Version: 2.16.0
Locale: en-US
---

Expand Down
6 changes: 2 additions & 4 deletions src/Catesta.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ Add-BuildTask Test {
if ($env:CI -and $IsMacOS) {
# the MacOS github action does not properly detect the relative path.
Write-Build White " CI: $env:CI and MacOS action detected. Hard coding path."
$pesterConfiguration.CodeCoverage.Path = "/Users/runner/work/Catesta/Catesta/src/Catesta/*/*.ps1"
$pesterConfiguration.CodeCoverage.Path = "/Users/runner/work/$ModuleName/$ModuleName/src/$ModuleName/*/*.ps1"
}
else {
$pesterConfiguration.CodeCoverage.Path = "..\..\..\$ModuleName\*\*.ps1"
$pesterConfiguration.CodeCoverage.Path = "..\..\..\src\$ModuleName\*\*.ps1"
}
$pesterConfiguration.TestResult.Enabled = $true
$pesterConfiguration.TestResult.OutputPath = "$testOutPutPath\PesterTests.xml"
Expand Down Expand Up @@ -526,8 +526,6 @@ Add-BuildTask Build {
Write-Build Green ' ...Build Complete!'
} #Build

# TODO: schema generator step

#Synopsis: Invokes all Pester Integration Tests in the Tests\Integration folder (if it exists)
Add-BuildTask IntegrationTest {
if (Test-Path -Path $script:IntegrationTestsPath) {
Expand Down
2 changes: 1 addition & 1 deletion src/Catesta/Catesta.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'Catesta.psm1'

# Version number of this module.
ModuleVersion = '2.13.0'
ModuleVersion = '2.16.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
2 changes: 1 addition & 1 deletion src/Catesta/Resources/Module/plasterManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<metadata>
<name>Catesta</name>
<id>258a61ba-566b-4c3a-8230-c2b6861a1a8d</id>
<version>2.13.0</version>
<version>2.16.0</version>
<title>Catesta</title>
<description>Scaffolds a new PowerShell module project</description>
<author>Jake Morrison</author>
Expand Down
2 changes: 1 addition & 1 deletion src/Catesta/Resources/Module/src/PSModule.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ elseif ($PLASTER_PARAM_Pester -eq '5') {
$pesterConfiguration.Run.PassThru = $true
$pesterConfiguration.Run.Exit = $false
$pesterConfiguration.CodeCoverage.Enabled = $true
$pesterConfiguration.CodeCoverage.Path = "..\..\..\$ModuleName\*\*.ps1"
$pesterConfiguration.CodeCoverage.Path = "..\..\..\src\$ModuleName\*\*.ps1"
$pesterConfiguration.CodeCoverage.CoveragePercentTarget = $script:coverageThreshold
$pesterConfiguration.CodeCoverage.OutputPath = "$codeCovPath\CodeCoverage.xml"
$pesterConfiguration.CodeCoverage.OutputFormat = 'JaCoCo'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# #-------------------------------------------------------------------------
# Set-Location -Path $PSScriptRoot
# #-------------------------------------------------------------------------
# $ModuleName = '<%=$PLASTER_PARAM_ModuleName%>'
# #-------------------------------------------------------------------------
# #if the module is already in memory, remove it
# Get-Module $ModuleName | Remove-Module -Force
# $PathToManifest = [System.IO.Path]::Combine('..', '..', 'Artifacts', "$ModuleName.psd1")
# #-------------------------------------------------------------------------
# Import-Module $PathToManifest -Force
# #-------------------------------------------------------------------------
# BeforeAll {
# Set-Location -Path $PSScriptRoot
# $ModuleName = '<%=$PLASTER_PARAM_ModuleName%>'
# $PathToManifest = [System.IO.Path]::Combine('..', '..', 'Artifacts', "$ModuleName.psd1")
# #if the module is already in memory, remove it
# Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force
# Import-Module $PathToManifest -Force
# }

# Describe 'Integration Tests' -Tag Integration {
# Context 'First Integration Tests' {
# It 'should pass the first integration test' {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
#-------------------------------------------------------------------------
Set-Location -Path $PSScriptRoot
#-------------------------------------------------------------------------
$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>'
$PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1")
#-------------------------------------------------------------------------
if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') {
#if the module is already in memory, remove it
Remove-Module -Name $ModuleName -Force
}
Import-Module $PathToManifest -Force
#-------------------------------------------------------------------------

BeforeAll {
Set-Location -Path $PSScriptRoot
$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>'
$PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1")
Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force
Import-Module $PathToManifest -Force
$manifestContent = Test-ModuleManifest -Path $PathToManifest
$moduleExported = Get-Command -Module $ModuleName | Select-Object -ExpandProperty Name
$manifestExported = ($manifestContent.ExportedFunctions).Keys
}
BeforeDiscovery {
Set-Location -Path $PSScriptRoot
$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>'
$PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1")
Expand All @@ -24,43 +21,40 @@ Describe $ModuleName {
Context 'Exported Commands' -Fixture {

Context 'Number of commands' -Fixture {
It -Name 'Exports the same number of public functions as what is listed in the Module Manifest' -Test {

It 'Exports the same number of public functions as what is listed in the Module Manifest' {
$manifestExported.Count | Should -BeExactly $moduleExported.Count
}

}

Context 'Explicitly exported commands' -ForEach $moduleExported {
foreach ($command in $moduleExported) {
BeforeAll {
$command = $_
}
It -Name "Includes the $command in the Module Manifest ExportedFunctions" -Test {
$manifestExported -contains $command | Should -BeTrue
}
Context 'Explicitly exported commands' {

It 'Includes <_> in the Module Manifest ExportedFunctions' -ForEach $moduleExported {
$manifestExported -contains $_ | Should -BeTrue
}

}
}
} #context_ExportedCommands

Context 'Command Help' -ForEach $moduleExported {
foreach ($command in $moduleExported) {
BeforeAll {
Context 'Command Help' -Fixture {
Context '<_>' -Foreach $moduleExported {

BeforeEach {
$help = Get-Help -Name $_ -Full
}
Context $command -Fixture {
$help = Get-Help -Name $command -Full

It -Name 'Includes a Synopsis' -Test {
$help.Synopsis | Should -Not -BeNullOrEmpty
}
It -Name 'Includes a Synopsis' -Test {
$help.Synopsis | Should -Not -BeNullOrEmpty
}

It -Name 'Includes a Description' -Test {
$help.description.Text | Should -Not -BeNullOrEmpty
}
It -Name 'Includes a Description' -Test {
$help.description.Text | Should -Not -BeNullOrEmpty
}

It -Name 'Includes an Example' -Test {
$help.examples.example | Should -Not -BeNullOrEmpty
}
It -Name 'Includes an Example' -Test {
$help.examples.example | Should -Not -BeNullOrEmpty
}
}
}
}
} #context_CommandHelp
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#-------------------------------------------------------------------------
Set-Location -Path $PSScriptRoot
#-------------------------------------------------------------------------
$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>'
$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1")
#-------------------------------------------------------------------------
if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') {
BeforeAll {
Set-Location -Path $PSScriptRoot
$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>'
$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1")
#if the module is already in memory, remove it
Remove-Module -Name $ModuleName -Force
Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force
Import-Module $PathToManifest -Force
}
Import-Module $PathToManifest -Force
#-------------------------------------------------------------------------

InModuleScope '<%=$PLASTER_PARAM_ModuleName%>' {
#-------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#-------------------------------------------------------------------------
Set-Location -Path $PSScriptRoot
#-------------------------------------------------------------------------
$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>'
$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1")
#-------------------------------------------------------------------------
if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') {
BeforeAll {
Set-Location -Path $PSScriptRoot
$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>'
$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1")
#if the module is already in memory, remove it
Remove-Module -Name $ModuleName -Force
Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force
Import-Module $PathToManifest -Force
}
Import-Module $PathToManifest -Force
#-------------------------------------------------------------------------

InModuleScope '<%=$PLASTER_PARAM_ModuleName%>' {
Describe 'Get-HelloWorld Public Function Tests' -Tag Unit {
Expand Down
2 changes: 1 addition & 1 deletion src/Catesta/Resources/Vault/plasterManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<metadata>
<name>Catesta</name>
<id>d531e058-52b8-4dd2-8162-01c95d1eb8f7</id>
<version>2.13.0</version>
<version>2.16.0</version>
<title>Catesta</title>
<description>Scaffolds a new PowerShell SecretManagement extension vault module project</description>
<author>Jake Morrison</author>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
#-------------------------------------------------------------------------
Set-Location -Path $PSScriptRoot
#-------------------------------------------------------------------------
$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>'
$PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1")
#-------------------------------------------------------------------------
if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') {
#if the module is already in memory, remove it
Remove-Module -Name $ModuleName -Force
}
Import-Module $PathToManifest -Force
#-------------------------------------------------------------------------

BeforeAll {
Set-Location -Path $PSScriptRoot
$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>'
$PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1")
Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force
Import-Module $PathToManifest -Force
$manifestContent = Test-ModuleManifest -Path $PathToManifest
$moduleExported = Get-Command -Module $ModuleName | Select-Object -ExpandProperty Name
$manifestExported = ($manifestContent.ExportedFunctions).Keys
}
BeforeDiscovery {
Set-Location -Path $PSScriptRoot
$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>'
$PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1")
Expand All @@ -24,21 +21,20 @@ Describe $ModuleName {
Context 'Exported Commands' -Fixture {

Context 'Number of commands' -Fixture {
It -Name 'Exports the same number of public functions as what is listed in the Module Manifest' -Test {

It 'Exports the same number of public functions as what is listed in the Module Manifest' {
$manifestExported.Count | Should -BeExactly $moduleExported.Count
}

}

Context 'Explicitly exported commands' -ForEach $moduleExported {
foreach ($command in $moduleExported) {
BeforeAll {
$command = $_
}
It -Name "Includes the $command in the Module Manifest ExportedFunctions" -Test {
$manifestExported -contains $command | Should -BeTrue
}
Context 'Explicitly exported commands' {

It 'Includes <_> in the Module Manifest ExportedFunctions' -ForEach $moduleExported {
$manifestExported -contains $_ | Should -BeTrue
}

}
}
} #context_ExportedCommands

}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#-------------------------------------------------------------------------
Set-Location -Path $PSScriptRoot
#-------------------------------------------------------------------------
$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>'
$vaultName = '<%=$PLASTER_PARAM_ModuleName%>'
$PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1")
#-------------------------------------------------------------------------
if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') {
BeforeAll {
Set-Location -Path $PSScriptRoot
$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>'
$vaultName = '<%=$PLASTER_PARAM_ModuleName%>'
$PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1")
#if the module is already in memory, remove it
Remove-Module -Name $ModuleName -Force
Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force
Import-Module $PathToManifest -Force
}
Import-Module $PathToManifest -Force
#-------------------------------------------------------------------------

Describe '<%=$PLASTER_PARAM_ModuleName%> Vault Extension Tests' -Tag Unit {
BeforeAll {
Expand All @@ -33,4 +29,4 @@ Describe '<%=$PLASTER_PARAM_ModuleName%> Vault Extension Tests' -Tag Unit {
} #it

} #context_FunctionName
} #describe_vaultExtension
} #describe_vaultExtension
14 changes: 7 additions & 7 deletions src/Tests/Integration/FileChecks.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#-------------------------------------------------------------------------
Set-Location -Path $PSScriptRoot
#-------------------------------------------------------------------------
$ModuleName = 'Catesta'
$resourcePath1 = [System.IO.Path]::Combine( '..', '..', 'Artifacts', 'Resources')
$manifests = Get-ChildItem -Path $resourcePath1 -Include '*.xml' -Recurse
#-------------------------------------------------------------------------
BeforeAll {
Set-Location -Path $PSScriptRoot
$ModuleName = 'Catesta'
$resourcePath1 = [System.IO.Path]::Combine( '..', '..', 'Artifacts', 'Resources')
$manifests = Get-ChildItem -Path $resourcePath1 -Include '*.xml' -Recurse
}

Describe 'File Checks' {
BeforeAll {
$WarningPreference = 'Continue'
Expand Down
23 changes: 9 additions & 14 deletions src/Tests/Integration/New-ModuleProject.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#-------------------------------------------------------------------------
Set-Location -Path $PSScriptRoot
#-------------------------------------------------------------------------
$ModuleName = 'Catesta'
#-------------------------------------------------------------------------
#if the module is already in memory, remove it
Get-Module $ModuleName | Remove-Module -Force
$PathToManifest = [System.IO.Path]::Combine('..', '..', 'Artifacts', "$ModuleName.psd1")
#-------------------------------------------------------------------------
Import-Module $PathToManifest -Force
#-------------------------------------------------------------------------
$resourcePath1 = [System.IO.Path]::Combine( '..', '..', $ModuleName, 'Resources')
# $manifests = Get-ChildItem -Path $resourcePath1 -Include '*.xml' -Recurse -Force
#-------------------------------------------------------------------------
BeforeAll {
Set-Location -Path $PSScriptRoot
$ModuleName = 'Catesta'
$PathToManifest = [System.IO.Path]::Combine('..', '..', 'Artifacts', "$ModuleName.psd1")
#if the module is already in memory, remove it
Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force
Import-Module $PathToManifest -Force
}

Describe 'Module Integration Tests' {

BeforeAll {
Expand Down
Loading

0 comments on commit 215e499

Please sign in to comment.