Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions samples/react-native/e2e/jest.config.android.auto.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const baseConfig = require('./jest.config.base');
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
...baseConfig,
globals: { E2E_PLATFORM: 'android' },
globalSetup: path.resolve(__dirname, 'setup.android.auto.ts'),
testMatch: [
...baseConfig.testMatch,
Expand Down
1 change: 1 addition & 0 deletions samples/react-native/e2e/jest.config.android.manual.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const baseConfig = require('./jest.config.base');
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
...baseConfig,
globals: { E2E_PLATFORM: 'android' },
testMatch: [
...baseConfig.testMatch,
'<rootDir>/e2e/**/*.test.android.ts',
Expand Down
1 change: 1 addition & 0 deletions samples/react-native/e2e/jest.config.ios.auto.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const baseConfig = require('./jest.config.base');
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
...baseConfig,
globals: { E2E_PLATFORM: 'ios' },
globalSetup: path.resolve(__dirname, 'setup.ios.auto.ts'),
testMatch: [
...baseConfig.testMatch,
Expand Down
1 change: 1 addition & 0 deletions samples/react-native/e2e/jest.config.ios.manual.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const path = require('path');
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
...baseConfig,
globals: { E2E_PLATFORM: 'ios' },
testMatch: [
...baseConfig.testMatch,
'<rootDir>/e2e/**/*.test.ios.ts',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ describe('Capture Errors Screen Transaction', () => {
if (appStartTransaction) break;
}

if (!appStartTransaction) {
// Print what did arrive, so a CI failure shows whether the app start was not
// attached to the ErrorsScreen transaction or that transaction was never sent.
const received = sentryServer.getAllEnvelopes(() => true).flatMap(envelope =>
envelope[1]
.filter(([header]) => header.type === 'transaction')
.map(([, payload]) => {
const event = payload as any;
return {
transaction: event.transaction,
op: event.contexts?.trace?.op,
origin: event.contexts?.trace?.origin,
start_timestamp: event.start_timestamp,
timestamp: event.timestamp,
measurements: Object.keys(event.measurements ?? {}),
span_ops: (event.spans ?? []).map((span: any) => span.op),
};
}),
);
console.log('Received transactions:', JSON.stringify(received, null, 2));
}

expect(appStartTransaction).toBeDefined();

const [header, payload] = appStartTransaction!;
Expand Down Expand Up @@ -123,6 +145,26 @@ describe('Capture Errors Screen Transaction', () => {
);
});

it('contains device connection type', async () => {
// The transaction is sent seconds after launch, once the native SDK reported the
// network path, so `connection_type` is reliably present here โ€” unlike on a message
// captured right after launch (see captureMessage.test.ios.ts).
const item = getItemOfTypeFrom<EventItem>(
getErrorsEnvelope(),
'transaction',
);

expect(item?.[1]).toEqual(
expect.objectContaining({
contexts: expect.objectContaining({
device: expect.objectContaining({
connection_type: expect.any(String),
}),
}),
}),
);
});

it('contains JS stall measurements', async () => {
const item = getItemOfTypeFrom<EventItem>(
await getErrorsEnvelope(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ describe('Capture message', () => {
contexts: expect.objectContaining({
device: expect.objectContaining({
arch: expect.any(String),
connection_type: expect.any(String),
family: expect.any(String),
free_memory: expect.any(Number),
locale: expect.any(String),
Expand All @@ -73,6 +72,16 @@ describe('Capture message', () => {
}),
}),
);

// sentry-cocoa only knows the connection type after its reachability monitor reported the
// first network path, which happens asynchronously after start. A message captured right
// after launch can be sent before that, so the field is optional here. Its presence is
// asserted on a later event in captureErrorsScreenTransaction.test.ts.
const connectionType = (item?.[1].contexts?.device as Record<string, unknown> | undefined)
?.connection_type;
if (connectionType !== undefined) {
expect(connectionType).toEqual(expect.any(String));
}
});

it('contains app context', async () => {
Expand Down
28 changes: 28 additions & 0 deletions samples/react-native/e2e/utils/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { execFileSync } from 'node:child_process';

const APP_ID = 'io.sentry.reactnative.sample';

type E2EPlatform = 'android' | 'ios';

declare const E2E_PLATFORM: E2EPlatform | undefined;

/**
* Stops the sample app if it is still running from a previous test.
*
* Each test file starts its own mocked Sentry server, but the app launched by the
* previous test file keeps running until the next Maestro flow relaunches it. Any
* transaction that app finishes in the meantime (idle navigation spans end seconds
* later) would be delivered to the new server and mixed into the new test's envelopes.
*/
export function stopApp(): void {
const platform = typeof E2E_PLATFORM === 'undefined' ? undefined : E2E_PLATFORM;
try {
if (platform === 'android') {
execFileSync('adb', ['shell', 'am', 'force-stop', APP_ID], { stdio: 'ignore' });
} else if (platform === 'ios') {
execFileSync('xcrun', ['simctl', 'terminate', 'booted', APP_ID], { stdio: 'ignore' });
}
} catch {
// The app is not running, which is the state we want.
}
}
4 changes: 4 additions & 0 deletions samples/react-native/e2e/utils/mockedSentryServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IncomingMessage, ServerResponse, createServer } from 'node:http';
import { createGunzip } from 'node:zlib';
import { Envelope, EnvelopeItem } from '@sentry/core';
import { parseEnvelope } from './parseEnvelope';
import { stopApp } from './app';
import { Event } from '@sentry/core';

type RecordedRequest = {
Expand Down Expand Up @@ -64,6 +65,9 @@ export function createSentryServer({ port = 8961 } = {}): {

return {
start: () => {
// Stop the app left running by the previous test, so its late envelopes
// can't reach this server.
stopApp();
return new Promise<void>((resolve, _reject) => {
server.listen(port, () => {
resolve();
Expand Down
Loading