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-transform-react-qa-classes

v1.6.0

Published

Add component's name in `data-qa` attributes to React Components Edit

Downloads

58,071

Readme

Babel plugin transform React qa classes

Build Status js-standard-style npm

This babel plugin adds the component name as a data-qa in each React Component.

This plugin asumes that you are using React and Babel as a building tool to generate your bundle.

Why?

The idea is to facilitate Automate Testing on Frontend Applications. Automate Frontend highly requires to get the DOMElements and interact with them, adding data-qa attributes automatically to all the components will make it more easy, rather than do it by code, with this way you won't have this data-qa in production code.

On the testing site would need to get the element like that:

document.querySelectorAll('[data-qa="component"]')

That depends on the Test suit stack, for example with Ruby and PageObject looks like that:

div(:component, data_qa: 'component')

Install

npm install --save-dev babel-plugin-transform-react-qa-classes
# or yarn add -D

Use

Inside .babelrc:

{
  "presets": ["es2015", "react"],
  "env": {
    "dev": {
      "plugins": ["transform-react-qa-classes"]
    }
  }
}

Note: Adding this plugin only on DEV mode (or PREPROD) allows not having data-qa attributes on production.

You can specify the format of the name that you want and the name of the attribute, inside your babelrc:

{
  "presets": ["es2015", "react"],
  "env": {
    "dev": {
      "plugins": ["transform-react-qa-classes", {
        "attribute": "qa-property",
        "format": "camel"
      }]
    }
  }
}

Note: format can be: "camel" (camelCase), "snake" (snake_case), "kebab" (kebab-case) or "pascal" (PascalCase).

with CLI

babel --plugins transform-react-qa-classes component.js

or programatically with babel-core

require('babel-core').transform(`code`, {
  plugins: ['transform-react-qa-classes']
})

Contributing

PRs for additional features are welcome!

There's still a few feature that are missing, for example each change of the state of the component is added as a data-qa-state into the DOM. Support for more libraries.

I recommend checking this handbook about how to write babel plugins in order to learn.

  • Clone the repo: git clone https://github.com/davesnx/babel-plugin-transform-react-qa-classes
  • Fork it & set origin as this repo: git remote set-url origin https://github.com/YOUR_USERNAME/babel-plugin-transform-react-qa-classes.git
  • Create a branch: git checkout -b BRANCH_NAME
  • Do the code
  • Create a PR to this repo.

In order to do the commits I prefer to use Commitizen and there's a githook setted up when you push it runs the tests.

Feedback

Is your company using it? I would love to know more! Could you answer this small Typeform :P

License

MIT