The `babel-plugin-react-test-id` package provides a Babel plugin designed to automatically remove specified props, such as `testID`, from React components during the build process. This is particularly useful for optimizing production bundles by eliminating test-specific attributes that are not needed in the final deployed application, thereby reducing bundle size and preventing the exposure of internal testing implementation details. The current stable version is 1.0.2. As a build-time utility, its release cadence is typically slow, with updates primarily driven by changes in Babel's API or feature requests for additional prop removal customization. It differentiates itself by offering a straightforward, declarative way to strip these attributes without manual refactoring or conditional rendering logic within components, ensuring a clean separation between testing instrumentation and production code.
npm install babel-plugin-react-test-idVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to install `babel-plugin-react-test-id`, configure it in `.babelrc`, and use a `npm run build` script to process a React component file. The resulting output in `dist/App.js` will show that `testID` props have been successfully removed, illustrating its function in a typical development workflow.
Ensure `babel-plugin-react-test-id` is included in your `.babelrc`, `babel.config.js`, or Babel CLI arguments, and that your build scripts invoke Babel correctly for the target environment.
Double-check the `props` array in your Babel configuration (e.g., `['data-test-id', 'customTestId']`) against your component code.
Run `npm install --save-dev babel-plugin-react-test-id` or `yarn add --dev babel-plugin-react-test-id`. If in a monorepo or with custom paths, ensure the plugin can be resolved (e.g., use `require.resolve('babel-plugin-react-test-id')` in `babel.config.js`).