Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/Sentry/public/Out-Sentry.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

function Out-Sentry
{
[OutputType([Sentry.SentryId])]
[CmdletBinding(DefaultParameterSetName = 'ErrorRecord')]
param(
[Parameter(ValueFromPipeline = $true, ParameterSetName = 'ErrorRecord')]
Expand Down Expand Up @@ -32,7 +33,7 @@ function Out-Sentry
}

$options = Get-CurrentOptions
[Sentry.SentryEvent]$event_
[Sentry.SentryEvent]$event_ = $null
$processor = [StackTraceProcessor]::new()

if ($ErrorRecord -ne $null)
Expand Down Expand Up @@ -106,5 +107,4 @@ function Out-Sentry
$scope | ForEach-Object $EditScope
})
}
end {}
}
6 changes: 4 additions & 2 deletions tests/init.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,17 @@ Describe 'SentrySdk' {
}

It 'Out-Sentry does not crash when Sentry is not enabled' {
'message' | Out-Sentry -Debug
$eventId = 'message' | Out-Sentry -Debug
$eventId | Should -Be $null
}

It 'Out-Sentry does not capture when Sentry is not enabled' {
$events = [System.Collections.Generic.List[Sentry.SentryEvent]]::new();
$transport = [RecordingTransport]::new()
StartSentryForEventTests ([ref] $events) ([ref] $transport)
Stop-Sentry
'message' | Out-Sentry -Debug
$eventId = 'message' | Out-Sentry -Debug
$eventId | Should -Be $null
$events.Count | Should -Be 0
}
}
55 changes: 55 additions & 0 deletions tests/userfeedback.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
BeforeAll {
. "$PSScriptRoot/utils.ps1"
}

Describe 'UserFeedback' {
BeforeEach {
$events = [System.Collections.Generic.List[Sentry.SentryEvent]]::new();
$transport = [RecordingTransport]::new()
StartSentryForEventTests ([ref] $events) ([ref] $transport)
}

AfterEach {
$events.Clear()
$transport.Clear()
Stop-Sentry
}

It 'Out-Sentry returns an event ID for messages' {
$eventId = 'msg' | Out-Sentry
$eventId | Should -BeOfType [Sentry.SentryId]
$eventId.ToString().Length | Should -Be 32
}

It 'Out-Sentry returns an event ID for an error record' {
try
{
throw 'error'
}
catch
{
$eventId = $_ | Out-Sentry
}
$eventId | Should -BeOfType [Sentry.SentryId]
$eventId.ToString().Length | Should -Be 32
}

It 'Feedback gets captured' {
$eventId = 'msg' | Out-Sentry

$eventId | Should -BeOfType [Sentry.SentryId]
[Sentry.SentrySdk]::Flush()
$transport.Envelopes.Count | Should -Be 1

[Sentry.SentrySdk]::CaptureUserFeedback($eventId, 'email@example.com', 'comments', 'name')
[Sentry.SentrySdk]::Flush()
$transport.Envelopes.Count | Should -Be 2
$envelopeItem = $transport.Envelopes.ToArray()[1].Items[0]
$envelopeItem.Header['type'] | Should -Be 'user_report'
$envelopeItem.Payload.Source.EventId | Should -Be $eventId
$envelopeItem.Payload.Source.Name | Should -Be 'name'
$envelopeItem.Payload.Source.Email | Should -Be 'email@example.com'
$envelopeItem.Payload.Source.Comments | Should -Be 'comments'
}

}
5 changes: 5 additions & 0 deletions tests/utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ class RecordingTransport:Sentry.Extensibility.ITransport
$this.envelopes.Enqueue($envelope);
return [System.Threading.Tasks.Task]::CompletedTask;
}

[void] Clear()
{
$this.envelopes = [System.Collections.Concurrent.ConcurrentQueue[Sentry.Protocol.Envelopes.Envelope]]::new()
}
}

class TestLogger:Sentry.Infrastructure.DiagnosticLogger
Expand Down