Skip to content

Commit 35a0038

Browse files
add react annotate to e2e tests
1 parent f5d0d6e commit 35a0038

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

test/react-native/rn.patch.metro.config.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const importSerializer = "const { withSentryConfig } = require('@sentry/react-na
2020

2121
let config = fs.readFileSync(configFilePath, 'utf8').split('\n');
2222

23+
const sentryOptions = '{ annotateReactComponents: true }';
24+
2325
const isPatched = config.includes(importSerializer);
2426
if (!isPatched) {
2527
config = [importSerializer, ...config];
@@ -35,11 +37,18 @@ if (!isPatched) {
3537
lineParsed[1] = lineParsed[1].slice(0, -1);
3638
}
3739

38-
lineParsed[1] = `= withSentryConfig(${lineParsed[1]}${endsWithSemicolon ? ');' : ''}`;
40+
lineParsed[1] = `= withSentryConfig(${lineParsed[1]}${endsWithSemicolon ? `, ${sentryOptions});` : ''}`;
3941
config[moduleExportsLineIndex] = lineParsed.join('');
4042

4143
if (endOfModuleExportsIndex !== -1) {
42-
config[endOfModuleExportsIndex] = '});';
44+
config[endOfModuleExportsIndex] = `}, ${sentryOptions});`;
45+
}
46+
47+
// RN Before 0.72 does not include default config in the metro.config.js
48+
// We have to specify babelTransformerPath manually
49+
const transformerIndex = config.findIndex(line => line.includes('transformer: {'));
50+
if (transformerIndex !== -1) {
51+
config[transformerIndex] = `transformer: { babelTransformerPath: require.resolve('metro-babel-transformer'),`;
4352
}
4453

4554
fs.writeFileSync(configFilePath, config.join('\n'), 'utf8');

0 commit comments

Comments
 (0)