babel-plugin-react-element-info
Babel plugin for exposing React element name and filename in DOM nodes
Installation
npm install --save-dev babel-plugin-react-element-info
The problem solved
This is useful for auto-generating selectors to run selenium tests.
Example
In
myInputFile.js
Component { return <MyReactComponent> My component contents </MyReactComponent> ; }
Out
Component { return <MyReactComponent data-qa-node="MyReactComponent" data-qa-file="myInputFile"> My component contents </MyReactComponent> ; }
Usage
.babelrc
(Recommended)
Via .babelrc
without options:
with options. Prefix is the attribute prefix, defaulting to qa
(data-qa-*
). To get data-test-prefix-*
attributes, set prefix to test-prefix
:
Via CLI
babel --plugins react-element-info script.js
Via Node API
without options:
;
with options:
;
License
MIT