A Babel plugin that automatically generates testID (and id) props for React Native components, designed to streamline automated testing with Detox, Appium, or similar frameworks. Current stable version is 0.2.1, released under an Apache-2.0 license, with no recent updates. Release cadence is low. Key differentiators: supports a multi-priority strategy for testID generation (manual props, meaningful attributes like title/placeholder, children text with i18n key extraction, fallback to component hierarchy), is highly configurable (attributes list, delimiter, ignore list, custom meaningful attributes), and ships TypeScript definitions. Alternatives like react-native-testid or babel-plugin-react-native-transform-testid offer simpler fixed-pattern approaches, whereas this plugin prioritizes semantic and stable IDs from props and i18n keys.
npm install babel-plugin-react-native-testidVerified import paths — ran on the pinned version, not inferred.
Configures the Babel plugin with custom settings and demonstrates how it automatically adds testID to TextInput, Button, and Text components with i18n key extraction.
If you only want 'testID', set attributes: ['testID'] in config.
Upgrade Node.js to >=10 or stay on older plugin version.
Replace 'addId: true' with 'attributes: ["testID", "id"]' in config.
Ensure i18n keys are static strings passed directly to the t() or i18n.t() call. Avoid template literals or variable keys.
Set 'ignoreElements: []' in config if you want testID on all components.
If you need stable testID from text, ensure children are static strings or i18n function calls.
Upgrade Babel to v7+ or use babel-upgrade. The plugin is designed for Babel 7.
Ensure your Babel config is correct and the plugin is last in the plugins array. If the error persists, file an issue with the plugin author.
Run 'npm install babel-plugin-react-native-testid --save-dev' or 'yarn add babel-plugin-react-native-testid --dev'.