-
-
Notifications
You must be signed in to change notification settings - Fork 357
test(e2e): Add auto init from JS tests for Android #5583
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
antonis
merged 9 commits into
antonis/capture-app-start-errors-v8
from
antonis/test-capture-app-start-errors-android
Jan 29, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
40f0d2f
test(e2e): Add auto init from JS tests for Android
antonis 5bf59f4
fix(e2e): Add scrolling to find crash control buttons in Android test
antonis 9870761
fix(e2e): Make Android crash flag auto-expire after one crash
antonis 181c4ba
fix(e2e): Handle wrapped exceptions in Android crash test
antonis 8db2547
Merge branch 'antonis/capture-app-start-errors-v8' into antonis/test-…
antonis be3fb84
Merge branch 'antonis/capture-app-start-errors-v8' into antonis/test-…
antonis 25331c7
Clean up notes for now
antonis 28b4cb0
Merge branch 'antonis/capture-app-start-errors-v8' into antonis/test-…
antonis 112bfc6
Merge branch 'antonis/capture-app-start-errors-v8' into antonis/test-…
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
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,13 @@ | ||
| const path = require('path'); | ||
| const baseConfig = require('./jest.config.base'); | ||
|
|
||
| /** @type {import('@jest/types').Config.InitialOptions} */ | ||
| module.exports = { | ||
| ...baseConfig, | ||
| globalSetup: path.resolve(__dirname, 'setup.android.auto.ts'), | ||
| testMatch: [ | ||
| ...baseConfig.testMatch, | ||
| '<rootDir>/e2e/**/*.test.android.ts', | ||
| '<rootDir>/e2e/**/*.test.android.auto.ts', | ||
| ], | ||
| }; |
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,7 @@ | ||
| import { setAutoInitTest } from './utils/environment'; | ||
|
|
||
| function setupAuto() { | ||
| setAutoInitTest(); | ||
| } | ||
|
|
||
| export default setupAuto; |
118 changes: 118 additions & 0 deletions
118
...s/react-native/e2e/tests/captureAppStartCrash/captureAppStartCrash.test.android.manual.ts
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,118 @@ | ||
| import { describe, it, beforeAll, expect, afterAll } from '@jest/globals'; | ||
| import { Envelope, EventItem } from '@sentry/core'; | ||
|
|
||
| import { | ||
| createSentryServer, | ||
| containingEvent, | ||
| } from '../../utils/mockedSentryServer'; | ||
| import { getItemOfTypeFrom } from '../../utils/event'; | ||
| import { maestro } from '../../utils/maestro'; | ||
|
|
||
| describe('Capture app start crash (Android)', () => { | ||
| let sentryServer = createSentryServer(); | ||
|
|
||
| let envelope: Envelope; | ||
|
|
||
| beforeAll(async () => { | ||
| await sentryServer.start(); | ||
|
|
||
| const envelopePromise = sentryServer.waitForEnvelope(containingEvent); | ||
|
|
||
| await maestro('tests/captureAppStartCrash/captureAppStartCrash.test.android.manual.yml'); | ||
|
|
||
| envelope = await envelopePromise; | ||
| }, 300000); // 5 minutes timeout for crash handling | ||
|
|
||
| afterAll(async () => { | ||
| await sentryServer.close(); | ||
| }); | ||
|
|
||
| it('envelope contains sdk metadata', async () => { | ||
| const item = getItemOfTypeFrom<EventItem>(envelope, 'event'); | ||
|
|
||
| expect(item).toEqual([ | ||
| { | ||
| content_type: 'application/json', | ||
| length: expect.any(Number), | ||
| type: 'event', | ||
| }, | ||
| expect.objectContaining({ | ||
| platform: 'java', | ||
| sdk: expect.objectContaining({ | ||
| name: 'sentry.java.android.react-native', | ||
| packages: expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| name: 'maven:io.sentry:sentry-android-core', | ||
| }), | ||
| expect.objectContaining({ | ||
| name: 'npm:@sentry/react-native', | ||
| }), | ||
| ]), | ||
| }), | ||
| }), | ||
| ]); | ||
| }); | ||
|
|
||
| it('captures app start crash exception', async () => { | ||
| const item = getItemOfTypeFrom<EventItem>(envelope, 'event'); | ||
|
|
||
| // Android wraps onCreate exceptions, so check that at least one exception | ||
| // contains our intentional crash message | ||
| const exceptions = item?.[1]?.exception?.values; | ||
| expect(exceptions).toBeDefined(); | ||
|
|
||
| const hasIntentionalCrash = exceptions?.some( | ||
| (ex: any) => | ||
| ex.type === 'RuntimeException' && | ||
| ex.value?.includes('This was intentional test crash before JS started.') | ||
| ); | ||
|
|
||
| expect(hasIntentionalCrash).toBe(true); | ||
|
|
||
| // Verify at least one exception has UncaughtExceptionHandler mechanism | ||
| const hasUncaughtHandler = exceptions?.some( | ||
| (ex: any) => ex.mechanism?.type === 'UncaughtExceptionHandler' | ||
| ); | ||
|
|
||
| expect(hasUncaughtHandler).toBe(true); | ||
| }); | ||
|
|
||
| it('crash happened before JS was loaded', async () => { | ||
| const item = getItemOfTypeFrom<EventItem>(envelope, 'event'); | ||
|
|
||
| // Verify this is a native crash, not from JavaScript | ||
| expect(item?.[1]).toEqual( | ||
| expect.objectContaining({ | ||
| platform: 'java', | ||
| }), | ||
| ); | ||
|
|
||
| // Should not have JavaScript context since JS wasn't loaded yet | ||
| expect(item?.[1]?.contexts?.react_native_context).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('contains device and app context', async () => { | ||
| const item = getItemOfTypeFrom<EventItem>(envelope, 'event'); | ||
|
|
||
| expect(item?.[1]).toEqual( | ||
| expect.objectContaining({ | ||
| contexts: expect.objectContaining({ | ||
| device: expect.objectContaining({ | ||
| brand: expect.any(String), | ||
| manufacturer: expect.any(String), | ||
| model: expect.any(String), | ||
| }), | ||
| app: expect.objectContaining({ | ||
| app_identifier: 'io.sentry.reactnative.sample', | ||
| app_name: expect.any(String), | ||
| app_version: expect.any(String), | ||
| }), | ||
| os: expect.objectContaining({ | ||
| name: 'Android', | ||
| version: expect.any(String), | ||
| }), | ||
| }), | ||
| }), | ||
| ); | ||
| }); | ||
| }); |
30 changes: 30 additions & 0 deletions
30
.../react-native/e2e/tests/captureAppStartCrash/captureAppStartCrash.test.android.manual.yml
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,30 @@ | ||
| appId: io.sentry.reactnative.sample | ||
| --- | ||
| # First launch: Enable crash flag and exit gracefully | ||
| - launchApp: | ||
| clearState: true | ||
| stopApp: true | ||
|
|
||
| # App launches on ErrorsTab by default, wait for screen to load | ||
| - waitForAnimationToEnd: | ||
| timeout: 2000 | ||
|
|
||
| # Scroll down to find the "Enable Crash on Start" button (Android only) | ||
| - scrollUntilVisible: | ||
| element: "Enable Crash on Start" | ||
| timeout: 10000 | ||
| direction: DOWN | ||
|
|
||
| - tapOn: "Enable Crash on Start" | ||
| - stopApp | ||
|
|
||
| # Second launch: App crashes on start | ||
| # The crash flag auto-deletes when read, so app only crashes once | ||
| - launchApp: | ||
| clearState: false | ||
| stopApp: false | ||
|
|
||
| # Third launch: App starts normally and sends the crash event | ||
| - launchApp: | ||
| clearState: false | ||
| stopApp: false |
99 changes: 99 additions & 0 deletions
99
samples/react-native/e2e/tests/captureMessage/captureMessage.test.android.auto.ts
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,99 @@ | ||
| import { describe, it, beforeAll, expect, afterAll } from '@jest/globals'; | ||
| import { Envelope, EventItem } from '@sentry/core'; | ||
|
|
||
| import { | ||
| createSentryServer, | ||
| containingEventWithAndroidMessage, | ||
| } from '../../utils/mockedSentryServer'; | ||
| import { getItemOfTypeFrom } from '../../utils/event'; | ||
| import { maestro } from '../../utils/maestro'; | ||
|
|
||
| describe('Capture message (auto init from JS)', () => { | ||
| let sentryServer = createSentryServer(); | ||
|
|
||
| let envelope: Envelope; | ||
|
|
||
| beforeAll(async () => { | ||
| await sentryServer.start(); | ||
|
|
||
| const envelopePromise = sentryServer.waitForEnvelope( | ||
| containingEventWithAndroidMessage('Captured message'), | ||
| ); | ||
|
|
||
| await maestro('tests/captureMessage/captureMessage.test.yml'); | ||
|
|
||
| envelope = await envelopePromise; | ||
| }, 240000); // 240 seconds timeout | ||
|
|
||
| afterAll(async () => { | ||
| await sentryServer.close(); | ||
| }); | ||
|
|
||
| it('envelope contains message event', async () => { | ||
| const item = getItemOfTypeFrom<EventItem>(envelope, 'event'); | ||
|
|
||
| expect(item).toEqual([ | ||
| { | ||
| content_type: 'application/json', | ||
| length: expect.any(Number), | ||
| type: 'event', | ||
| }, | ||
| expect.objectContaining({ | ||
| level: 'info', | ||
| message: { | ||
| message: 'Captured message', | ||
| }, | ||
| platform: 'javascript', | ||
| }), | ||
| ]); | ||
| }); | ||
|
|
||
| it('contains device context', async () => { | ||
| const item = getItemOfTypeFrom<EventItem>(envelope, 'event'); | ||
|
|
||
| expect(item?.[1]).toEqual( | ||
| expect.objectContaining({ | ||
| contexts: expect.objectContaining({ | ||
| device: expect.objectContaining({ | ||
| battery_level: expect.any(Number), | ||
| brand: expect.any(String), | ||
| family: expect.any(String), | ||
| manufacturer: expect.any(String), | ||
| model: expect.any(String), | ||
| simulator: expect.any(Boolean), | ||
| }), | ||
| }), | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('contains app context', async () => { | ||
| const item = getItemOfTypeFrom<EventItem>(envelope, 'event'); | ||
|
|
||
| expect(item?.[1]).toEqual( | ||
| expect.objectContaining({ | ||
| contexts: expect.objectContaining({ | ||
| app: expect.objectContaining({ | ||
| app_identifier: expect.any(String), | ||
| app_name: expect.any(String), | ||
| app_version: expect.any(String), | ||
| }), | ||
| }), | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('SDK initialized from JavaScript (auto init)', async () => { | ||
| const item = getItemOfTypeFrom<EventItem>(envelope, 'event'); | ||
|
|
||
| // Verify that native SDK was NOT initialized before JS | ||
| // When auto init, the SDK is initialized from JavaScript | ||
| expect(item?.[1]).toEqual( | ||
| expect.objectContaining({ | ||
| sdk: expect.objectContaining({ | ||
| name: 'sentry.javascript.react-native', | ||
| }), | ||
| }), | ||
| ); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Exit on error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set -e | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| thisFilePath=$(dirname "$0") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export RN_ARCHITECTURE="new" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export CONFIG="debug" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export SENTRY_DISABLE_NATIVE_START="true" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Building Android with SENTRY_DISABLE_NATIVE_START=${SENTRY_DISABLE_NATIVE_START}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "This build will initialize Sentry from JavaScript (auto init)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "${thisFilePath}/build-android.sh" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Rename the output APK to distinguish it from manual build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cd "${thisFilePath}/.." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -f "app.apk" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mv app.apk app-auto.apk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Build complete: app-auto.apk" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+22
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.