This package provides a TypeScript transformer designed to automatically strip `data-test-id` and `data-testid` attributes from JSX elements during the build process, primarily for production builds. It helps clean up the final DOM, removing attributes that are only relevant for testing and debugging, thus preventing unnecessary bloat or exposure of internal testing concerns. The current stable version is 1.1.0, released in October 2020. This project does not follow a strict release cadence, with updates being made as needed. A key differentiator is its implementation as a TypeScript transformer, offering integration into TypeScript compilation workflows (e.g., via webpack with `ts-loader`), as opposed to similar solutions built as Babel plugins.
npm install typescript-transformer-jsx-remove-data-test-idVerified import paths — ran on the pinned version, not inferred.
This webpack configuration demonstrates how to integrate the TypeScript transformer using `ts-loader` to remove `data-test-id` and `data-testid` attributes from production builds of React/TypeScript applications.
Configure your build tool (e.g., webpack) to use `ts-loader`'s `getCustomTransformers` option or an equivalent mechanism in other bundlers.
Upgrade to `1.1.0` or higher to ensure both `data-test-id` and `data-testid` attributes are removed if both are present in your codebase.
Wrap the transformer application in conditional logic based on your environment variables (e.g., `process.env.NODE_ENV === 'production'`) within your webpack or build configuration.
Use named import syntax: `import { removeDataTestIdTransformer } from 'typescript-transformer-jsx-remove-data-test-id';` or CommonJS destructuring: `const { removeDataTestIdTransformer } = require('typescript-transformer-jsx-remove-data-test-id');`Verify that `ts-loader` is configured with `getCustomTransformers: () => ({ before: [removeDataTestIdTransformer()] })` in your webpack config for `.tsx` files. Ensure your `tsconfig.json` supports JSX. Check that `typescript-transformer-jsx-remove-data-test-id` is version `1.1.0` or higher for `data-testid` support.