Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Nov 5, 2023
1 parent 595780e commit d08cedb
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 86 deletions.
92 changes: 46 additions & 46 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ jobs:
name: Modules
path: ${{github.workspace}}/output

# - name: Upload Tests
# uses: actions/upload-artifact@v3
# with:
# name: PesterTests
# path: ${{github.workspace}}/Tests
- name: Upload Tests
uses: actions/upload-artifact@v3
with:
name: PesterTests
path: ${{github.workspace}}/Tests

- name: Upload RequiredModules.psd1
uses: actions/upload-artifact@v3
Expand All @@ -69,48 +69,48 @@ jobs:
rootPath: Modules/F7History
repoToken: ${{ secrets.GITHUB_TOKEN }}

# test:
# needs: build
# runs-on: ${{ matrix.os }}
# strategy:
# fail-fast: false
# matrix:
# os: [windows-latest, ubuntu-latest, macos-latest]
# steps:
# - name: Download Build Output
# uses: actions/download-artifact@v3

# - name: Install Required Modules
# uses: PoshCode/Actions/install-requiredmodules@v1
# with:
# requiredModules-path: ${{github.workspace}}/RequiredModules/RequiredModules.psd1

# # see https://github.com/Jaykul/RequiredModules/issues/6
# - name: Manually Install Modules F7History is dependent on
# shell: pwsh
# run: |
# Install-Module -Name Microsoft.PowerShell.ConsoleGuiTools -Force -SkipPublisherCheck -Scope CurrentUser
# Install-Module -Name PSReadLine -Force -SkipPublisherCheck -Scope CurrentUser
# Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser

# - name: Run Pester Tests
# uses: PoshCode/Actions/pester@v2
# with:
# pesterVersion: "5.5.0"
# codeCoveragePath: Modules/F7History
# moduleUnderTest: F7History
# additionalModulePaths: ${{github.workspace}}/Modules
test:
needs: build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
steps:
- name: Download Build Output
uses: actions/download-artifact@v3

- name: Install Required Modules
uses: PoshCode/Actions/install-requiredmodules@v1
with:
requiredModules-path: ${{github.workspace}}/RequiredModules/RequiredModules.psd1

# see https://github.com/Jaykul/RequiredModules/issues/6
- name: Manually Install Modules F7History is dependent on
shell: pwsh
run: |
Install-Module -Name Microsoft.PowerShell.ConsoleGuiTools -Force -SkipPublisherCheck -Scope CurrentUser
Install-Module -Name PSReadLine -Force -SkipPublisherCheck -Scope CurrentUser
Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser
- name: Run Pester Tests
uses: PoshCode/Actions/pester@v2
with:
pesterVersion: "5.5.0"
codeCoveragePath: Modules/F7History
moduleUnderTest: F7History
additionalModulePaths: ${{github.workspace}}/Modules

# - name: Publish Test Results
# uses: zyborg/dotnet-tests-report@v1
# with:
# test_results_path: results.xml

# - name: Upload Results
# uses: actions/upload-artifact@v3
# with:
# name: Pester Results
# path: ${{github.workspace}}/*.xml
- name: Publish Test Results
uses: zyborg/dotnet-tests-report@v1
with:
test_results_path: results.xml

