-
-
Notifications
You must be signed in to change notification settings - Fork 366
feat(replay): Add Session Replay runtime controls #6703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d901746
feat(replay): Add Session Replay runtime controls
antonis 67a77e4
docs(changelog): Link Session Replay runtime controls to #6703
antonis 9e7730d
fix(replay): Invalidate cached replay id and guard native controls
antonis 04900f6
feat(replay): Honor flush continueRecording option on mobile
antonis 08fd397
fix(replay): Prefer browser replay over mobile no-op on Web in getReplay
antonis 73a4bd4
style(replay): Fix import ordering in getReplay test
antonis bacbf10
fix(replay): Invalidate cached replay id even when stop/flush native โฆ
antonis 50e36d9
Merge remote-tracking branch 'origin/main' into feat/replay-runtime-cโฆ
antonis 24a18f8
fix(replay): Guard iOS replay control bridge methods with @try/@catch
antonis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryReplayControlTests.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #import <XCTest/XCTest.h> | ||
| @import RNSentry.Swift; | ||
|
|
||
| /** | ||
| * Coverage for the Session Replay runtime controls bridged through | ||
| * `RNSentryInternal` (`startReplay`, `startReplayBuffering`, `stopReplay`, | ||
| * `pauseReplay`, `resumeReplay`, `flushReplay`). | ||
| * | ||
| * These forward to `SentrySDK.internal.replay.*`. Without a started SDK there is | ||
| * no active replay, so every control must be a safe no-op that does not crash, | ||
| * and `replayId` must stay nil. That mirrors the "call uninitialized, assert a | ||
| * safe default" convention used by the other `RNSentryInternal` tests. | ||
| */ | ||
| @interface RNSentryReplayControlTests : XCTestCase | ||
|
|
||
| @end | ||
|
|
||
| @implementation RNSentryReplayControlTests | ||
|
|
||
| - (void)testStartReplayDoesNotCrashWhenNotRunning | ||
| { | ||
| [RNSentryInternal startReplay]; | ||
| XCTAssertNil(RNSentryInternal.replayId); | ||
| } | ||
|
|
||
| - (void)testStartReplayBufferingDoesNotCrashWhenNotRunning | ||
| { | ||
| [RNSentryInternal startReplayBuffering]; | ||
| XCTAssertNil(RNSentryInternal.replayId); | ||
| } | ||
|
|
||
| - (void)testStopReplayDoesNotCrashWhenNotRunning | ||
| { | ||
| [RNSentryInternal stopReplay]; | ||
| XCTAssertNil(RNSentryInternal.replayId); | ||
| } | ||
|
|
||
| - (void)testPauseReplayDoesNotCrashWhenNotRunning | ||
| { | ||
| [RNSentryInternal pauseReplay]; | ||
| XCTAssertNil(RNSentryInternal.replayId); | ||
| } | ||
|
|
||
| - (void)testResumeReplayDoesNotCrashWhenNotRunning | ||
| { | ||
| [RNSentryInternal resumeReplay]; | ||
| XCTAssertNil(RNSentryInternal.replayId); | ||
| } | ||
|
|
||
| - (void)testFlushReplayDoesNotCrashWhenNotRunning | ||
| { | ||
| [RNSentryInternal flushReplay]; | ||
| XCTAssertNil(RNSentryInternal.replayId); | ||
| } | ||
|
|
||
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
packages/core/android/src/test/java/io/sentry/react/RNSentryReplayControlTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| package io.sentry.react; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.anyInt; | ||
| import static org.mockito.ArgumentMatchers.anyString; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.mockStatic; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import android.content.pm.PackageInfo; | ||
| import android.content.pm.PackageManager; | ||
| import com.facebook.react.bridge.Promise; | ||
| import com.facebook.react.bridge.ReactApplicationContext; | ||
| import io.sentry.IReplayApi; | ||
| import io.sentry.Sentry; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.mockito.MockedStatic; | ||
|
|
||
| /** | ||
| * Coverage for the Session Replay runtime controls exposed on {@link RNSentryModuleImpl} ({@code | ||
| * startReplay}, {@code startReplayBuffering}, {@code stopReplay}, {@code pauseReplay}, {@code | ||
| * resumeReplay}, {@code flushReplay}). | ||
| * | ||
| * <p>Each control forwards to the corresponding {@link IReplayApi} method returned by {@code | ||
| * Sentry.replay()} and then resolves the promise with {@code null}. | ||
| */ | ||
| public class RNSentryReplayControlTest { | ||
|
|
||
| private RNSentryModuleImpl module; | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| ReactApplicationContext reactContext = mock(ReactApplicationContext.class); | ||
| PackageManager packageManager = mock(PackageManager.class); | ||
| when(packageManager.getPackageInfo(anyString(), anyInt())).thenReturn(new PackageInfo()); | ||
| when(reactContext.getPackageManager()).thenReturn(packageManager); | ||
| when(reactContext.getPackageName()).thenReturn("com.test.app"); | ||
| module = new RNSentryModuleImpl(reactContext); | ||
| } | ||
|
|
||
| @Test | ||
| public void startReplayCallsSdkAndResolvesNull() { | ||
| try (MockedStatic<Sentry> sentry = mockStatic(Sentry.class)) { | ||
| final IReplayApi replay = mock(IReplayApi.class); | ||
| sentry.when(Sentry::replay).thenReturn(replay); | ||
|
|
||
| final Promise promise = mock(Promise.class); | ||
| module.startReplay(promise); | ||
|
|
||
| verify(replay).start(); | ||
| verify(promise).resolve(null); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void startReplayBufferingCallsSdkAndResolvesNull() { | ||
| try (MockedStatic<Sentry> sentry = mockStatic(Sentry.class)) { | ||
| final IReplayApi replay = mock(IReplayApi.class); | ||
| sentry.when(Sentry::replay).thenReturn(replay); | ||
|
|
||
| final Promise promise = mock(Promise.class); | ||
| module.startReplayBuffering(promise); | ||
|
|
||
| verify(replay).startBuffering(); | ||
| verify(promise).resolve(null); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void stopReplayCallsSdkAndResolvesNull() { | ||
| try (MockedStatic<Sentry> sentry = mockStatic(Sentry.class)) { | ||
| final IReplayApi replay = mock(IReplayApi.class); | ||
| sentry.when(Sentry::replay).thenReturn(replay); | ||
|
|
||
| final Promise promise = mock(Promise.class); | ||
| module.stopReplay(promise); | ||
|
|
||
| verify(replay).stop(); | ||
| verify(promise).resolve(null); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void pauseReplayCallsSdkAndResolvesNull() { | ||
| try (MockedStatic<Sentry> sentry = mockStatic(Sentry.class)) { | ||
| final IReplayApi replay = mock(IReplayApi.class); | ||
| sentry.when(Sentry::replay).thenReturn(replay); | ||
|
|
||
| final Promise promise = mock(Promise.class); | ||
| module.pauseReplay(promise); | ||
|
|
||
| verify(replay).pause(); | ||
| verify(promise).resolve(null); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void resumeReplayCallsSdkAndResolvesNull() { | ||
| try (MockedStatic<Sentry> sentry = mockStatic(Sentry.class)) { | ||
| final IReplayApi replay = mock(IReplayApi.class); | ||
| sentry.when(Sentry::replay).thenReturn(replay); | ||
|
|
||
| final Promise promise = mock(Promise.class); | ||
| module.resumeReplay(promise); | ||
|
|
||
| verify(replay).resume(); | ||
| verify(promise).resolve(null); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void flushReplayCallsSdkAndResolvesNull() { | ||
| try (MockedStatic<Sentry> sentry = mockStatic(Sentry.class)) { | ||
| final IReplayApi replay = mock(IReplayApi.class); | ||
| sentry.when(Sentry::replay).thenReturn(replay); | ||
|
|
||
| final Promise promise = mock(Promise.class); | ||
| module.flushReplay(promise); | ||
|
|
||
| verify(replay).flush(); | ||
| verify(promise).resolve(null); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.