Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-zimerman committed Aug 15, 2024
1 parent 060294d commit 27132ce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/js/tools/metroconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ export function excludeSentryWebReplay(config: MetroConfig, includeWebReplay: bo
resolver: {
...config.resolver,
resolveRequest: (context, moduleName, platform) => {
if (includeWebReplay === false || platform !== 'web' &&
moduleName.includes('@sentry/replay')) {
if (includeWebReplay === false || (platform !== 'web' && moduleName.includes('@sentry/replay'))) {
return { type: 'empty' };
}
if (originalResolver) {
Expand All @@ -179,7 +178,7 @@ export function excludeSentryWebReplay(config: MetroConfig, includeWebReplay: bo
return context.resolveRequest(context, moduleName, platform);
},
},
}
};
}

type MetroFrame = Parameters<Required<Required<MetroConfig>['symbolicator']>['customizeFrame']>[0];
Expand Down
23 changes: 14 additions & 9 deletions test/tools/metroconfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import type { MetroConfig } from 'metro';
import * as path from 'path';
import * as process from 'process';

import { excludeSentryWebReplay,withSentryBabelTransformer, withSentryFramesCollapsed } from '../../src/js/tools/metroconfig';
import {
excludeSentryWebReplay,
withSentryBabelTransformer,
withSentryFramesCollapsed,
} from '../../src/js/tools/metroconfig';

type MetroFrame = Parameters<Required<Required<MetroConfig>['symbolicator']>['customizeFrame']>[0];

Expand Down Expand Up @@ -110,11 +114,11 @@ describe('metroconfig', () => {
});

describe('excludeSentryWebReplay', () => {
let originalResolverMock : any;
let originalResolverMock: any;

// @ts-expect-error Can't see type CustomResolutionContext
let contextMock : CustomResolutionContext;
let config : MetroConfig = {};
let contextMock: CustomResolutionContext;
let config: MetroConfig = {};

beforeEach(() => {
originalResolverMock = jest.fn();
Expand Down Expand Up @@ -144,7 +148,7 @@ describe('metroconfig', () => {
expect(originalResolverMock).not.toHaveBeenCalled();
});

/* Test expected to fail but not required since excludeSentryWebReplay is not run when includeWebReplay is true.
/* Test expected to fail but not required since excludeSentryWebReplay is not run when includeWebReplay is true.
test('keep Web Replay when platform is android and includeWebReplay is true', () => {
const modifiedConfig = excludeSentryWebReplay(config, true);
resolveRequest(modifiedConfig, contextMock, '@sentry/replay', 'android');
Expand All @@ -169,7 +173,7 @@ describe('metroconfig', () => {
expect(originalResolverMock).not.toHaveBeenCalled();
});

/* Test expected to fail but not required since excludeSentryWebReplay is not run when includeWebReplay is true.
/* Test expected to fail but not required since excludeSentryWebReplay is not run when includeWebReplay is true.
test('keep Web Replay when platform is ios and includeWebReplay is true', () => {
const modifiedConfig = excludeSentryWebReplay(config, true);
resolveRequest(modifiedConfig, contextMock, '@sentry/replay', 'ios');
Expand Down Expand Up @@ -197,15 +201,15 @@ describe('metroconfig', () => {
test('calls originalResolver when moduleName is not @sentry/replay', () => {
const modifiedConfig = excludeSentryWebReplay(config, true);
const moduleName = 'some/other/module';
resolveRequest(modifiedConfig,contextMock, moduleName, 'web');
resolveRequest(modifiedConfig, contextMock, moduleName, 'web');

expect(originalResolverMock).toHaveBeenCalledWith(contextMock, moduleName, 'web');
});

test('calls context.resolveRequest when originalResolver is not provided', () => {
const modifiedConfig = excludeSentryWebReplay({ resolver: {} }, true);
const moduleName = 'some/other/module';
resolveRequest(modifiedConfig,contextMock, moduleName, 'web');
resolveRequest(modifiedConfig, contextMock, moduleName, 'web');

expect(contextMock.resolveRequest).toHaveBeenCalledWith(contextMock, moduleName, 'web');
});
Expand All @@ -219,4 +223,5 @@ function createMockSentryInstrumentMetroFrame(): MetroFrame {

// @ts-expect-error Can't see type Resolution.
function resolveRequest(metroConfig: MetroConfig, context: any, moduleName: string, platform: string): Resolution {
return metroConfig.resolver?.resolveRequest && metroConfig.resolver.resolveRequest(context, moduleName, platform);}
return metroConfig.resolver?.resolveRequest && metroConfig.resolver.resolveRequest(context, moduleName, platform);
}

0 comments on commit 27132ce

Please sign in to comment.