11import { describe , it , beforeAll , expect , afterAll } from '@jest/globals' ;
2- import { Envelope } from '@sentry/core' ;
2+ import { Envelope , EventItem } from '@sentry/core' ;
33import { device } from 'detox' ;
44import {
55 createSentryServer ,
66 containingEvent ,
77} from './utils/mockedSentryServer' ;
8- import { HEADER , ITEMS } from './utils/consts' ;
98import { tap } from './utils/tap' ;
9+ import { getItemOfTypeFrom } from './utils/event' ;
1010
1111describe ( 'Capture message' , ( ) => {
1212 let sentryServer = createSentryServer ( ) ;
@@ -27,9 +27,7 @@ describe('Capture message', () => {
2727 } ) ;
2828
2929 it ( 'envelope contains message event' , async ( ) => {
30- const item = ( envelope [ ITEMS ] as [ { type ?: string } , unknown ] [ ] ) . find (
31- i => i [ HEADER ] . type === 'event' ,
32- ) ;
30+ const item = getItemOfTypeFrom < EventItem > ( envelope , 'event' ) ;
3331
3432 expect ( item ) . toEqual ( [
3533 {
@@ -46,4 +44,103 @@ describe('Capture message', () => {
4644 } ) ,
4745 ] ) ;
4846 } ) ;
47+
48+ it ( 'contains device context' , async ( ) => {
49+ const item = getItemOfTypeFrom < EventItem > ( envelope , 'event' ) ;
50+
51+ expect ( item ?. [ 1 ] ) . toEqual (
52+ expect . objectContaining ( {
53+ contexts : expect . objectContaining ( {
54+ device : expect . objectContaining ( {
55+ battery_level : expect . any ( Number ) ,
56+ battery_temperature : expect . any ( Number ) ,
57+ boot_time : expect . any ( String ) ,
58+ brand : expect . any ( String ) ,
59+ charging : expect . any ( Boolean ) ,
60+ connection_type : expect . any ( String ) ,
61+ family : expect . any ( String ) ,
62+ free_memory : expect . any ( Number ) ,
63+ free_storage : expect . any ( Number ) ,
64+ id : expect . any ( String ) ,
65+ language : expect . any ( String ) ,
66+ locale : expect . any ( String ) ,
67+ low_memory : expect . any ( Boolean ) ,
68+ manufacturer : expect . any ( String ) ,
69+ memory_size : expect . any ( Number ) ,
70+ model : expect . any ( String ) ,
71+ model_id : expect . any ( String ) ,
72+ online : expect . any ( Boolean ) ,
73+ orientation : expect . any ( String ) ,
74+ processor_count : expect . any ( Number ) ,
75+ processor_frequency : expect . any ( Number ) ,
76+ screen_density : expect . any ( Number ) ,
77+ screen_dpi : expect . any ( Number ) ,
78+ screen_height_pixels : expect . any ( Number ) ,
79+ screen_width_pixels : expect . any ( Number ) ,
80+ simulator : expect . any ( Boolean ) ,
81+ storage_size : expect . any ( Number ) ,
82+ timezone : expect . any ( String ) ,
83+ } ) ,
84+ } ) ,
85+ } ) ,
86+ ) ;
87+ } ) ;
88+
89+ it ( 'contains app context' , async ( ) => {
90+ const item = getItemOfTypeFrom < EventItem > ( envelope , 'event' ) ;
91+
92+ expect ( item ?. [ 1 ] ) . toEqual (
93+ expect . objectContaining ( {
94+ contexts : expect . objectContaining ( {
95+ app : expect . objectContaining ( {
96+ app_build : expect . any ( String ) ,
97+ app_identifier : expect . any ( String ) ,
98+ app_name : expect . any ( String ) ,
99+ app_start_time : expect . any ( String ) ,
100+ app_version : expect . any ( String ) ,
101+ in_foreground : expect . any ( Boolean ) ,
102+ view_names : [ 'ErrorsScreen' ] ,
103+ } ) ,
104+ } ) ,
105+ } ) ,
106+ ) ;
107+ } ) ;
108+
109+ it ( 'contains os context' , async ( ) => {
110+ const item = getItemOfTypeFrom < EventItem > ( envelope , 'event' ) ;
111+
112+ expect ( item ?. [ 1 ] ) . toEqual (
113+ expect . objectContaining ( {
114+ contexts : expect . objectContaining ( {
115+ os : {
116+ build : expect . any ( String ) ,
117+ kernel_version : expect . any ( String ) ,
118+ name : 'Android' ,
119+ rooted : expect . any ( Boolean ) ,
120+ version : expect . any ( String ) ,
121+ } ,
122+ } ) ,
123+ } ) ,
124+ ) ;
125+ } ) ;
126+
127+ it ( 'contains react native context' , async ( ) => {
128+ const item = getItemOfTypeFrom < EventItem > ( envelope , 'event' ) ;
129+
130+ expect ( item ?. [ 1 ] ) . toEqual (
131+ expect . objectContaining ( {
132+ contexts : expect . objectContaining ( {
133+ react_native_context : {
134+ expo : false ,
135+ fabric : expect . any ( Boolean ) ,
136+ hermes_debug_info : expect . any ( Boolean ) ,
137+ hermes_version : expect . any ( String ) ,
138+ js_engine : 'hermes' ,
139+ react_native_version : expect . any ( String ) ,
140+ turbo_module : expect . any ( Boolean ) ,
141+ } ,
142+ } ) ,
143+ } ) ,
144+ ) ;
145+ } ) ;
49146} ) ;
0 commit comments