diff --git a/packages/core/test/tools/metroconfig.test.ts b/packages/core/test/tools/metroconfig.test.ts index 2d2addeb11..18177fb71e 100644 --- a/packages/core/test/tools/metroconfig.test.ts +++ b/packages/core/test/tools/metroconfig.test.ts @@ -1,6 +1,7 @@ import type { getDefaultConfig } from 'expo/metro-config'; import type { MetroConfig } from 'metro'; import * as process from 'process'; +import type { SentryExpoConfigOptions } from '../../src/js/tools/metroconfig'; import { getSentryExpoConfig, withSentryBabelTransformer, @@ -31,6 +32,45 @@ describe('metroconfig', () => { acceptsExpoDefaultConfigFactory(getSentryExpoConfig); }); + describe('SentryExpoConfigOptions.getDefaultConfig type compatibility', () => { + const checkCompatibility = (_options: SentryExpoConfigOptions): void => { + expect(true).toBe(true); + }; + + test('accepts a getDefaultConfig with the new flexible Record signature (Expo SDK 54 format)', () => { + // Expo SDK 54 Metro type definitions diverged from the metro package. + // The fix allows passing a getDefaultConfig with flexible types rather than + // the exact MetroConfig return type, accommodating different Metro versions. + const newFormatGetDefaultConfig = ( + _projectRoot: string, + _options?: Record, + ): Record => ({}); + + checkCompatibility({ getDefaultConfig: newFormatGetDefaultConfig }); + }); + + test('accepts a getDefaultConfig wrapping expo/metro-config (old usage pattern)', () => { + // Old usage pattern: users wrapping expo/metro-config's getDefaultConfig to + // add custom transformer or resolver config (e.g. react-native-svg-transformer). + // Record options are compatible with DefaultConfigOptions, + // and the spread object return type is compatible with Record. + const expoGetDefaultConfigMock: typeof getDefaultConfig = jest.fn().mockReturnValue({}); + + const oldPatternGetDefaultConfig = (projectRoot: string, options?: Record) => { + // Record is compatible with DefaultConfigOptions (all optional fields) + const config = expoGetDefaultConfigMock(projectRoot, options as Parameters[1]); + return { + ...config, + transformer: { + ...config.transformer, + }, + }; + }; + + checkCompatibility({ getDefaultConfig: oldPatternGetDefaultConfig }); + }); + }); + describe('withSentryFramesCollapsed', () => { test('adds customizeFrames if undefined ', () => { const config = withSentryFramesCollapsed({});