diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index 59924d910..e5064c03a 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -11,8 +11,14 @@ 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.Path = $env:PROJECTROOT + $configuration.Output.Verbosity = 'Normal' + + Invoke-Pester -Configuration $Configuration } finally { $Timestamp = Get-Date -Format "yyyyMMdd-hhmmss" 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/PSKoans/PSKoans.psd1 b/PSKoans/PSKoans.psd1 index df3e9e77a..8083317cc 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.68.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.1' + } + ) + + # 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 = '' +} diff --git a/PSKoans/Private/Measure-Koan.ps1 b/PSKoans/Private/Measure-Koan.ps1 index 3fbc7169b..e9b891008 100644 --- a/PSKoans/Private/Measure-Koan.ps1 +++ b/PSKoans/Private/Measure-Koan.ps1 @@ -37,45 +37,26 @@ $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 '], [')]" - - $Result = & (Get-Module Pester) { - [CmdletBinding()] - param( - $Path, - $ExcludePath, - $SessionState - ) - - $_Pester_State_Backup = $state.PSObject.Copy() - $state.Stack = [System.Collections.Stack]@() - try { - Reset-TestSuiteState - - # to avoid Describe thinking that we run in interactive mode - $invokedViaInvokePester = $true + $koanTopics = "[$($KoanInfo.Name -join '], [')]" + Write-Verbose "Discovering koans in $koanTopics" + $configuration.Run.Path = $KoanInfo.Path - $fileList = Find-File -Path $Path -ExcludePath $ExcludePath -Extension '.Koans.ps1' - $containers = foreach ($file in $fileList) { - New-BlockContainerObject -File (Get-Item $file) - } + $Result = Invoke-Pester -Configuration $configuration - 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 { + $env:PSModulePath = $oldModulePath 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" -} 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')