From 215e499e22dfe2921eed0e70b8b22bafeb577e02 Mon Sep 17 00:00:00 2001 From: Jake Morrison Date: Wed, 7 Aug 2024 18:34:11 -0500 Subject: [PATCH] fixes #88 - refactored pester 5 samples to follow pester 5 rules --- docs/CHANGELOG.md | 6 +- docs/Catesta.md | 2 +- src/Catesta.build.ps1 | 6 +- src/Catesta/Catesta.psd1 | 2 +- .../Resources/Module/plasterManifest.xml | 2 +- .../Resources/Module/src/PSModule.build.ps1 | 2 +- .../SampleIntegrationTest.Tests.ps1 | 20 +++--- .../Tests/v5/Unit/ExportedFunctions.Tests.ps1 | 72 +++++++++---------- .../Unit/Private/Private-Function.Tests.ps1 | 16 ++--- .../v5/Unit/Public/Public-Function.Tests.ps1 | 16 ++--- .../Resources/Vault/plasterManifest.xml | 2 +- .../Tests/v5/Unit/ExportedFunctions.Tests.ps1 | 44 ++++++------ .../Tests/v5/Unit/Module-Function.Tests.ps1 | 20 +++--- src/Tests/Integration/FileChecks.Tests.ps1 | 14 ++-- .../Integration/New-ModuleProject.Tests.ps1 | 23 +++--- .../Integration/New-VaultProject.Tests.ps1 | 23 +++--- src/Tests/Unit/ExportedFunctions.Tests.ps1 | 72 +++++++++---------- .../Unit/Public/New-ModuleProject.Tests.ps1 | 20 +++--- .../Unit/Public/New-VaultProject.Tests.ps1 | 20 +++--- 19 files changed, 170 insertions(+), 212 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index ac02b15..478315f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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 @@ -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] diff --git a/docs/Catesta.md b/docs/Catesta.md index 3ef901b..b38a8d7 100644 --- a/docs/Catesta.md +++ b/docs/Catesta.md @@ -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 --- diff --git a/src/Catesta.build.ps1 b/src/Catesta.build.ps1 index dd6b1e0..6037110 100644 --- a/src/Catesta.build.ps1 +++ b/src/Catesta.build.ps1 @@ -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" @@ -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) { diff --git a/src/Catesta/Catesta.psd1 b/src/Catesta/Catesta.psd1 index 27aadf3..1149875 100644 --- a/src/Catesta/Catesta.psd1 +++ b/src/Catesta/Catesta.psd1 @@ -12,7 +12,7 @@ RootModule = 'Catesta.psm1' # Version number of this module. - ModuleVersion = '2.13.0' + ModuleVersion = '2.16.0' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/src/Catesta/Resources/Module/plasterManifest.xml b/src/Catesta/Resources/Module/plasterManifest.xml index 989da5d..a27cb1e 100644 --- a/src/Catesta/Resources/Module/plasterManifest.xml +++ b/src/Catesta/Resources/Module/plasterManifest.xml @@ -18,7 +18,7 @@ Catesta 258a61ba-566b-4c3a-8230-c2b6861a1a8d - 2.13.0 + 2.16.0 Catesta Scaffolds a new PowerShell module project Jake Morrison diff --git a/src/Catesta/Resources/Module/src/PSModule.build.ps1 b/src/Catesta/Resources/Module/src/PSModule.build.ps1 index b19c7c6..6a428e1 100644 --- a/src/Catesta/Resources/Module/src/PSModule.build.ps1 +++ b/src/Catesta/Resources/Module/src/PSModule.build.ps1 @@ -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' diff --git a/src/Catesta/Resources/Module/src/Tests/v5/Integration/SampleIntegrationTest.Tests.ps1 b/src/Catesta/Resources/Module/src/Tests/v5/Integration/SampleIntegrationTest.Tests.ps1 index ed629e3..b0a334c 100644 --- a/src/Catesta/Resources/Module/src/Tests/v5/Integration/SampleIntegrationTest.Tests.ps1 +++ b/src/Catesta/Resources/Module/src/Tests/v5/Integration/SampleIntegrationTest.Tests.ps1 @@ -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' { diff --git a/src/Catesta/Resources/Module/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 b/src/Catesta/Resources/Module/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 index cced9cf..d12fb9a 100644 --- a/src/Catesta/Resources/Module/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 +++ b/src/Catesta/Resources/Module/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 @@ -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") @@ -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 } } - } -} \ No newline at end of file + } #context_CommandHelp +} diff --git a/src/Catesta/Resources/Module/src/Tests/v5/Unit/Private/Private-Function.Tests.ps1 b/src/Catesta/Resources/Module/src/Tests/v5/Unit/Private/Private-Function.Tests.ps1 index 565cacf..73e8a2b 100644 --- a/src/Catesta/Resources/Module/src/Tests/v5/Unit/Private/Private-Function.Tests.ps1 +++ b/src/Catesta/Resources/Module/src/Tests/v5/Unit/Private/Private-Function.Tests.ps1 @@ -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%>' { #------------------------------------------------------------------------- diff --git a/src/Catesta/Resources/Module/src/Tests/v5/Unit/Public/Public-Function.Tests.ps1 b/src/Catesta/Resources/Module/src/Tests/v5/Unit/Public/Public-Function.Tests.ps1 index 8f158ab..e87dbde 100644 --- a/src/Catesta/Resources/Module/src/Tests/v5/Unit/Public/Public-Function.Tests.ps1 +++ b/src/Catesta/Resources/Module/src/Tests/v5/Unit/Public/Public-Function.Tests.ps1 @@ -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 { diff --git a/src/Catesta/Resources/Vault/plasterManifest.xml b/src/Catesta/Resources/Vault/plasterManifest.xml index af7dde9..b52bf64 100644 --- a/src/Catesta/Resources/Vault/plasterManifest.xml +++ b/src/Catesta/Resources/Vault/plasterManifest.xml @@ -6,7 +6,7 @@ Catesta d531e058-52b8-4dd2-8162-01c95d1eb8f7 - 2.13.0 + 2.16.0 Catesta Scaffolds a new PowerShell SecretManagement extension vault module project Jake Morrison diff --git a/src/Catesta/Resources/Vault/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 b/src/Catesta/Resources/Vault/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 index d16fb79..aa447e3 100644 --- a/src/Catesta/Resources/Vault/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 +++ b/src/Catesta/Resources/Vault/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 @@ -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") @@ -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 -} \ No newline at end of file +} diff --git a/src/Catesta/Resources/Vault/src/Tests/v5/Unit/Module-Function.Tests.ps1 b/src/Catesta/Resources/Vault/src/Tests/v5/Unit/Module-Function.Tests.ps1 index 4a51dc0..0603f14 100644 --- a/src/Catesta/Resources/Vault/src/Tests/v5/Unit/Module-Function.Tests.ps1 +++ b/src/Catesta/Resources/Vault/src/Tests/v5/Unit/Module-Function.Tests.ps1 @@ -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 { @@ -33,4 +29,4 @@ Describe '<%=$PLASTER_PARAM_ModuleName%> Vault Extension Tests' -Tag Unit { } #it } #context_FunctionName -} #describe_vaultExtension \ No newline at end of file +} #describe_vaultExtension diff --git a/src/Tests/Integration/FileChecks.Tests.ps1 b/src/Tests/Integration/FileChecks.Tests.ps1 index 6aa833e..caa913e 100644 --- a/src/Tests/Integration/FileChecks.Tests.ps1 +++ b/src/Tests/Integration/FileChecks.Tests.ps1 @@ -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' diff --git a/src/Tests/Integration/New-ModuleProject.Tests.ps1 b/src/Tests/Integration/New-ModuleProject.Tests.ps1 index 05088bb..2cc1eb9 100644 --- a/src/Tests/Integration/New-ModuleProject.Tests.ps1 +++ b/src/Tests/Integration/New-ModuleProject.Tests.ps1 @@ -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 { diff --git a/src/Tests/Integration/New-VaultProject.Tests.ps1 b/src/Tests/Integration/New-VaultProject.Tests.ps1 index ca3f14d..b6ba715 100644 --- a/src/Tests/Integration/New-VaultProject.Tests.ps1 +++ b/src/Tests/Integration/New-VaultProject.Tests.ps1 @@ -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 'Vault Integration Tests' { BeforeAll { diff --git a/src/Tests/Unit/ExportedFunctions.Tests.ps1 b/src/Tests/Unit/ExportedFunctions.Tests.ps1 index 23909a6..cad8586 100644 --- a/src/Tests/Unit/ExportedFunctions.Tests.ps1 +++ b/src/Tests/Unit/ExportedFunctions.Tests.ps1 @@ -1,17 +1,14 @@ -#------------------------------------------------------------------------- -Set-Location -Path $PSScriptRoot -#------------------------------------------------------------------------- -$ModuleName = 'Catesta' -$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 = 'Catesta' + $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 = 'Catesta' $PathToManifest = [System.IO.Path]::Combine('..\', '..\', $ModuleName, "$ModuleName.psd1") @@ -19,48 +16,45 @@ BeforeAll { $moduleExported = Get-Command -Module $ModuleName | Select-Object -ExpandProperty Name $manifestExported = ($manifestContent.ExportedFunctions).Keys } -Describe $ModuleName { +Describe 'Catesta Functions' -Tag Unit { 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' -Fixture { + Context '<_>' -Foreach $moduleExported { - Context 'Command Help' -Foreach $moduleExported { - foreach ($command in $moduleExported) { - BeforeAll { + 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 } diff --git a/src/Tests/Unit/Public/New-ModuleProject.Tests.ps1 b/src/Tests/Unit/Public/New-ModuleProject.Tests.ps1 index f5aa3e6..56beb63 100644 --- a/src/Tests/Unit/Public/New-ModuleProject.Tests.ps1 +++ b/src/Tests/Unit/Public/New-ModuleProject.Tests.ps1 @@ -1,14 +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('..', '..', '..', $ModuleName, "$ModuleName.psd1") -#------------------------------------------------------------------------- -Import-Module $PathToManifest -Force -#------------------------------------------------------------------------- +BeforeAll { + Set-Location -Path $PSScriptRoot + $ModuleName = 'Catesta' + $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") + #if the module is already in memory, remove it + Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force + Import-Module $PathToManifest -Force +} + InModuleScope $ModuleName { $functionName = 'New-ModuleProject' Describe "$functionName Function Tests" -Tag Unit { diff --git a/src/Tests/Unit/Public/New-VaultProject.Tests.ps1 b/src/Tests/Unit/Public/New-VaultProject.Tests.ps1 index b7e5d8a..7f21060 100644 --- a/src/Tests/Unit/Public/New-VaultProject.Tests.ps1 +++ b/src/Tests/Unit/Public/New-VaultProject.Tests.ps1 @@ -1,14 +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('..', '..', '..', $ModuleName, "$ModuleName.psd1") -#------------------------------------------------------------------------- -Import-Module $PathToManifest -Force -#------------------------------------------------------------------------- +BeforeAll { + Set-Location -Path $PSScriptRoot + $ModuleName = 'Catesta' + $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") + #if the module is already in memory, remove it + Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force + Import-Module $PathToManifest -Force +} + InModuleScope $ModuleName { $functionName = 'New-VaultProject' Describe "$functionName Function Tests" -Tag Unit {