npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babel-plugin-remove-test-id

v2.0.0

Published

Babel plugin to remove test-id (or any other props) from JSXAttirbutes, object properties, function calls, and file imports

Downloads

2

Readme

another pluginother plugin with the same idea](https://github.com/coderas/babel-plugin-jsx-remove-data-test-id.git), here we have some preferences. Instead of removing specified attributes only from jsx code and object properties, you can remove all files with your test-id from the bundle. In most cases creating separate file help improve readability in our components and tests, and there is no reason why we should leave unnecessary files in bundles.

Install

npm i --save-dev babel-plugin-remove-test-id 

API Reference

There are no default values, so you need to provide your custom for every type, you want. If the option is not provided this step is skipped.

[
    'babel-plugin-jsx-remove-data-test-id',
    {
        importFileNames: 'file-with-test-ids',
        testIdObjects: 'object-with-test-ids',
        jsxAttributes: 'test-id-jsx-attribute',
        objectProperties: 'test-id-property',
    }
]

| Parameter | Type | Description | | :-------- | :------- | :------------------------- | | importFileNames | string or Array<string> | Name(s) of file(s) that should be removed | | testIdObjects | string or Array<string> | If the file is removed, we can still have the imported object in the code. Example: someFunction(ObjectWithTestId.Text) -> someFunction(undefined). Now not working with function calls like func(Obj.func()) | | jsxAttributes | string or Array<string> | Name(s) of attribute(s) that should be removed in jsx components. Use can provide an array, for example ['testid', 'buttonTestid', 'textTestid'] | | objectProperties | string or Array<string> | Name(s) of object property(-ies) that should be removed. Example: someFunction({testid: ObjectWithTestId.Text}) -> someFunction({}) |

importNames and importFileName was replaced by testIdObjects and importFileName in v2.0.0.

Usage

Be careful while adding this package directly into your plugin's array, because your test will be failed. Better choose any of these variants:

  • Babel environment configuration:
    ...,
    env: {
        production: {
            plugins: [
                ...,
                [
                    'babel-plugin-remove-test-id',
                    {
                        importFileNames: 'file-with-test-ids',
                        testIdObjects: 'object-with-test-ids',
                        jsxAttributes: 'test-id-jsx-attribute',
                        objectProperties: 'test-id-property',
                    }
                ],
                ...
            ]
        },
        test: {
            plugins: [...]
        }
    },
    ...
  • Custom environment configuration:
const plugins = [...];

if (process.env.REMOVE_TEST_ID) {
    plugins.push([
        'babel-plugin-remove-test-id',
        {
            importFileNames: 'file-with-test-ids',
            testIdObjects: 'object-with-test-ids',
            jsxAttributes: 'test-id-jsx-attribute',
            objectProperties: 'test-id-property',
        }
    ])
}

module.export = {
    presets: [...],
    plugins
}
  • Predefined *.json files for each environment:
const fs = require('fs');

fs.writeFileSync(
    'path-to-file/babel.config.js',
    process.env.REMOVE_TEST_ID
        ? require('path-to-predefined/bundle.production.json')
        : require('path-to-predefined/bundle.test.json')
)

Examples

Add your test id property into HTML tags

return (
  <div>
    <p data-test-id="component-text">someText</p>
  </div>
);

or into React Native components

return (
  <View>
    <Text testID='any-test-id-value'>someText</Text>
  </View>
)

or into function calls

function TextArgumentTestId(testid) {
    return <Text testID={testid}>{testid}</Text>
}

function TextObjectPropTestId({testid}: {testid: string}) {
    return <Text testid={testid}>{testid}</Text>
}

const textArgumentTestId = TextArgumentTestId('test-id-argument');
const textObjectPropTestId = TextObjectPropTestId({testid: 'test-id-prop'});

return (
    <View>
        <TextObjectPropTestId testid={'test-id-jsx-attribute'} />
        {textArgumentTestId}
        {textObjectPropTestId}
    </View>
)

of import file

import ObjectWithTestId from './FileWithTestIds'

Start your app and check bundle.