Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-jsx-remove-qa

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-jsx-remove-qa

babel plugin to remove-qa-classes

  • 0.3.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

babel-plugin-jsx-remove-qa

You may want to consider using babel-plugin-jsx-remove-data-test-id over this package, since we believe it is more delcarative and works well as a uniform approach for both unit testing, and end to end.

Remove QA classes from your production builds.

Motivation

It's not a good idea to hang unit tests off production CSS classes or DOM elements for a couple of reasons:

  • Finding by an .o-some-class selector couples our test to the CSS; making changes can be expensive from a maintainance point of view, whether they are coming from the CSS or the tests
  • Finding elements by DOM tag, such as <span /> or <p> can be equally as difficult to maintain; these things move around so if your looking for .first() you might get a nasty surprise

We wanted to decouple our tests from the production CSS, but quite liked what class selectors gave us, so we started to add className="qa-some-class" to our React components.

This is good because, by convention, our UI guys never style to these classes so when we want to move stuff around - we just do it, and so do they.

The problem is, left untreated, these things can makes their way into your production code. Not good.

Install

npm install babel-plugin-jsx-remove-qa --save-dev

Add this to you babel config plugins

plugins: [
    'babel-plugin-jsx-remove-qa',
    {
        attributes: ['cssClassName'] // Another attribute you might want to remove
    }
]

How to use

Add classnames to your react components

return (
    <div>
        <p className="qa-component-text">{someText}</p>
        <ChildComponent cssClassName="qa-child-component" {...props] />
    </div>
);

Make sure the plugins are part of your webpack build, and that's it. .qa-classes will be stripped.

At the moment this only works on string literals, but at some point we'll be adding support for expressions too.

Keywords

FAQs

Package last updated on 31 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc