Skip to content

Commit

Permalink
Fixed bug with delay in message on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
merill committed Apr 2, 2024
1 parent 116a8db commit 5860ae5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
27 changes: 23 additions & 4 deletions powershell/internal/Write-MtProgress.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ Function Write-MtProgress {
[string]$Activity,

[Parameter(Mandatory = $false)]
[object]$Status
[object]$Status,

# Forces this message to be displayed by adding a 200ms sleep for the update to be displayed
# Use sparingly as it can slow down the script
# This is a workaround for bug on macOS where first call does not show the progress bar. See https://github.com/PowerShell/PowerShell/issues/5741
[Parameter(Mandatory = $false)]
[switch]$Force,

# Specifies that progress is completed.
[Parameter(Mandatory = $false)]
[switch]$Completed
)

try {
Expand All @@ -28,14 +38,23 @@ Function Write-MtProgress {
$totalWidth = $Activity.Length + $statusString.Length + $buffer # 10 for buffer
if ($totalWidth -gt $hostWidth) {
$length = $hostWidth - $Activity.Length - $buffer
if($length -lt $statusString.Length -and $length -gt 0) {
if ($length -lt $statusString.Length -and $length -gt 0) {
$statusString = $statusString.Substring(0, $length) + "..."
}
}

Write-Progress -Activity $Activity -Status $statusString
Write-Progress -Activity $Activity -Status $statusString -Completed:$Completed
if ($Force -and !$IsWindows) {
Start-Sleep -Milliseconds 200
Write-Progress -Activity $Activity -Status $statusString -Completed:$Completed
}

} else {
Write-Progress -Activity $Activity
Write-Progress -Activity $Activity -Completed:$Completed
if ($Force -and !$IsWindows) {
Start-Sleep -Milliseconds 200
Write-Progress -Activity $Activity -Completed:$Completed
}
}
} catch {
Write-Verbose $_
Expand Down
7 changes: 4 additions & 3 deletions powershell/public/Invoke-Maester.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,13 @@ Function Invoke-Maester {
$maesterResults = $null

Set-MtProgressView
Write-MtProgress "Starting tests"
Write-MtProgress -Activity "Starting Maester" -Status "Discovering tests to run..." -Force

$pesterResults = Invoke-Pester -Configuration $pesterConfig

if ($pesterResults) {

Write-MtProgress -Activity "Processing test results" -Status "$($pesterResults.TotalCount) tests"
Write-MtProgress -Activity "Processing test results" -Status "$($pesterResults.TotalCount) tests" -Force
$maesterResults = ConvertTo-MtMaesterResult $PesterResults

if (![string]::IsNullOrEmpty($out.OutputJsonFile)) {
Expand Down Expand Up @@ -279,7 +280,7 @@ Function Invoke-Maester {

Get-IsNewMaesterVersionAvailable | Out-Null

Write-Progress -Activity "🔥 Completed tests" -Completed # Clear progress bar
Write-MtProgress -Activity "🔥 Completed tests" -Status "Total $($pesterResults.TotalCount) " -Completed -Force # Clear progress bar
}
Reset-MtProgressView
if ($PassThru) {
Expand Down

0 comments on commit 5860ae5

Please sign in to comment.