All Projects → davesnx → babel-plugin-transform-react-qa-classes

davesnx / babel-plugin-transform-react-qa-classes

Licence: MIT license
Add component's name in `data-qa` attributes to React Components

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to babel-plugin-transform-react-qa-classes

mailhandler
Simple lightweight mail library which allows you to send and retrieve emails, and get more details about email sending and delivery
Stars: ✭ 49 (+19.51%)
Mutual labels:  qa, qatools
php-qa-tools
A metapackage for all PHP quality assurance tools we use at Dealerdirect
Stars: ✭ 36 (-12.2%)
Mutual labels:  qa, qatools
Extract React Types
One stop shop to document your react components.
Stars: ✭ 141 (+243.9%)
Mutual labels:  babel-plugin, react-components
unity-asset-validator
The Asset Validator is an editor tool for validating assets in the project and in scenes.
Stars: ✭ 30 (-26.83%)
Mutual labels:  qa, qatools
Links-QA
Сборная солянка полезных ссылок для QA/тестировщика. Ссылки будут постоянно пополняться.
Stars: ✭ 42 (+2.44%)
Mutual labels:  qa, qatools
aquality-selenium-java
Aquality Selenium is a library built over Selenium WebDriver tool that allows to automate work with web browsers. Selenium WebDriver requires some skill and experience. So, Aquality Selenium suggests simplified and most importantly safer and more stable way to work with Selenium WebDriver.
Stars: ✭ 41 (+0%)
Mutual labels:  qa, qatools
relint
General purpose RegEx based file linter.
Stars: ✭ 33 (-19.51%)
Mutual labels:  qa, qatools
autotests
Armbian automated testings
Stars: ✭ 18 (-56.1%)
Mutual labels:  qa, qatools
test junkie
Highly configurable testing framework for Python
Stars: ✭ 72 (+75.61%)
Mutual labels:  qa, qatools
react-color
🎨 Is a tiny color picker widget component for React apps.
Stars: ✭ 50 (+21.95%)
Mutual labels:  react-components
babel-plugin-transform-rename-properties
A Babel plugin for renaming JavaScript properties
Stars: ✭ 19 (-53.66%)
Mutual labels:  babel-plugin
mern-admin-panel
Admin-panel using ReactJs, ExpressJs, NodeJs, MongoDB and Bootstrap
Stars: ✭ 84 (+104.88%)
Mutual labels:  react-components
react-nes
React components for nes
Stars: ✭ 32 (-21.95%)
Mutual labels:  react-components
dialogbot
dialogbot, provide search-based dialogue, task-based dialogue and generative dialogue model. 对话机器人,基于问答型对话、任务型对话、聊天型对话等模型实现,支持网络检索问答,领域知识问答,任务引导问答,闲聊问答,开箱即用。
Stars: ✭ 96 (+134.15%)
Mutual labels:  qa
react-component-maker
react-component-maker
Stars: ✭ 32 (-21.95%)
Mutual labels:  react-components
babel-plugin-console-source
Add the file name and line numbers to all console logs.
Stars: ✭ 38 (-7.32%)
Mutual labels:  babel-plugin
babel-plugin-solid-undestructure
A Babel plugin for SolidJS that allows you to destructure component props without losing reactivity.
Stars: ✭ 45 (+9.76%)
Mutual labels:  babel-plugin
pysys-test
PySys System Test Framework
Stars: ✭ 14 (-65.85%)
Mutual labels:  qa
babel-plugin-transform-amd-to-commonjs
✨ Babel plugin that transforms AMD to CommonJS
Stars: ✭ 44 (+7.32%)
Mutual labels:  babel-plugin
fyndiq-ui
Library of reusable web frontend components for Fyndiq
Stars: ✭ 39 (-4.88%)
Mutual labels:  react-components

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.

Before After
function FancyComponent () {
  return (
    <div>
      <div>Hello world</div>
    </div>
  )
}
      
function FancyComponent () {
  return (
    <div data-qa='fancy-component'>
      <div>Hello world</div>
    </div>
  )
}
      

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

Features

Works with:

  • class components
  • styled-components
  • arrow components
  • without JSX
  • option to configure the attribute name (default data-qa)
  • formats different the value of the attribute (default camelCase)

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].