Skip to content

Commit ae342a3

Browse files
test(e2e): Verify captured Errors Screen transaction (#4584)
1 parent 952dd05 commit ae342a3

File tree

6 files changed

+448
-14
lines changed

6 files changed

+448
-14
lines changed

samples/react-native/e2e/captureMessage.test.android.ts

Lines changed: 102 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { describe, it, beforeAll, expect, afterAll } from '@jest/globals';
2-
import { Envelope } from '@sentry/core';
2+
import { Envelope, EventItem } from '@sentry/core';
33
import { device } from 'detox';
44
import {
55
createSentryServer,
66
containingEvent,
77
} from './utils/mockedSentryServer';
8-
import { HEADER, ITEMS } from './utils/consts';
98
import { tap } from './utils/tap';
9+
import { getItemOfTypeFrom } from './utils/event';
1010

1111
describe('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
});

samples/react-native/e2e/captureMessage.test.ios.ts

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { describe, it, beforeAll, expect, afterAll } from '@jest/globals';
2-
import { Envelope } from '@sentry/core';
2+
import { Envelope, EventItem } from '@sentry/core';
33
import { device } from 'detox';
44
import {
55
createSentryServer,
66
containingEvent,
77
} from './utils/mockedSentryServer';
8-
import { HEADER, ITEMS } from './utils/consts';
98
import { tap } from './utils/tap';
9+
import { getItemOfTypeFrom } from './utils/event';
1010

1111
describe('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
{
@@ -43,4 +41,86 @@ describe('Capture message', () => {
4341
}),
4442
]);
4543
});
44+
45+
it('contains device context', async () => {
46+
const item = getItemOfTypeFrom<EventItem>(envelope, 'event');
47+
48+
expect(item?.[1]).toEqual(
49+
expect.objectContaining({
50+
contexts: expect.objectContaining({
51+
device: expect.objectContaining({
52+
arch: expect.any(String),
53+
family: expect.any(String),
54+
free_memory: expect.any(Number),
55+
locale: expect.any(String),
56+
memory_size: expect.any(Number),
57+
model: expect.any(String),
58+
model_id: expect.any(String),
59+
processor_count: expect.any(Number),
60+
simulator: expect.any(Boolean),
61+
thermal_state: expect.any(String),
62+
usable_memory: expect.any(Number),
63+
}),
64+
}),
65+
}),
66+
);
67+
});
68+
69+
it('contains app context', async () => {
70+
const item = getItemOfTypeFrom<EventItem>(envelope, 'event');
71+
72+
expect(item?.[1]).toEqual(
73+
expect.objectContaining({
74+
contexts: expect.objectContaining({
75+
app: expect.objectContaining({
76+
app_build: expect.any(String),
77+
app_identifier: expect.any(String),
78+
app_name: expect.any(String),
79+
app_start_time: expect.any(String),
80+
app_version: expect.any(String),
81+
in_foreground: expect.any(Boolean),
82+
// view_names: ['ErrorsScreen-jn5qquvH9Nz'], // TODO: fix this generated hash should not be part of the name
83+
}),
84+
}),
85+
}),
86+
);
87+
});
88+
89+
it('contains os context', async () => {
90+
const item = getItemOfTypeFrom<EventItem>(envelope, 'event');
91+
92+
expect(item?.[1]).toEqual(
93+
expect.objectContaining({
94+
contexts: expect.objectContaining({
95+
os: {
96+
build: expect.any(String),
97+
kernel_version: expect.any(String),
98+
name: 'iOS',
99+
rooted: expect.any(Boolean),
100+
version: expect.any(String),
101+
},
102+
}),
103+
}),
104+
);
105+
});
106+
107+
it('contains react native context', async () => {
108+
const item = getItemOfTypeFrom<EventItem>(envelope, 'event');
109+
110+
expect(item?.[1]).toEqual(
111+
expect.objectContaining({
112+
contexts: expect.objectContaining({
113+
react_native_context: {
114+
expo: false,
115+
fabric: expect.any(Boolean),
116+
hermes_debug_info: expect.any(Boolean),
117+
hermes_version: expect.any(String),
118+
js_engine: 'hermes',
119+
react_native_version: expect.any(String),
120+
turbo_module: expect.any(Boolean),
121+
},
122+
}),
123+
}),
124+
);
125+
});
46126
});

0 commit comments

Comments
 (0)