Skip to content

Commit

Permalink
#351: Stops the done message appears when server errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Badgerati committed Aug 26, 2019
1 parent 50f2d93 commit 2f45fa8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Private/Helpers.ps1
Expand Up @@ -781,7 +781,7 @@ function Close-PodeServer
{
param (
[switch]
$Exit
$ShowDoneMessage
)

# stpo all current runspaces
Expand All @@ -802,7 +802,7 @@ function Close-PodeServer
# remove all of the pode temp drives
Remove-PodePSDrives

if ($Exit -and ![string]::IsNullOrWhiteSpace($PodeContext.Server.Type) -and !$PodeContext.Server.IsServerless) {
if ($ShowDoneMessage -and ![string]::IsNullOrWhiteSpace($PodeContext.Server.Type) -and !$PodeContext.Server.IsServerless) {
Write-Host " Done" -ForegroundColor Green
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/Public/Core.ps1
Expand Up @@ -82,6 +82,7 @@ function Start-PodeServer

# ensure the session is clean
$PodeContext = $null
$ShowDoneMessage = $true

try {
# configure the server's root path
Expand Down Expand Up @@ -128,9 +129,13 @@ function Start-PodeServer
Write-Host 'Terminating...' -NoNewline -ForegroundColor Yellow
$PodeContext.Tokens.Cancellation.Cancel()
}
catch {
$ShowDoneMessage = $false
throw
}
finally {
# clean the runspaces and tokens
Close-PodeServer -Exit
Close-PodeServer -ShowDoneMessage:$ShowDoneMessage

# clean the session
$PodeContext = $null
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Helpers.Tests.ps1
Expand Up @@ -1208,13 +1208,13 @@ Describe 'Close-PodeServer' {

It 'Closes out pode, but with the done flag' {
$PodeContext = @{ 'Server' = @{ 'Type' = 'Server' } }
Close-PodeServer -Exit
Close-PodeServer -ShowDoneMessage
Assert-MockCalled Write-Host -Times 1 -Scope It
}

It 'Closes out pode, but with no done flag if serverless' {
$PodeContext = @{ 'Server' = @{ 'Type' = 'Server'; 'IsServerless' = $true } }
Close-PodeServer -Exit
Close-PodeServer -ShowDoneMessage
Assert-MockCalled Write-Host -Times 0 -Scope It
}
}
Expand Down

0 comments on commit 2f45fa8

Please sign in to comment.