- name: Upload Results
uses: actions/upload-artifact@v3
with:
name: Pester Results
path: ${{github.workspace}}/*.xml

publish:
needs:
Expand Down
7 changes: 5 additions & 2 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ $ocgvModule = "Microsoft.PowerShell.ConsoleGuiTools"
$localRepositoryPath = $localRepository | Select-Object -ExpandProperty SourceLocation
$v = Get-ChildItem "${localRepositoryPath}/${ocgvModule}*.nupkg" | Select-Object -ExpandProperty Name | Sort-Object -Descending | Select-Object -First 1
if ($v -match "$ocgvModule.(.*?).nupkg") {
$ocgvVersion = $Matches[1]
$v = [Version]::new($Matches[1])
$ocgvVersion = "$($v.Major).$($v.Minor).$($v.Build)"
"$ocgvModule v $ocgvVersion found in local repository; setting RequiredVersion in $PsdPath"
Update-ModuleManifest -Path $PsdPath -RequiredModules @(
@{
Expand All @@ -52,7 +53,9 @@ $ocgvModule = "Microsoft.PowerShell.ConsoleGuiTools"
}

if ($null -eq $ocgvVersion) {
$ocgvVersion = (Find-Module $ocgvModule).Version
$module = (Find-Module $ocgvModule) | Select-Object -ExpandProperty Version | Sort-Object -Descending | Select-Object -First 1
$v = [Version]::new($module)
$ocgvVersion = "$($v.Major).$($v.Minor).$($v.Build)"
"$ocgvModule v $ocgvVersion` found in PSGallery; setting ModuleVersion in $PsdPath"
Update-ModuleManifest -Path $PsdPath -RequiredModules @(
@{
Expand Down
4 changes: 2 additions & 2 deletions Source/F7History.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Tig Kindel
#
# Generated on: 11/4/2023
# Generated on: 11/5/2023
#

@{
Expand Down Expand Up @@ -52,7 +52,7 @@ Description = 'Press F7 to get a graphical Command History in Powershell.'

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(@{ModuleName = 'PSReadline'; ModuleVersion = '2.1'; },
@{ModuleName = 'Microsoft.PowerShell.ConsoleGuiTools'; ModuleVersion = '0.7.6.0'; })
@{ModuleName = 'Microsoft.PowerShell.ConsoleGuiTools'; ModuleVersion = '0.7.6'; })

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()
Expand Down
75 changes: 43 additions & 32 deletions Tests/Public/f7_history.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
#requires -Module F7History

# Describe "f7_history" {
# Context "The f7_history function" {
# $cmd = $null
# try {
# $cmd = get-item -path Function:\f7_history
# } catch {
# $cmd = $null
# }

# It " is defined" {
# $cmd | Should -Be "f7_history"
# }
# }
Describe "f7_history" {
Context "The f7_history function" {
BeforeAll {
$cmd = $null
try {
$cmd = get-item -path Function:\f7_history
}
catch {
$cmd = $null
}
}
It " is defined" {
$cmd | Should -Be "f7_history"
}
}

# Context "The f7_history function" {
# $parameters = (Get-Command f7_history).Parameters
# It "has a required string parameter for the global flag" {
# $parameters.ContainsKey("global") | Should -Be $true
# $parameters["global"].ParameterType | Should -Be ([boolean])
# $parameters["global"].Attributes.Where{$_ -is [Parameter]}.Mandatory | Should -Be $true
# }
# }
Context "The f7_history function" {
BeforeAll {
$parameters = (Get-Command f7_history).Parameters
}
It "has a required string parameter for the global flag" {
$parameters.ContainsKey("global") | Should -Be $true
$parameters["global"].ParameterType | Should -Be ([boolean])
$parameters["global"].Attributes.Where{ $_ -is [Parameter] }.Mandatory | Should -Be $true
}
}

# Context "Default key bindings" {
# $Result = (Get-PSReadLineKeyHandler -Chord F7).Function
# It "defines F7 as the default key binding" {
# $Result | Should -Be "Show Matching Command History"
# }
Context "Default F7 keybinding " {
BeforeAll {
$Result = (Get-PSReadLineKeyHandler -Chord F7).Function
}
It "defines F7 as the default key binding" {
$Result | Should -Be "Show Matching Command History"
}

# $Result = (Get-PSReadLineKeyHandler -Chord Shift-F7).Function
# It "defines Shift-F7 as the default key binding" {
# $Result | Should -Be "Show Matching Command History for All"
# }
# }
# }
}

Context "Default Shift-F7 keybinding " {
BeforeAll {
$Result = (Get-PSReadLineKeyHandler -Chord Shift-F7).Function
}
It "defines Shift-F7 as the default key binding" {
$Result | Should -Be "Show Matching Command History for All"
}
}
}
18 changes: 14 additions & 4 deletions test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,24 @@ Remove-Module $ModuleName -ErrorAction Ignore -Force
$ModuleUnderTest = Import-Module $FoundModule.FullName -PassThru -Force -DisableNameChecking -Verbose:$false
Write-Host "Invoke-Pester for Module $($ModuleUnderTest) version $($ModuleUnderTest.Version)"

$MyOptions = @{
Run = @{ # Run configuration.
PassThru = $true # Return result object after finishing the test run.
}
}

$config = New-PesterConfiguration -Hashtable $MyOptions
$config.Output.Verbosity = "Detailed"

if ($CodeCoverage) {
$config.CodeCoverage.Enabled = $true
$config.CodeCoverage.OutputPath = "./coverage.xml"
# Get code coverage for the psm1 file to a coverage.xml that we can mess with later
# Invoke-Pester ./Tests -Show $Show -PesterOption @{
#Invoke-Pester -Confi
# IncludeVSCodeMarker = $IncludeVSCodeMarker
# } -CodeCoverage $ModuleUnderTest.Path -CodeCoverageOutputFile ./coverage.xml -PassThru | Convert-CodeCoverage -SourceRoot ./Source
} else {
Invoke-Pester -Path ./Tests
}
}
Invoke-Pester -Configuration $config

Write-Host
if (-not $SkipScriptAnalyzer) {
Expand Down

0 comments on commit d08cedb

Please sign in to comment.