0.0.4 • Published 1 year ago

babel-plugin-test-id v0.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

babel-plugin-test-id

Example

in

const Bar = () => <div>Hi</div>;

out

const Bar = () => <div data-id="Hi">Hi</div>;

in

const t = (s) => s;

const I18NDiv = () => <div>{t('I18N_KEY')}</div>;

out

const t = (s) => s;

const I18NDiv = () => <div data-id="I18N_KEY">{t('I18N_KEY')}</div>;

Install

yarn add babel-plugin-test-id

or

npm install babel-plugin-test-id

Usage

in .babelrc

"plugins": [
  "babel-plugin-test-id",
  ...
 ]

Options

PropertyTypeDefaultDescription
idAttributeKeystringdata-idUnique information extracted from the attributes and content of the element
componentAttributeKeystringdata-componentReact component name if any
classnameAttributeKeystringdata-classnamecss classnames before uglified
idAttributeListstring[]["title", "label", "placeholder", "description", "header", "name", "field", "type",]Extract unique strings from these attributes to construct the value for 'idAttributeKey'
idAttributeValueStringstring"/^A-Z/g"Only extract string that matches with this pattern (string will be converted to RegExp) to construct the value for 'idAttributeKey', default to Pascal cases
delimiterstring-Join multiple extracted strings

in .babelrc

"plugins": [
  ["babel-plugin-test-id", { "idAttributeKey", "data-my-test-id" }]
  ...
 ]
0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago