Skip to content

Commit cf00d4d

Browse files
internal(sample-rn): Add header and message envelope tests (#4536)
1 parent 28cf7b4 commit cf00d4d

17 files changed

+499
-9
lines changed

.github/workflows/sample-application.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ jobs:
114114
if: ${{ matrix.platform == 'android' }}
115115
working-directory: ${{ env.REACT_NATIVE_SAMPLE_PATH }}/android
116116
run: |
117+
../scripts/set-aos-dsn.mjs
118+
117119
if [[ ${{ matrix.rn-architecture }} == 'new' ]]; then
118120
perl -i -pe's/newArchEnabled=false/newArchEnabled=true/g' gradle.properties
119121
echo 'New Architecture enabled'
@@ -134,6 +136,8 @@ jobs:
134136
if: ${{ matrix.platform == 'ios' }}
135137
working-directory: ${{ env.REACT_NATIVE_SAMPLE_PATH }}/ios
136138
run: |
139+
../scripts/set-ios-dsn.mjs
140+
137141
[[ "${{ matrix.build-type }}" == "production" ]] && CONFIG='Release' || CONFIG='Debug'
138142
echo "Building $CONFIG"
139143
mkdir -p "DerivedData"

samples/react-native/.detoxrc.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
const process = require('process');
22

3+
const testRunnerIos = {
4+
args: {
5+
$0: 'jest',
6+
config: 'e2e/jest.config.ios.js',
7+
},
8+
jest: {
9+
setupTimeout: 120000,
10+
},
11+
};
12+
13+
const testRunnerAos = {
14+
args: {
15+
$0: 'jest',
16+
config: 'e2e/jest.config.android.js',
17+
},
18+
jest: {
19+
setupTimeout: 120000,
20+
},
21+
};
22+
323
/** @type {Detox.DetoxConfig} */
424
module.exports = {
5-
testRunner: {
6-
args: {
7-
$0: 'jest',
8-
config: 'e2e/jest.config.js',
9-
},
10-
jest: {
11-
setupTimeout: 120000,
12-
},
13-
},
25+
testRunner: {},
1426
apps: {
1527
'ios.debug': {
1628
type: 'ios.app',
@@ -86,34 +98,42 @@ module.exports = {
8698
'ios.sim.debug': {
8799
device: 'simulator',
88100
app: 'ios.debug',
101+
testRunner: testRunnerIos,
89102
},
90103
'ios.sim.release': {
91104
device: 'simulator',
92105
app: 'ios.release',
106+
testRunner: testRunnerIos,
93107
},
94108
'android.att.debug': {
95109
device: 'attached',
96110
app: 'android.debug',
111+
testRunner: testRunnerAos,
97112
},
98113
'android.att.release': {
99114
device: 'attached',
100115
app: 'android.release',
116+
testRunner: testRunnerAos,
101117
},
102118
'android.emu.debug': {
103119
device: 'emulator',
104120
app: 'android.debug',
121+
testRunner: testRunnerAos,
105122
},
106123
'android.emu.release': {
107124
device: 'emulator',
108125
app: 'android.release',
126+
testRunner: testRunnerAos,
109127
},
110128
'ci.android': {
111129
device: 'ci.emulator',
112130
app: 'ci.android',
131+
testRunner: testRunnerAos,
113132
},
114133
'ci.sim': {
115134
device: 'ci.simulator',
116135
app: 'ci.ios',
136+
testRunner: testRunnerIos,
117137
},
118138
},
119139
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { describe, it, beforeAll, expect } from '@jest/globals';
2+
import { Envelope } from '@sentry/core';
3+
import { device } from 'detox';
4+
import {
5+
createSentryServer,
6+
containingEvent,
7+
} from './utils/mockedSentryServer';
8+
import { HEADER, ITEMS } from './utils/consts';
9+
import { tap } from './utils/tap';
10+
11+
describe('Capture message', () => {
12+
let sentryServer = createSentryServer();
13+
sentryServer.start();
14+
15+
let envelope: Envelope;
16+
17+
beforeAll(async () => {
18+
await device.launchApp();
19+
20+
const envelopePromise = sentryServer.waitForEnvelope(containingEvent);
21+
await tap('Capture message');
22+
envelope = await envelopePromise;
23+
});
24+
25+
afterAll(async () => {
26+
await sentryServer.close();
27+
});
28+
29+
it('envelope contains message event', async () => {
30+
const item = (envelope[ITEMS] as [{ type?: string }, unknown][]).find(
31+
i => i[HEADER].type === 'event',
32+
);
33+
34+
expect(item).toEqual([
35+
{
36+
content_type: 'application/json',
37+
length: expect.any(Number),
38+
type: 'event',
39+
},
40+
expect.objectContaining({
41+
level: 'info',
42+
message: {
43+
message: 'Captured message',
44+
},
45+
platform: 'javascript',
46+
}),
47+
]);
48+
});
49+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { describe, it, beforeAll, expect } from '@jest/globals';
2+
import { Envelope } from '@sentry/core';
3+
import { device } from 'detox';
4+
import {
5+
createSentryServer,
6+
containingEvent,
7+
} from './utils/mockedSentryServer';
8+
import { HEADER, ITEMS } from './utils/consts';
9+
import { tap } from './utils/tap';
10+
11+
describe('Capture message', () => {
12+
let sentryServer = createSentryServer();
13+
sentryServer.start();
14+
15+
let envelope: Envelope;
16+
17+
beforeAll(async () => {
18+
await device.launchApp();
19+
20+
const envelopePromise = sentryServer.waitForEnvelope(containingEvent);
21+
await tap('Capture message');
22+
envelope = await envelopePromise;
23+
});
24+
25+
afterAll(async () => {
26+
await sentryServer.close();
27+
});
28+
29+
it('envelope contains message event', async () => {
30+
const item = (envelope[ITEMS] as [{ type?: string }, unknown][]).find(
31+
i => i[HEADER].type === 'event',
32+
);
33+
34+
expect(item).toEqual([
35+
{
36+
length: expect.any(Number),
37+
type: 'event',
38+
},
39+
expect.objectContaining({
40+
level: 'info',
41+
message: 'Captured message',
42+
platform: 'javascript',
43+
}),
44+
]);
45+
});
46+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { describe, it, beforeAll, expect } from '@jest/globals';
2+
import { Envelope } from '@sentry/core';
3+
import { device } from 'detox';
4+
import {
5+
createSentryServer,
6+
containingEvent,
7+
} from './utils/mockedSentryServer';
8+
import { HEADER } from './utils/consts';
9+
import { tap } from './utils/tap';
10+
11+
describe('Capture message', () => {
12+
let sentryServer = createSentryServer();
13+
sentryServer.start();
14+
15+
let envelope: Envelope;
16+
17+
beforeAll(async () => {
18+
await device.launchApp();
19+
20+
const envelopePromise = sentryServer.waitForEnvelope(containingEvent);
21+
22+
await tap('Capture message');
23+
envelope = await envelopePromise;
24+
});
25+
26+
afterAll(async () => {
27+
await sentryServer.close();
28+
});
29+
30+
it('contains event_id and sent_at in the envelope header', async () => {
31+
expect(envelope[HEADER]).toEqual(
32+
expect.objectContaining({
33+
event_id: expect.any(String),
34+
sent_at: expect.any(String),
35+
}),
36+
);
37+
});
38+
39+
it('contains sdk info in the envelope header', async () => {
40+
expect(envelope[HEADER]).toEqual(
41+
expect.objectContaining({
42+
sdk: {
43+
name: 'sentry.javascript.react-native',
44+
version: expect.any(String),
45+
},
46+
sent_at: expect.any(String),
47+
}),
48+
);
49+
});
50+
51+
it('contains trace info in the envelope header', async () => {
52+
expect(envelope[HEADER]).toEqual(
53+
expect.objectContaining({
54+
trace: {
55+
environment: expect.any(String),
56+
public_key: expect.any(String),
57+
replay_id: expect.any(String),
58+
trace_id: expect.any(String),
59+
},
60+
}),
61+
);
62+
});
63+
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { describe, it, beforeAll, expect } from '@jest/globals';
2+
import { Envelope } from '@sentry/core';
3+
import { device } from 'detox';
4+
import {
5+
createSentryServer,
6+
containingEvent,
7+
} from './utils/mockedSentryServer';
8+
import { HEADER } from './utils/consts';
9+
import { tap } from './utils/tap';
10+
11+
describe('Capture message', () => {
12+
let sentryServer = createSentryServer();
13+
sentryServer.start();
14+
15+
let envelope: Envelope;
16+
17+
beforeAll(async () => {
18+
await device.launchApp();
19+
20+
const envelopePromise = sentryServer.waitForEnvelope(containingEvent);
21+
22+
await tap('Capture message');
23+
envelope = await envelopePromise;
24+
});
25+
26+
afterAll(async () => {
27+
await sentryServer.close();
28+
});
29+
30+
it('contains event_id and sent_at in the envelope header', async () => {
31+
expect(envelope[HEADER]).toEqual(
32+
expect.objectContaining({
33+
event_id: expect.any(String),
34+
sent_at: expect.any(String),
35+
}),
36+
);
37+
});
38+
39+
it('contains sdk info in the envelope header', async () => {
40+
expect(envelope[HEADER]).toEqual(
41+
expect.objectContaining({
42+
sdk: {
43+
features: [],
44+
integrations: [],
45+
name: 'sentry.javascript.react-native',
46+
packages: [],
47+
version: expect.any(String),
48+
},
49+
sent_at: expect.any(String),
50+
}),
51+
);
52+
});
53+
54+
it('contains trace info in the envelope header', async () => {
55+
expect(envelope[HEADER]).toEqual(
56+
expect.objectContaining({
57+
trace: {
58+
environment: expect.any(String),
59+
public_key: expect.any(String),
60+
replay_id: expect.any(String),
61+
sample_rate: '1',
62+
sampled: '1',
63+
trace_id: expect.any(String),
64+
transaction: 'ErrorsScreen',
65+
},
66+
}),
67+
);
68+
});
69+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/** @type {import('@jest/types').Config.InitialOptions} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
rootDir: '..',
5+
testMatch: [
6+
'<rootDir>/e2e/**/*.test.ts',
7+
'<rootDir>/e2e/**/*.test.android.ts',
8+
],
9+
testTimeout: 120000,
10+
maxWorkers: 1,
11+
globalSetup: 'detox/runners/jest/globalSetup',
12+
globalTeardown: 'detox/runners/jest/globalTeardown',
13+
reporters: ['detox/runners/jest/reporter'],
14+
testEnvironment: 'detox/runners/jest/testEnvironment',
15+
verbose: true,
16+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/** @type {import('@jest/types').Config.InitialOptions} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
rootDir: '..',
5+
testMatch: ['<rootDir>/e2e/**/*.test.ts', '<rootDir>/e2e/**/*.test.ios.ts'],
6+
testTimeout: 120000,
7+
maxWorkers: 1,
8+
globalSetup: 'detox/runners/jest/globalSetup',
9+
globalTeardown: 'detox/runners/jest/globalTeardown',
10+
reporters: ['detox/runners/jest/reporter'],
11+
testEnvironment: 'detox/runners/jest/testEnvironment',
12+
verbose: true,
13+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const HEADER = 0;
2+
export const ITEMS = 1;

0 commit comments

Comments
 (0)