Skip to content

Commit

Permalink
update test expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Oct 21, 2024
1 parent 6a2fb35 commit b74ef0c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 26 deletions.
6 changes: 4 additions & 2 deletions dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class SentryClient {

hint ??= Hint();

SentryEvent? preparedEvent = _prepareEvent(event, hint, stackTrace: stackTrace);
SentryEvent? preparedEvent =
_prepareEvent(event, hint, stackTrace: stackTrace);

if (scope != null) {
preparedEvent = await scope.applyToEvent(preparedEvent, hint);
Expand Down Expand Up @@ -209,7 +210,8 @@ class SentryClient {
return isMatchingRegexPattern(message, _options.ignoreErrors);
}

SentryEvent _prepareEvent(SentryEvent event, Hint hint, {dynamic stackTrace}) {
SentryEvent _prepareEvent(SentryEvent event, Hint hint,
{dynamic stackTrace}) {
event = event.copyWith(
serverName: event.serverName ?? _options.serverName,
dist: event.dist ?? _options.dist,
Expand Down
7 changes: 3 additions & 4 deletions dart/lib/src/sentry_exception_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ class SentryExceptionFactory {

SentryStackTrace? sentryStackTrace;
if (stackTrace != null) {
sentryStackTrace =
_stacktraceFactory
.parse(stackTrace, removeSentryFrames: removeSentryFrames)
.copyWith(snapshot: snapshot);
sentryStackTrace = _stacktraceFactory
.parse(stackTrace, removeSentryFrames: removeSentryFrames)
.copyWith(snapshot: snapshot);
if (sentryStackTrace.frames.isEmpty) {
sentryStackTrace = null;
}
Expand Down
4 changes: 3 additions & 1 deletion dart/lib/src/sentry_stack_trace_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class SentryStackTraceFactory {
var stackTraceFrame = encodeStackTraceFrame(frame);

if (stackTraceFrame != null) {
if (removeSentryFrames == true && (stackTraceFrame.package == 'sentry' || stackTraceFrame.package == 'sentry_flutter')) {
if (removeSentryFrames == true &&
(stackTraceFrame.package == 'sentry' ||
stackTraceFrame.package == 'sentry_flutter')) {
continue;
}
frames.add(stackTraceFrame);
Expand Down
19 changes: 13 additions & 6 deletions dart/test/sentry_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2201,17 +2201,20 @@ void main() {

final capturedEnvelope = (fixture.transport).envelopes.first;
final attachmentItem = capturedEnvelope.items.firstWhereOrNull(
(element) => element.header.type == SentryItemType.attachment,
(element) => element.header.type == SentryItemType.attachment,
);
expect(attachmentItem, isNull);
});

test('null stack trace marked in hint & sentry frames removed from thread stackTrace', () async {
test(
'null stack trace marked in hint & sentry frames removed from thread stackTrace',
() async {
final beforeSendCallback = (SentryEvent event, Hint hint) {
expect(hint.get(TypeCheckHint.currentStackTrace), isTrue);
return event;
};
final client = fixture.getSut(beforeSend: beforeSendCallback, attachStacktrace: true);
final client = fixture.getSut(
beforeSend: beforeSendCallback, attachStacktrace: true);
await client.captureEvent(fakeEvent);

final capturedEnvelope = (fixture.transport).envelopes.first;
Expand All @@ -2224,12 +2227,15 @@ void main() {
expect(sentryFramesCount, 0);
});

test('empty stack trace marked in hint & sentry frames removed from thread stackTrace', () async {
test(
'empty stack trace marked in hint & sentry frames removed from thread stackTrace',
() async {
final beforeSendCallback = (SentryEvent event, Hint hint) {
expect(hint.get(TypeCheckHint.currentStackTrace), isTrue);
return event;
};
final client = fixture.getSut(beforeSend: beforeSendCallback, attachStacktrace: true);
final client = fixture.getSut(
beforeSend: beforeSendCallback, attachStacktrace: true);
await client.captureEvent(fakeEvent, stackTrace: StackTrace.empty);

final capturedEnvelope = (fixture.transport).envelopes.first;
Expand All @@ -2247,7 +2253,8 @@ void main() {
expect(hint.get(TypeCheckHint.currentStackTrace), isNull);
return event;
};
final client = fixture.getSut(beforeSend: beforeSendCallback, attachStacktrace: true);
final client = fixture.getSut(
beforeSend: beforeSendCallback, attachStacktrace: true);
await client.captureEvent(fakeEvent, stackTrace: StackTrace.current);
});
});
Expand Down
26 changes: 13 additions & 13 deletions dart/test/sentry_exception_factory_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ void main() {
final sentryException =
fixture.getSut(attachStacktrace: false).getSentryException(Object());

expect(sentryException.stackTrace!.snapshot, true);
// stackTrace is null anyway when not present and attachStacktrace false
expect(sentryException.stackTrace?.snapshot, isNull);
});

test('sets stacktrace build id and image address', () {
Expand All @@ -226,19 +227,19 @@ void main() {
.getSut(attachStacktrace: false)
.getSentryException(Object(), stackTrace: null);

final sentryStackTrace = sentryException.stackTrace!;
expect(sentryStackTrace.baseAddr, isNull);
expect(sentryStackTrace.buildId, isNull);
// stackTrace is null anyway with null stack trace and attachStacktrace false
final sentryStackTrace = sentryException.stackTrace;
expect(sentryStackTrace?.baseAddr, isNull);
expect(sentryStackTrace?.buildId, isNull);
});

test('remove sentry frames', () {
final sentryException = fixture
.getSut(attachStacktrace: false)
.getSentryException(
SentryStackTraceError(),
stackTrace: SentryStackTrace(),
removeSentryFrames: true,
);
final sentryException =
fixture.getSut(attachStacktrace: false).getSentryException(
SentryStackTraceError(),
stackTrace: SentryStackTrace(),
removeSentryFrames: true,
);

final sentryStackTrace = sentryException.stackTrace!;
expect(sentryStackTrace.baseAddr, isNull);
Expand Down Expand Up @@ -306,8 +307,7 @@ isolate_instructions: 7526344980, vm_instructions: 752633f000
}

class SentryStackTraceError extends Error {
var prefix =
"Unknown error without own stacktrace";
var prefix = "Unknown error without own stacktrace";

@override
String toString() {
Expand Down

0 comments on commit b74ef0c

Please sign in to comment.