Skip to content

Commit

Permalink
Merge 0c277d1 into 28633a7
Browse files Browse the repository at this point in the history
  • Loading branch information
Badgerati authored Nov 7, 2019
2 parents 28633a7 + 0c277d1 commit f7d8118
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
'Test-IsWindows',
'Test-IsPSCore',
'Test-IsEmpty',
'Write-PodeHost',

# routes
'Add-PodeRoute',
Expand Down
25 changes: 25 additions & 0 deletions src/Public/Utilities.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -760,4 +760,29 @@ function Test-IsWindows

$v = Get-PodePSVersionTable
return ($v.Platform -ilike '*win*' -or ($null -eq $v.Platform -and $v.PSEdition -ieq 'desktop'))
}

<#
.SYNOPSIS
Writes a message to the main Host.
.DESCRIPTION
Due to Pode's use of runspaces, this will write a given message back to the main Host.
.PARAMETER Message
The Message to write.
.EXAMPLE
'Hello, world!' | Write-PodeHost
#>
function Write-PodeHost
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[string]
$Message
)

$Message | Out-Default
}
14 changes: 14 additions & 0 deletions tests/unit/Helpers.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1379,4 +1379,18 @@ Describe 'Convert-PodePathSeparators' {
Convert-PodePathSeparators -Path @(' ', '') | Should Be $null
}
}
}

Describe 'Write-PodeHost' {
Mock Out-Default {}

It 'Writes a message to the Host by parameters' {
Write-PodeHost -Message 'Hello'
Assert-MockCalled Out-Default -Scope It -Times 1
}

It 'Writes a message to the Host by pipeline' {
'Hello' | Write-PodeHost
Assert-MockCalled Out-Default -Scope It -Times 1
}
}

0 comments on commit f7d8118

Please sign in to comment.