Skip to content

Commit dd46979

Browse files
authored
Merge branch 'main' into antonis/issue-3889
2 parents 4e5d1a5 + 7a26cc6 commit dd46979

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

packages/core/test/tools/metroconfig.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { getDefaultConfig } from 'expo/metro-config';
22
import type { MetroConfig } from 'metro';
33
import * as process from 'process';
4+
import type { SentryExpoConfigOptions } from '../../src/js/tools/metroconfig';
45
import {
56
getSentryExpoConfig,
67
withSentryBabelTransformer,
@@ -31,6 +32,45 @@ describe('metroconfig', () => {
3132
acceptsExpoDefaultConfigFactory(getSentryExpoConfig);
3233
});
3334

35+
describe('SentryExpoConfigOptions.getDefaultConfig type compatibility', () => {
36+
const checkCompatibility = (_options: SentryExpoConfigOptions): void => {
37+
expect(true).toBe(true);
38+
};
39+
40+
test('accepts a getDefaultConfig with the new flexible Record<string, unknown> signature (Expo SDK 54 format)', () => {
41+
// Expo SDK 54 Metro type definitions diverged from the metro package.
42+
// The fix allows passing a getDefaultConfig with flexible types rather than
43+
// the exact MetroConfig return type, accommodating different Metro versions.
44+
const newFormatGetDefaultConfig = (
45+
_projectRoot: string,
46+
_options?: Record<string, unknown>,
47+
): Record<string, unknown> => ({});
48+
49+
checkCompatibility({ getDefaultConfig: newFormatGetDefaultConfig });
50+
});
51+
52+
test('accepts a getDefaultConfig wrapping expo/metro-config (old usage pattern)', () => {
53+
// Old usage pattern: users wrapping expo/metro-config's getDefaultConfig to
54+
// add custom transformer or resolver config (e.g. react-native-svg-transformer).
55+
// Record<string, unknown> options are compatible with DefaultConfigOptions,
56+
// and the spread object return type is compatible with Record<string, unknown>.
57+
const expoGetDefaultConfigMock: typeof getDefaultConfig = jest.fn().mockReturnValue({});
58+
59+
const oldPatternGetDefaultConfig = (projectRoot: string, options?: Record<string, unknown>) => {
60+
// Record<string, unknown> is compatible with DefaultConfigOptions (all optional fields)
61+
const config = expoGetDefaultConfigMock(projectRoot, options as Parameters<typeof getDefaultConfig>[1]);
62+
return {
63+
...config,
64+
transformer: {
65+
...config.transformer,
66+
},
67+
};
68+
};
69+
70+
checkCompatibility({ getDefaultConfig: oldPatternGetDefaultConfig });
71+
});
72+
});
73+
3474
describe('withSentryFramesCollapsed', () => {
3575
test('adds customizeFrames if undefined ', () => {
3676
const config = withSentryFramesCollapsed({});

0 commit comments

Comments
 (0)