transformTestId.js 572 B

12345678910111213141516171819202122232425
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. const NodeTypes = {
  3. ELEMENT: 1,
  4. ATTRIBUTE: 6,
  5. }
  6. const dataAttributes = new Set(['data-testid', 'data-test-id', 'data-testId'])
  7. const TransformTestId = (node) => {
  8. if (node.type !== NodeTypes.ELEMENT || !('props' in node)) {
  9. return
  10. }
  11. for (let i = 0; i < node.props.length; i += 1) {
  12. const p = node.props[i]
  13. if (p && p.type === NodeTypes.ATTRIBUTE && dataAttributes.has(p.name)) {
  14. node.props.splice(i, 1)
  15. i -= 1
  16. }
  17. }
  18. }
  19. module.exports = TransformTestId