From 0f81b2c998eb3efde2d8d5ba0862dac3a85cd205 Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Thu, 6 May 2021 09:13:33 -0400 Subject: [PATCH 1/9] (#413) Update to Pester v5.2.0 --- PSKoans/PSKoans.psd1 | 358 +++++++++++++++++++++---------------------- 1 file changed, 179 insertions(+), 179 deletions(-) diff --git a/PSKoans/PSKoans.psd1 b/PSKoans/PSKoans.psd1 index df3e9e77a..043293bf9 100644 --- a/PSKoans/PSKoans.psd1 +++ b/PSKoans/PSKoans.psd1 @@ -1,179 +1,179 @@ -# -# Module manifest for module 'PSKoans' -# -# Generated by: Joel Sallow -# -# Generated on: 7/8/2018 -# - -@{ - - # Script module or binary module file associated with this manifest. - RootModule = 'PSKoans.psm1' - - # Version number of this module. - ModuleVersion = '0.67.0' - - # Supported PSEditions - CompatiblePSEditions = @('Desktop', 'Core') - - # ID used to uniquely identify this module - GUID = '45003073-0315-4aef-862f-4d9ff1bd8f4a' - - # Author of this module - Author = 'Joel Sallow' - - # Company or vendor of this module - CompanyName = 'None' - - # Copyright statement for this module - Copyright = '(c) 2019 Joel Sallow (/u/ta11ow). All rights reserved.' - - # Description of the functionality provided by this module - Description = 'A module designed to provide a crash-course introduction to PowerShell with programming koans.' - - # Minimum version of the Windows PowerShell engine required by this module - PowerShellVersion = '5.1' - - # Name of the Windows PowerShell host required by this module - # PowerShellHostName = '' - - # Minimum version of the Windows PowerShell host required by this module - # PowerShellHostVersion = '' - - # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. - # DotNetFrameworkVersion = '' - - # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. - # CLRVersion = '' - - # Processor architecture (None, X86, Amd64) required by this module - ProcessorArchitecture = 'None' - - # Modules that must be imported into the global environment prior to importing this module - RequiredModules = @( - @{ - ModuleName = 'Pester' - ModuleVersion = '5.0.2' - } - ) - - # Assemblies that must be loaded prior to importing this module - # RequiredAssemblies = @() - - # Script files (.ps1) that are run in the caller's environment prior to importing this module. - ScriptsToProcess = @( 'DummyTypes.ps1' ) - - # Type files (.ps1xml) to be loaded when importing this module - # TypesToProcess = @() - - # Format files (.ps1xml) to be loaded when importing this module - FormatsToProcess = @( 'PSKoans.format.ps1xml' ) - - # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess - # NestedModules = @() - - # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. - FunctionsToExport = @( - 'Get-Blank' - 'Get-Karma' - 'Get-PSKoan' - 'Get-PSKoanLocation' - 'Get-PSKoanSetting' - - 'Set-PSKoanLocation' - 'Set-PSKoanSetting' - - 'Move-PSKoanLibrary' - - 'Register-Advice' - - 'Reset-PSKoan' - - 'Show-Advice' - 'Show-Karma' - - 'Update-PSKoan' - ) - - # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. - CmdletsToExport = @() - - # Variables to export from this module - VariablesToExport = '*' - - # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. - AliasesToExport = @( - 'Invoke-PSKoans' - 'Test-Koans' - - '__' - '____' - 'FILL_ME_IN' - - 'Clear-Path' - - 'Get-Advice' - - 'Get-Enlightenment' - 'Measure-Karma' - ) - - # DSC resources to export from this module - # DscResourcesToExport = @() - - # List of all modules packaged with this module - # ModuleList = @() - - # List of all files packaged with this module - # FileList = @() - - # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. - PrivateData = @{ - - Colors = @{ - - Meditation = @{ - Text = "#7AAFCA" - Emphasis = "#DACF60" - Passed = "#30DF60" - Error = '#E02020' - Progress = '#CACEFA' - } - - } - - PSData = @{ - - # Tags applied to this module. These help with module discovery in online galleries. - Tags = @( - 'Pester' - 'Koans' - 'Educational' - 'Windows' - 'MacOS' - 'Linux' - ) - - # A URL to the license for this module. - LicenseUri = 'https://github.com/vexx32/PSKoans/blob/main/LICENSE' - - # A URL to the main website for this project. - ProjectUri = 'https://github.com/vexx32/PSKoans' - - # A URL to an icon representing this module. - # IconUri = '' - - # ReleaseNotes of this module - # ReleaseNotes = '' - - } # End of PSData hashtable - - } # End of PrivateData hashtable - - # HelpInfo URI of this module - # HelpInfoURI = '' - - # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. - # DefaultCommandPrefix = '' -} +# +# Module manifest for module 'PSKoans' +# +# Generated by: Joel Sallow +# +# Generated on: 7/8/2018 +# + +@{ + + # Script module or binary module file associated with this manifest. + RootModule = 'PSKoans.psm1' + + # Version number of this module. + ModuleVersion = '0.67.0' + + # Supported PSEditions + CompatiblePSEditions = @('Desktop', 'Core') + + # ID used to uniquely identify this module + GUID = '45003073-0315-4aef-862f-4d9ff1bd8f4a' + + # Author of this module + Author = 'Joel Sallow' + + # Company or vendor of this module + CompanyName = 'None' + + # Copyright statement for this module + Copyright = '(c) 2019 Joel Sallow (/u/ta11ow). All rights reserved.' + + # Description of the functionality provided by this module + Description = 'A module designed to provide a crash-course introduction to PowerShell with programming koans.' + + # Minimum version of the Windows PowerShell engine required by this module + PowerShellVersion = '5.1' + + # Name of the Windows PowerShell host required by this module + # PowerShellHostName = '' + + # Minimum version of the Windows PowerShell host required by this module + # PowerShellHostVersion = '' + + # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # DotNetFrameworkVersion = '' + + # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # CLRVersion = '' + + # Processor architecture (None, X86, Amd64) required by this module + ProcessorArchitecture = 'None' + + # Modules that must be imported into the global environment prior to importing this module + RequiredModules = @( + @{ + ModuleName = 'Pester' + ModuleVersion = '5.2.0' + } + ) + + # Assemblies that must be loaded prior to importing this module + # RequiredAssemblies = @() + + # Script files (.ps1) that are run in the caller's environment prior to importing this module. + ScriptsToProcess = @( 'DummyTypes.ps1' ) + + # Type files (.ps1xml) to be loaded when importing this module + # TypesToProcess = @() + + # Format files (.ps1xml) to be loaded when importing this module + FormatsToProcess = @( 'PSKoans.format.ps1xml' ) + + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess + # NestedModules = @() + + # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. + FunctionsToExport = @( + 'Get-Blank' + 'Get-Karma' + 'Get-PSKoan' + 'Get-PSKoanLocation' + 'Get-PSKoanSetting' + + 'Set-PSKoanLocation' + 'Set-PSKoanSetting' + + 'Move-PSKoanLibrary' + + 'Register-Advice' + + 'Reset-PSKoan' + + 'Show-Advice' + 'Show-Karma' + + 'Update-PSKoan' + ) + + # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. + CmdletsToExport = @() + + # Variables to export from this module + VariablesToExport = '*' + + # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. + AliasesToExport = @( + 'Invoke-PSKoans' + 'Test-Koans' + + '__' + '____' + 'FILL_ME_IN' + + 'Clear-Path' + + 'Get-Advice' + + 'Get-Enlightenment' + 'Measure-Karma' + ) + + # DSC resources to export from this module + # DscResourcesToExport = @() + + # List of all modules packaged with this module + # ModuleList = @() + + # List of all files packaged with this module + # FileList = @() + + # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. + PrivateData = @{ + + Colors = @{ + + Meditation = @{ + Text = "#7AAFCA" + Emphasis = "#DACF60" + Passed = "#30DF60" + Error = '#E02020' + Progress = '#CACEFA' + } + + } + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + Tags = @( + 'Pester' + 'Koans' + 'Educational' + 'Windows' + 'MacOS' + 'Linux' + ) + + # A URL to the license for this module. + LicenseUri = 'https://github.com/vexx32/PSKoans/blob/main/LICENSE' + + # A URL to the main website for this project. + ProjectUri = 'https://github.com/vexx32/PSKoans' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + } # End of PSData hashtable + + } # End of PrivateData hashtable + + # HelpInfo URI of this module + # HelpInfoURI = '' + + # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. + # DefaultCommandPrefix = '' +} From 3dfd0dbdac3effabc5df326adbe2cb65bb78d6d5 Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Thu, 6 May 2021 09:15:57 -0400 Subject: [PATCH 2/9] (#413) Refactor Measure-Koan to use SkipRun Pester v5.2.0 added the ability to natively run just the discovery phase of a test suite, so we refactor Measure-Koan to utilize this and save doing a lot of manual work. This also obsoletes the private Measure-KoanTestBlock command that previously supported Measure-Koan. Pester automatically does that calculation on its own before presenting the discovery results. This command has been removed as a result. --- PSKoans/Private/Measure-Koan.ps1 | 52 +++++++---------------- PSKoans/Private/Measure-KoanBlockTest.ps1 | 23 ---------- 2 files changed, 16 insertions(+), 59 deletions(-) delete mode 100644 PSKoans/Private/Measure-KoanBlockTest.ps1 diff --git a/PSKoans/Private/Measure-Koan.ps1 b/PSKoans/Private/Measure-Koan.ps1 index 3fbc7169b..cf4dadf41 100644 --- a/PSKoans/Private/Measure-Koan.ps1 +++ b/PSKoans/Private/Measure-Koan.ps1 @@ -31,51 +31,31 @@ ) begin { $KoanCount = 0 - $oldModulePath = $env:PSModulePath - $env:PSModulePath = @( - $MyInvocation.MyCommand.Module.ModuleBase - $env:PSModulePath -split [System.IO.Path]::PathSeparator - ) -join [System.IO.Path]::PathSeparator + $configuration = New-PesterConfiguration + $configuration.Output.Verbosity = 'None' + $configuration.Run.SkipRun = $true + $configuration.Run.PassThru = $true + $configuration.Run.TestExtension = ".Koans.ps1" } process { - Write-Verbose "Discovering koans in [$($KoanInfo.Name -join '], [')]" + $koanTopics = "[$($KoanInfo.Name -join '], [')]" + Write-Verbose "Discovering koans in $koanTopics" + $configuration.Run.Path = $KoanInfo.Path - $Result = & (Get-Module Pester) { - [CmdletBinding()] - param( - $Path, - $ExcludePath, - $SessionState - ) + <# + Null-redirecting stream 6 is necessary because the message about skipping the test run still displays + even if the output verbosity is set to 'None' in Pester 5.2.0. - $_Pester_State_Backup = $state.PSObject.Copy() - $state.Stack = [System.Collections.Stack]@() - try { - Reset-TestSuiteState + Github issue: https://github.com/pester/Pester/issues/1933 + #> + $Result = Invoke-Pester -Configuration $configuration 6> $null - # to avoid Describe thinking that we run in interactive mode - $invokedViaInvokePester = $true - - $fileList = Find-File -Path $Path -ExcludePath $ExcludePath -Extension '.Koans.ps1' - $containers = foreach ($file in $fileList) { - New-BlockContainerObject -File (Get-Item $file) - } - - Find-Test -BlockContainer $containers -SessionState $SessionState - } - finally { - $state = $_Pester_State_Backup - Remove-Variable -Name _Pester_State_Backup - } - } -Path $KoanInfo.Path -SessionState $PSCmdlet.SessionState - - $KoanCount += Measure-KoanTestBlock $Result + Write-Debug "Found $($Result.TotalCount) koans in $koanTopics" + $KoanCount += $Result.TotalCount } end { Write-Verbose "Total Koans: $KoanCount" $KoanCount - - $env:PSModulePath = $oldModulePath } } diff --git a/PSKoans/Private/Measure-KoanBlockTest.ps1 b/PSKoans/Private/Measure-KoanBlockTest.ps1 deleted file mode 100644 index 7304cf91d..000000000 --- a/PSKoans/Private/Measure-KoanBlockTest.ps1 +++ /dev/null @@ -1,23 +0,0 @@ -function Measure-KoanTestBlock { - [CmdletBinding()] - param( - [Parameter(Mandatory)] - [psobject] - $Block - ) - - $Label = if ($Block.Name) { - "Block $($Block.Name)" - } - else { - "File $($Block.BlockContainer.Item)" - } - - $Count = $Block.Tests.Count - foreach ($testBlock in $Block.Blocks) { - $Count += Measure-KoanTestBlock $testBlock - } - - $Count - Write-Information "$Label Tests: $Count" -} From 9f56b0695dff28e8b85f1472048bd1dffc4ae6b0 Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Thu, 6 May 2021 09:16:22 -0400 Subject: [PATCH 3/9] (maint) Bump PSKoans version to 0.68 --- PSKoans/PSKoans.psd1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PSKoans/PSKoans.psd1 b/PSKoans/PSKoans.psd1 index 043293bf9..620719885 100644 --- a/PSKoans/PSKoans.psd1 +++ b/PSKoans/PSKoans.psd1 @@ -1,4 +1,4 @@ -# +# # Module manifest for module 'PSKoans' # # Generated by: Joel Sallow @@ -12,7 +12,7 @@ RootModule = 'PSKoans.psm1' # Version number of this module. - ModuleVersion = '0.67.0' + ModuleVersion = '0.68.0' # Supported PSEditions CompatiblePSEditions = @('Desktop', 'Core') From 1220b16e39dd2bc1819ccf2a876077cbc476aac7 Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Thu, 6 May 2021 12:11:20 -0400 Subject: [PATCH 4/9] :rocket: (maint) Ensure build publishes Pester In some cases it looks like Pester can fail to publish if there are too many versions of Pester available. Prevent this by checking the version we actually need and publishing just that version when doing a publish to the filesystem. Also set the initially installed version of pester to the correct version based on the current required version specified by PSKoans itself, instead of having to update the environment-setup.yml each time. --- Deploy/Publish.ps1 | 6 +++--- templates/environment-setup.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Deploy/Publish.ps1 b/Deploy/Publish.ps1 index b567722a4..b17e3e5c6 100644 --- a/Deploy/Publish.ps1 +++ b/Deploy/Publish.ps1 @@ -16,12 +16,12 @@ if ($OutputDirectory) { Import-Module "$PSScriptRoot/PSKoans" $Module = Get-Module -Name PSKoans $Dependencies = @( - $Module.RequiredModules.Name - $Module.NestedModules.Name + $Module.RequiredModules | Select-Object -Property Name, Version + $Module.NestedModules | Select-Object -Property Name, Version ).Where{ $_ } foreach ($Module in $Dependencies) { - Publish-Module -Name $Module -Repository FileSystem -NugetApiKey "Test-Publish" + Publish-Module -Name $Module.Name -Repository FileSystem -NugetApiKey "Test-Publish" -RequiredVersion $Module.Version } } diff --git a/templates/environment-setup.yml b/templates/environment-setup.yml index 634a3f602..b24f3232c 100644 --- a/templates/environment-setup.yml +++ b/templates/environment-setup.yml @@ -17,7 +17,7 @@ steps: $Params.Name = 'Pester' $Params.SkipPublisherCheck = $true - $Params.MinimumVersion = '5.0.2' + $Params.MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version $Params | Out-String | Write-Host Install-Module @Params $Params.Remove('SkipPublisherCheck') From a7d78ea21442fc758af2ccc983548c7cd51b8d59 Mon Sep 17 00:00:00 2001 From: "Joel Sallow (/u/ta11ow)" <32407840+vexx32@users.noreply.github.com> Date: Mon, 10 May 2021 20:31:13 -0400 Subject: [PATCH 5/9] :bug: Ensure module path handling is not removed --- PSKoans/Private/Measure-Koan.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/PSKoans/Private/Measure-Koan.ps1 b/PSKoans/Private/Measure-Koan.ps1 index cf4dadf41..d0a79ec92 100644 --- a/PSKoans/Private/Measure-Koan.ps1 +++ b/PSKoans/Private/Measure-Koan.ps1 @@ -31,6 +31,12 @@ ) begin { $KoanCount = 0 + $oldModulePath = $env:PSModulePath + + $env:PSModulePath = @( + $MyInvocation.MyCommand.Module.ModuleBase + $env:PSModulePath -split [System.IO.Path]::PathSeparator + ) -join [System.IO.Path]::PathSeparator $configuration = New-PesterConfiguration $configuration.Output.Verbosity = 'None' @@ -55,6 +61,7 @@ $KoanCount += $Result.TotalCount } end { + $env:PSModulePath = $oldModulePath Write-Verbose "Total Koans: $KoanCount" $KoanCount } From 2e7b6e3c331b31b4c70e4130a92201a10179834c Mon Sep 17 00:00:00 2001 From: "Joel Sallow (/u/ta11ow)" <32407840+vexx32@users.noreply.github.com> Date: Sat, 15 May 2021 08:29:57 -0400 Subject: [PATCH 6/9] :rocket: Update CI tests to use explicit config --- Build/Invoke-ModuleTests.ps1 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index 59924d910..d273cc329 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -11,8 +11,15 @@ Write-Host "TEST: Pester Version: $PesterVersion" Write-Host $Lines try { - # Try/Finally required since -CI will exit with exit code on failure. - Invoke-Pester -Path "$env:PROJECTROOT" -CI -Output Normal + # Try/Finally required since this will exit with exit code on failure. + $configuration = New-PesterConfiguration + $configuration.CodeCoverage.Enabled = $true + $configuration.TestResult.Enabled = $true + $configuration.Run.Exit = $true + $configuration.Run.Path = $env:PROJECTROOT + $configuration.Output.Verbosity = 'Normal' + + Invoke-Pester -Configuration $Configuration } finally { $Timestamp = Get-Date -Format "yyyyMMdd-hhmmss" From a68aba0061881ebf41b750aed347cbd90c0dc097 Mon Sep 17 00:00:00 2001 From: "Joel Sallow (/u/ta11ow)" <32407840+vexx32@users.noreply.github.com> Date: Sat, 15 May 2021 08:31:40 -0400 Subject: [PATCH 7/9] :arrow_up_small: Bump Pester to 5.2.1 --- PSKoans/PSKoans.psd1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PSKoans/PSKoans.psd1 b/PSKoans/PSKoans.psd1 index 620719885..8083317cc 100644 --- a/PSKoans/PSKoans.psd1 +++ b/PSKoans/PSKoans.psd1 @@ -1,4 +1,4 @@ -# +# # Module manifest for module 'PSKoans' # # Generated by: Joel Sallow @@ -54,7 +54,7 @@ RequiredModules = @( @{ ModuleName = 'Pester' - ModuleVersion = '5.2.0' + ModuleVersion = '5.2.1' } ) From 70485e811cc7f5e404a4527e3f5ffa06c330ff4a Mon Sep 17 00:00:00 2001 From: "Joel Sallow (/u/ta11ow)" <32407840+vexx32@users.noreply.github.com> Date: Sat, 15 May 2021 08:33:30 -0400 Subject: [PATCH 8/9] :fire: Remove workaround This issue was fixed in 5.2.1 of Pester --- PSKoans/Private/Measure-Koan.ps1 | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/PSKoans/Private/Measure-Koan.ps1 b/PSKoans/Private/Measure-Koan.ps1 index d0a79ec92..e9b891008 100644 --- a/PSKoans/Private/Measure-Koan.ps1 +++ b/PSKoans/Private/Measure-Koan.ps1 @@ -49,13 +49,7 @@ Write-Verbose "Discovering koans in $koanTopics" $configuration.Run.Path = $KoanInfo.Path - <# - Null-redirecting stream 6 is necessary because the message about skipping the test run still displays - even if the output verbosity is set to 'None' in Pester 5.2.0. - - Github issue: https://github.com/pester/Pester/issues/1933 - #> - $Result = Invoke-Pester -Configuration $configuration 6> $null + $Result = Invoke-Pester -Configuration $configuration Write-Debug "Found $($Result.TotalCount) koans in $koanTopics" $KoanCount += $Result.TotalCount From 5af665824e52b8b947b6a9c1422654fff4714b03 Mon Sep 17 00:00:00 2001 From: "Joel Sallow (/u/ta11ow)" <32407840+vexx32@users.noreply.github.com> Date: Sat, 15 May 2021 09:08:24 -0400 Subject: [PATCH 9/9] :rocket: Remove exit from pester configuration --- Build/Invoke-ModuleTests.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index d273cc329..e5064c03a 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -15,7 +15,6 @@ try { $configuration = New-PesterConfiguration $configuration.CodeCoverage.Enabled = $true $configuration.TestResult.Enabled = $true - $configuration.Run.Exit = $true $configuration.Run.Path = $env:PROJECTROOT $configuration.Output.Verbosity = 'Normal'