-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (26 loc) · 713 Bytes
/
index.js
File metadata and controls
31 lines (26 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const buildTestJsxAttributes = t => value => [
t.jsxAttribute(
t.jsxIdentifier('accessibilityLabel'),
t.jsxExpressionContainer(value)
),
t.jsxAttribute(
t.jsxIdentifier('accessible'),
t.jsxExpressionContainer(t.booleanLiteral(true))
)
]
module.exports = function composeTestId({ types }) {
if (process.env.BABEL_ENV === 'production') return {}
const mapTestIdFunction = buildTestJsxAttributes(types)
return {
name: 'testId Wrapper',
visitor: {
JSXAttribute(path) {
if (path.node.name.name !== 'testID') return
const value = types.isExpression(path.node.value)
? path.node.value
: path.node.value.expression
path.insertAfter(mapTestIdFunction(value))
}
}
}
}